Gilles.is

/Zettle/202110102130-SSH-Tunneling

Toggle Light


By Gilles Trenson
this is a 1 minutes read
17 paragraphs

202110102130 SSH Tunneling

#SSH#commandline#hacking

Local port forwarding

Mount port 80 of the external host (remote server home.local) to the port 8080of the local host. The -N flag prevents the initiation of an interactive session.

ssh -N -L 8080:localhost:80 [email protected]

Remote port forwarding

Also called SSH Reverse tunneling. Redirects the remote server's port to the local host's port. The client initiates the connection, then a tunnel is created (a socket listener is initiated by the server at the defined port) to forward incoming traffic to the server back to the client. It can be achieved with the -R flag. For example:

ssh -N -R 8080:localhost:1234 [email protected]

In order to make this work, it's also necessary to adjust the GatewayPortsdefault setting

sudo sed -i 's/#\?GatewayPorts.*/GatewayPorts yes/' /etc/ssh/sshd_config
sudo service ssh restart

Dynamic port forwarding

When, for example, traffic is blocked by your ISP or your organization, but an outbound ssh connection is allowed, then a SOCKS5 proxy server can be setup that allows traffic to be forwarded from whatever protocol/type to any address. The client takes initiative and starts a SOCKS5 proxy at the server side. He defines a local address where his browser could point to to allow unrestricted access.

ssh -D localhost:6000 [email protected]

Nearly anonymous ssh session

#hacking#tor

torsocks which routes your traffic through the TOR network using SOCKS5 for the application referenced torsocks <application>. For example:

torsocks ssh [email protected]

Or you could do the same using:

ssh -o ProxyCommand="nc -X 5 -x localhost:9050 %h %p" [email protected]

The TOR instance should be up and running on your client at port 9050.

Source

Blogpost by teleport

Similar story?

The following list contains an overview of all zettels that have been created with the same tags assigned.

list
from #SSH