#Why this matters
Enterprise networks isolate internal databases, directory servers and management interfaces behind firewalls and private routing. Once an authorised test gains a foothold on a perimeter web server or jump host, reaching deeper segments requires two distinct skills: pivoting (relaying network traffic across a boundary) and lateral movement (authenticating and executing on neighbouring internal hosts). Knowing how each works -- and what telemetry it leaves behind -- lets testers validate segmentation and helps defenders detect cross-zone intrusions.
#Pivoting versus lateral movement
Pivoting is a transport technique: assessment tools stay on your workstation while their TCP streams travel through a compromised intermediary. Lateral movement (MITRE ATT&CK TA0008) is an identity and execution technique: you reuse harvested credentials, SSH keys, Kerberos tickets or remote services (SSH, WinRM, SMB, RDP) to open sessions on new hosts.
Before building a tunnel, inspect the pivot's situational-awareness data: interfaces (ip addr or ipconfig /all), routing tables (ip route or route print), ARP neighbours and host firewall rules.
| Aspect | Network pivoting | Lateral movement |
|---|---|---|
| Core goal | Reach non-routable subnets from operator tools | Obtain sessions or execution on new hosts |
| Mechanism | SSH -L/-R/-D, SOCKS5, sshuttle, Chisel |
SSH keys, WinRM, SMB/WMI, RDP, Pass-the-Hash |
| Requirement | Dual-homed path or relay capability | Valid credentials, tokens or trust links |
| Primary telemetry | Long-lived tunnels, loopback listeners | Event IDs 4624 (Type 3) / 4648, sshd logs |
#SSH port forwarding and SOCKS5 proxies
When a pivot runs an SSH daemon and accepts inbound SSH, OpenSSH provides three forwarding modes without dropping third-party binaries:
- Local forward (
-L): binds a port on your workstation and forwards it through the pivot to one fixed internal host and port. - Remote forward (
-R): binds a port on the remote SSH server and sends connections back to your side, useful when the pivot must initiate SSH outbound. - Dynamic forward (
-D): opens a local SOCKS5 listener so SOCKS-aware clients can reach arbitrary internal IPs and ports.
For tools without native SOCKS5 support, ProxyChains (proxychains4) intercepts dynamic connect() calls via LD_PRELOAD and routes them through 127.0.0.1:1080 as set in /etc/proxychains4.conf.
$ ssh -N -D 127.0.0.1:1080 operator@10.10.10.20 &
$ ss -tlnp | grep 1080
LISTEN 0 128 127.0.0.1:1080 0.0.0.0:* users:(("ssh",pid=4128,fd=4))
$ proxychains4 -q nmap -sT -Pn -p 22,80,8080 192.0.2.15
PORT STATE SERVICE
22/tcp closed ssh
80/tcp closed http
8080/tcp open http-proxyAlways pass -sT (full TCP connect scan) and -Pn (skip ICMP discovery) to nmap: SOCKS5 proxies relay TCP connect() streams rather than raw SYN packets or ICMP echoes. Also enable proxy_dns in /etc/proxychains4.conf so internal hostname lookups do not leak to your local DNS resolver. For multi-hop SSH paths, use ProxyJump (ssh -J user@hop1 user@target) instead of copying private keys onto intermediate machines.
#Transparent routing and Chisel tunnels
ProxyChains fails on static binaries (such as many Go tools) that ignore LD_PRELOAD. When inbound SSH and Python exist on the pivot, sshuttle acts like a userland VPN over SSH: it needs sudo locally to redirect traffic for a target CIDR, and needs no root privileges on the pivot.
$ sudo sshuttle -r operator@10.10.10.20 192.0.2.0/24 -x 10.10.10.20The -x flag excludes the pivot IP so the outer SSH control session does not loop into itself. Like SOCKS, sshuttle relays TCP (plus optional --dns), not arbitrary ICMP.
When inbound SSH to the pivot is blocked by NAT, a firewall or the lack of an SSH server (typical on Windows targets), Chisel tunnels TCP and a built-in SOCKS5 proxy inside an outbound HTTP/WebSocket connection.
- Operatorchisel server --reverse -p 8443
- Pivotchisel client 10.10.10.5:8443 R:socks
- Result127.0.0.1:1080 SOCKS5 exits from Pivot
$ chisel server --reverse -p 8443
# Run on authorised pivot (10.10.10.20):
$ ./chisel client 10.10.10.5:8443 R:socksBecause the client connects outbound to port 8443 (or 443 in HTTPS-only egress zones) with R:socks, the Chisel server binds 127.0.0.1:1080 locally while traffic exits from the pivot.
| Method | Inbound SSH needed? | Pivot requirements | Best fit |
|---|---|---|---|
ssh -L |
Yes | SSH daemon | One fixed internal TCP port |
ssh -D + ProxyChains |
Yes | SSH daemon | Dynamically linked TCP tools |
sshuttle |
Yes | SSH daemon + Python | Whole-CIDR TCP scanning and static tools |
Chisel (R:socks) |
No (outbound) | Single Chisel binary | Firewalled, NATted or Windows pivots |
#Defending against pivoting and common mistakes
Stopping cross-segment traversal requires combining SSH hardening, segmentation and egress inspection:
- Restrict SSH forwarding: set
AllowTcpForwarding no(orPermitOpenallow-lists) andAllowAgentForwarding noin/etc/ssh/sshd_configon DMZ and jump servers. - Segment and filter egress: block DMZ hosts from initiating SMB (445), WinRM (5985/5986), RDP (3389) or SSH (22) into internal tiers, and force server egress through a proxy that flags persistent WebSocket tunnels.
- Hunt tunnel and logon telemetry: correlate Windows Event IDs
4624(Logon Type 3) and4648(explicit credentials),sshdport-forward messages, and unexpected processes holding long-lived outbound sockets.
Common operational mistakes to avoid:
- Binding forwards to
0.0.0.0: omitting127.0.0.1:(or passing-g) exposes your SOCKS tunnel to other hosts on the local network. - Using
ssh -Aon untrusted pivots: a root user on the pivot can hijack the forwardedSSH_AUTH_SOCKsocket; useProxyJump(-J) instead. - Running SYN or ping scans over SOCKS: forgetting
-sT -Pninnmapproduces false negatives. - Leaving stale tunnels or tools behind: track PIDs and uploaded binaries and remove them at the end of testing.
#Summary
- Pivoting relays traffic through an intermediary host; lateral movement uses credentials or remote protocols to execute on additional hosts.
- OpenSSH
-L,-Rand-Dhandle single-port, reverse and dynamic SOCKS5 forwarding; pair-Dwithproxychains4andnmap -sT -Pn. - Choose
sshuttlefor transparent CIDR routing over SSH/Python andChisel(R:socks) when only outbound HTTP/WebSocket egress works. - Prevent abuse with
sshdforwarding restrictions, strict DMZ-to-internal segmentation, egress proxy inspection and logon/tunnel monitoring.