Port Forwarding

SSH Local Port Forwarding

1
ssh -L 6999:localhost:5901 [email protected]
2
3
[email protected] = SSH host to connect to
4
-L = Option to enable local port forwarding
5
6999 = Port on the client PC
6
localhost = Host server to connect to (the remote PC, same as 127.0.0.1)
7
5901 = Port on the remote host (forwarded from the client PC)
Copied!
SSH Local and Remote Port Forwarding with VNC
Computing Tidbits
Local port forwarding – A port from the client PC is forwarded to the remote PC. A connection to this port enables data to be sent bidirectionally over the SSH connection between the client and remote PC.

SSH: Dynamic Port Forwarding

1
# Listen on local port 8080 and forward incoming traffic to REMOT_HOST:PORT via SSH_SERVER
2
# Scenario: access a host that's being blocked by a firewall via SSH_SERVER;
3
ssh -L 127.0.0.1:8080:REMOTE_HOST:PORT [email protected]_SERVER
Copied!

SSH: Remote Port Forwarding

1
# Open port 5555 on SSH_SERVER. Incoming traffic to SSH_SERVER:5555 is tunneled to LOCALHOST:3389
2
# Scenario: expose RDP on non-routable network;
3
ssh -R 5555:LOCAL_HOST:3389 [email protected]_SERVER
4
plink -R ATTACKER:ATTACKER_PORT:127.0.01:80 -l root -pw pw ATTACKER_IP
Copied!

Proxy Tunnel

1
# Open a local port 127.0.0.1:5555. Incoming traffic to 5555 is proxied to DESTINATION_HOST through PROXY_HOST:3128
2
# Scenario: a remote host has SSH running, but it's only bound to 127.0.0.1, but you want to reach it;
3
proxytunnel -p PROXY_HOST:3128 -d DESTINATION_HOST:22 -a 5555
4
ssh [email protected] -p 5555
Copied!

HTTP Tunnel: SSH Over HTTP

1
# Server - open port 80. Redirect all incoming traffic to localhost:80 to localhost:22
2
hts -F localhost:22 80
3
4
# Client - open port 8080. Redirect all incoming traffic to localhost:8080 to 192.168.1.15:80
5
htc -F 8080 192.168.1.15:80
6
7
# Client - connect to localhost:8080 -> get tunneled to 192.168.1.15:80 -> get redirected to 192.168.1.15:22
8
ssh localhost -p 8080
Copied!

Netsh - Windows Port Forwarding

1
# requires admin
2
netsh interface portproxy add v4tov4 listenaddress=localaddress listenport=localport connectaddress=destaddress connectport=destport
Copied!

Last modified 1yr ago
Copy link