Перейти к основному содержимому
Lateral Movement & Network Pivoting (SSH, SOCKS, Chisel)
Урок 9 из 11

Lateral Movement & Network Pivoting (SSH, SOCKS, Chisel)

Route assessment traffic through compromised dual-homed hosts using SSH port forwards, SOCKS5 proxies, sshuttle and Chisel, and distinguish network pivoting from lateral movement across segmented environments.

Эксперт 34 мин Пентест
Этого урока пока нет на выбранном языке — показана версия на другом языке. Перевод готовится.
Только в разрешённой среде — Описанные здесь приёмы применяются только в учебных лабораториях и в системах, которые принадлежат вам или на которые есть письменное разрешение.

Цели обучения

  • Distinguish network pivoting from lateral movement and identify when each is required in a segmented network
  • Configure SSH local, remote and dynamic SOCKS5 port forwards with ProxyChains for TCP tool routing
  • Select between OpenSSH forwarding, sshuttle and Chisel based on firewall directionality, OS and privileges
  • Identify host and network telemetry generated by tunnels and lateral movement and implement layered defences

Рекомендуется заранее: Post-Exploitation Enumeration & Safe Artifact HandlingApplied Privilege Escalation Workflow (Linux & Windows)

#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.
Dynamic SOCKS5 pivoting over SSH (-D)Dynamic SOCKS5 pivoting over SSH (-D)OperatorPivotInternalSSH session (TCP/22) + bind 127.0.0.1:1080SOCKS5 CONNECT 192.0.2.15:8080 (inside SSH)TCP connect to 192.0.2.15:8080HTTP responseRelayed payload over SSH channelInternal host sees only the pivot IP (192.0.2.1)

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.

Starting an SSH SOCKS5 pivot and probing an internal lab host
$ 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-proxy

Always 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.

Transparent subnet routing with sshuttle
$ sudo sshuttle -r operator@10.10.10.20 192.0.2.0/24 -x 10.10.10.20

The -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.

  1. Operatorchisel server --reverse -p 8443
  2. Pivotchisel client 10.10.10.5:8443 R:socks
  3. Result127.0.0.1:1080 SOCKS5 exits from Pivot
Reverse SOCKS5 tunnel over HTTP/WebSocket with Chisel
$ chisel server --reverse -p 8443
# Run on authorised pivot (10.10.10.20):
$ ./chisel client 10.10.10.5:8443 R:socks

Because 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 (or PermitOpen allow-lists) and AllowAgentForwarding no in /etc/ssh/sshd_config on 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) and 4648 (explicit credentials), sshd port-forward messages, and unexpected processes holding long-lived outbound sockets.

Common operational mistakes to avoid:

  • Binding forwards to 0.0.0.0: omitting 127.0.0.1: (or passing -g) exposes your SOCKS tunnel to other hosts on the local network.
  • Using ssh -A on untrusted pivots: a root user on the pivot can hijack the forwarded SSH_AUTH_SOCK socket; use ProxyJump (-J) instead.
  • Running SYN or ping scans over SOCKS: forgetting -sT -Pn in nmap produces 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, -R and -D handle single-port, reverse and dynamic SOCKS5 forwarding; pair -D with proxychains4 and nmap -sT -Pn.
  • Choose sshuttle for transparent CIDR routing over SSH/Python and Chisel (R:socks) when only outbound HTTP/WebSocket egress works.
  • Prevent abuse with sshd forwarding restrictions, strict DMZ-to-internal segmentation, egress proxy inspection and logon/tunnel monitoring.

Проверка знаний

Войдите, чтобы проходить тест, завершать уроки и сохранять прогресс. Войти в систему

Практика: проверьте свои знания