Combining SOCAT with SSH to have dynamic port forwarding through socks proxy

Amirali Amirale picture Amirali Amirale · Jul 2, 2015 · Viewed 10.1k times · Source

My issue is very simple, what I want to do is to connect to my ssh through socat, this means if I have server 10.0.0.1 that has SSH and SOCAT together I listen to 5555 port of my socat, then my socat forwards all tcp packets to my ssh server 22 port for dynamic port forwarding.

I hope hear from you and Thank you in advance

Answer

Bill picture Bill · Jul 2, 2015

Here is a basic configuration that seems to be what you want.

socat TCP-LISTEN:5555 TCP:localhost:22

If you want to use ssh on the server as a SOCKS proxy then you don't need socat. On the server run

ssh -D 10.0.0.1:5555 localhost 

Of course it is more secure if you run the ssh client on your local machine and change your socks proxy to point to localhost using

ssh -D 5555 10.0.0.1 

on the client machine.

If you can only use ssh indirectly then you can combine the above by running ssh on the server listening to 5550 on localhost and having socat listening on 5555 and forwarding it to 5550:

socat TCP-LISTEN:5555,fork TCP:localhost:5550 &
ssh -N -D 5550 localhost