Using a combination of netcat and SSH config files, it’s possible to use a proxy to SSH.
nc -x localhost:4444 -X5 whereiwant.togo
Using the above, it’s possible to configure SSH to use the netcat command from above. SSH can be configured on a per-user basis by creating a named config file in the
~/.ssh directory as below.
$ cat ~/.ssh/proxy4444 ProxyCommand /usr/bin/nc -X 5 -x localhost:4444 %h %p
To test the SSH over a proxy, a dynamic SSH tunnel can be brough up easily between local host and a remote host running
ssh -D 4444 $remoteHost -l $userName -f -N.
Finally, using the ssh config file a connection can be established via the proxy:
ssh -F ~/.ssh/proxy4444 $remoteHost -l $userName.
SSH remote tunnel
ssh -D 4444 $remoteHost -l $userName -f -N
-D $localPort- Specifies a local “dynamic” application-level port forwarding. This is the port that will be opened on our local host.
$remoteHost- A placeholder meant to represent the IP address or hostname of the remote host to which SSH will try to connect.
-l $userName- Simply the username registered on the remote host.
-f- Fork the session into the background
-N- Don’t execute a remote command.
For more information: https://linux.die.net/man/1/ssh
This command will test to see if it’s possible to use netcat to connect via SOCK5 to our remote host. netcat will form the connection to the remote host if possible for other applications without proxy support.
nc -x localhost:4444 -X5 $remoteHost
-x localhost:4444- The address of the proxy including port. In the above case, the SSH tunnel’s address and port.
-X5- Specify the version or type of proxy. 5 indicates SOCKS5.
$remoteHost- A placeholder meant to represent the IP address or hostname of the remote host to which nc will try to connect.
For more information: https://linux.die.net/man/1/nc