# Pivoting

## Port Forwarding

The goal is to redirect packet from one port to another port.

```


# from ipv4 to ipv6, all packet to localhost:445 will direct to <ipv6>:445
sudo socat TCP-LISTEN:445, fork TCP:<ipv6>:445

```

**ssh to kali machine**

<figure><img src="https://1855963211-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FaDjlLLsWaat1v8p89kgM%2Fuploads%2FJYbm4ieO5E1PpVnFTdiW%2Fimage.png?alt=media&#x26;token=5d23cf48-efa5-4264-a6ca-99a9b7da348f" alt=""><figcaption><p>port forwarding with ssh</p></figcaption></figure>

note:&#x20;

**local-port** and **local-machine** in the kali machine (**attacker**)

```
ssh -R -N <local-port>:127.0.0.1:<service-port> root@<local-machine>

```

##

## Reverse Proxy

### chisel

ref: <https://www.youtube.com/watch?v=dIqoULXmhXg>

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

1. **Attacker (Kali)**

```
./chisel server -p 8000 --reverse
```

<figure><img src="https://1855963211-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FaDjlLLsWaat1v8p89kgM%2Fuploads%2F6jB6FhDAmr9qCYpUAI2Q%2Fimage.png?alt=media&#x26;token=378bef45-cfcb-4569-b294-63e777d711c1" alt=""><figcaption></figcaption></figure>

2. **Run in Victim Machine**

**Windows**

```batch
chisel.exe client <attacker ip>:8000 R:socks
```

<figure><img src="https://1855963211-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FaDjlLLsWaat1v8p89kgM%2Fuploads%2FEqRnVVesyMyOjYiYYcDF%2Fimage.png?alt=media&#x26;token=1d5072ad-a73e-41c5-87dc-8c58c49e81b6" alt=""><figcaption></figcaption></figure>

**Linux**

```bash
./chisel client <attacker ip>:8000 R:sockss
```

3. **Config the proxychains (Attacker)**

change `/etc/proxychains4.conf`

```
[ProxyList]
socks5 127.0.0.1 1080
```

4. Run command

```bash
proxychains nmap -sT -p 88 -Pn -n <machine 2 ip>
```

### sshuttle

Need (user login as ssh)

```
# single
sshuttle -r username@remotehost 0.0.0.0/0
# example
sshuttle user@192.168.20.35 192.168.30.0/24

sshuttle -r root@10.1.1.1 10.2.2.0/24
```

{% embed url="<https://medium.com/vieh-group/hacking-oscp-cheatsheet-ef63c43f919c>" %}

{% embed url="<https://www.youtube.com/watch?v=lGr7VUCBvOQ&t=231s>" %}

### **SSH Tunnel**

nice ref:<https://www.isabekov.pro/reverse-ssh-tunnel/>

Can't ssh to machine?

```
ssh -p 22 -R "<attacker port>:<host port>
```

<figure><img src="https://1855963211-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FaDjlLLsWaat1v8p89kgM%2Fuploads%2FfKC015JqqqA8YTfZmjNV%2Fimage.png?alt=media&#x26;token=16fab1c0-97cf-44af-937c-cdf80c665276" alt=""><figcaption></figcaption></figure>

## **Forward Proxy**

### **chisel**

<figure><img src="https://1855963211-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FaDjlLLsWaat1v8p89kgM%2Fuploads%2F8VkueB4XPWM40DZ87VKx%2Fimage.png?alt=media&#x26;token=2bf01920-d398-4a28-a87b-af18b273fd61" alt=""><figcaption><p><a href="https://notes.benheater.com/books/network-pivoting/page/port-forwarding-with-chisel">https://notes.benheater.com/books/network-pivoting/page/port-forwarding-with-chisel</a></p></figcaption></figure>

### sshuttle

{% embed url="<https://fedoramagazine.org/use-sshuttle-to-build-a-poor-mans-vpn/>" %}

### SSH Tunnel (Recommended if you wanna access internal port)

**Forward Proxy**

Need SSH to machine:

```
ssh -D <local port> <user>@<IP of victim you have>

#example 
ssh -D 8989 local@10.10.10.10
```

It mean, every packet to 127.0.0.1:8989 will be forwarded as IP 10.10.10.10

You can set proxy on your `browser` or `proxychains.conf`

```
[Manual Proxy]
socks4 127.0.0.1 8989
```

Don't forget to using incognito to your browser or clear cache, for better process.

<figure><img src="https://1855963211-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FaDjlLLsWaat1v8p89kgM%2Fuploads%2Fl4Y6jNTF5zT7an1pUREJ%2Fimage.png?alt=media&#x26;token=879c51c1-3e4b-4e9c-b14b-ab5c0e8dfc99" alt=""><figcaption><p>Forward Proxy</p></figcaption></figure>

If that internal port have vhost configuration, you must set up that /etc/hosts on kali linux with pointing to local port (/etc/hosts on victim machine).

**Case of forward proxy**

{% embed url="<https://infosecwriteups.com/bypass-the-firewall-with-ssh-tunnelling-711fa78ea97f>" %}

## Are you stuck?

{% embed url="<https://resources.infosecinstitute.com/topic/tunneling-and-port-forwarding-tools-used-during-red-teaming-assessments/>" %}

### Network Pentest with Chisel

<figure><img src="https://1855963211-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FaDjlLLsWaat1v8p89kgM%2Fuploads%2Fs2k7EvIYkbAopYp7ttY9%2Fimage.png?alt=media&#x26;token=60428721-d0ef-4734-9ca4-c5559bbac4d8" alt=""><figcaption></figcaption></figure>

<https://notes.benheater.com/books/network-pivoting/page/penetrating-networks-via-chisel-proxies>
