Pivoting and Tunneling
Executive Summary
Pivoting and tunneling allow traffic to move through a compromised or authorized intermediate host to reach systems that are not directly accessible.
Use this cheatsheet for quick SSH forwarding, SOCKS proxying, Proxychains, Socat, Chisel, and Meterpreter routing syntax.
Core Concepts
| Concept | Purpose |
|---|---|
| Local port forward | Access an internal service from your local machine |
| Remote port forward | Expose a local service through a remote host |
| Dynamic port forward | Create a SOCKS proxy |
| SOCKS proxy | Route multiple tools through one proxy |
| Pivot host | Intermediate system with access to another network |
| Tunnel | Encapsulated traffic path through another connection |
Network Discovery
Linux interfaces:
Linux routes:
Windows interfaces:
Windows routes:
ARP table:
Test internal port:
PowerShell test:
SSH Local Port Forwarding
Forward local port 8080 to internal web service:
Access locally:
Forward local port to internal RDP:
SSH Remote Port Forwarding
Expose local service through remote host:
Remote forward with all interfaces:
SSH Dynamic Port Forwarding
Create SOCKS proxy:
Create SOCKS proxy without shell:
Use SOCKS proxy:
Proxychains
Edit config:
Add SOCKS proxy:
Run curl through proxy:
Run Nmap TCP connect scan:
Sshuttle
Route subnet through SSH:
Example:
Route all traffic through pivot:
Socat Port Forwarding
Forward local port to internal host:
TCP relay:
Reverse relay example:
Chisel
Start server on attacker machine:
Create reverse SOCKS from compromised host:
Create reverse port forward:
Create local SOCKS:
Meterpreter Routing
Show network interfaces:
Add route:
Print routes:
Start SOCKS proxy:
Proxychains entry:
Meterpreter Port Forwarding
Forward internal web service:
List forwards:
Delete forward:
Flush all forwards:
Nmap Through Tunnels
Through Proxychains, use TCP connect scan:
Do not rely on raw packet scans through SOCKS:
Browser Through SOCKS
Firefox SOCKS settings:
Quick Workflow
| Step | Action |
|---|---|
| Identify routes | ip route, route print |
| Find internal subnet | Check interfaces and ARP |
| Test reachability | nc -zv, Test-NetConnection |
| Build tunnel | SSH, Chisel, Socat, Meterpreter |
| Route tools | Proxychains or browser SOCKS |
| Validate access | Connect to internal service |
| Limit noise | Avoid broad scans through unstable tunnels |
Notes
- Use
-sTwith Nmap through SOCKS proxies. - DNS may not work unless the proxy handles DNS.
- Tunnels can be unstable through weak shells.
- Port forwards are best for single services.
- SOCKS proxies are better for exploring multiple services.