Sergii
Sergii

Reputation: 304

Open putty ssh connection over SOCKS5 proxy via command line

I tried to open putty ssh connection over SOCKS5 proxy via command line.

putty.exe -P port -pw password username@host -nc proxyhost:proxyport

This command doesn't work and I think it is incorrect. I tried a lot of variants of this command, but putty user manual doesn't contain necessary information.

I tried to connect to my host throw putty UI and it works fine.

For openSSH similar command looks

ssh -o "ProxyCommand=nc -x proxyhost:proxyport %h %p" -p port username@host

Upvotes: 7

Views: 9694

Answers (3)

Nishant Chauhan
Nishant Chauhan

Reputation: 73

Simple,

putty -D 8080 <user_id>@<server_name> -pw <password>

Upvotes: 2

jhn
jhn

Reputation: 71

Even though this is an old thread I would like to add my two cents, as I found it hard to gather all the information necessary to set up a working ssh connection over a SOCKS-5 proxy using putty command line and this thread showed up in my result list.

TL;DR

It is currently not possible (as of putty v0.74) to route ssh traffic over a SOCKS-5 proxy using putty or plink as the proxy-command on the command line. You have to use an alternative like ncat for windows, e.g.:

putty -p <targetport> -proxycmd "ncat.exe --proxy-type socks5 --proxy <proxyhost>:<proxyport> <targethost> <targetport>" <targethost>

Details

The putty GUI allows the configuration of an SOCKS-5 proxy, see putty documentation.

As correctly stated in the answer, by BlakBat this configuration can be called via command line using the -load argument.

The command line argument -proxycmd triggers the use of a so called 'local' proxy connection (see the putty documentation again):

> 3.8.3.24 -proxycmd: specify a **local** proxy command

The local proxy command is a command issued on the local machine, that will handle the proxy connection (see the documentation about proxy types). ncat is such a command and it is able to interact with a SOCKS-5 proxy.

Finally, it is tempting to use plink/putty as the proxy command to avoid the use of multiple tools. Putty claims to provide an alternative to the netcat utility via the -nc argument, however the putty documentation states:

If you want your local proxy command to make a secondary SSH connection to a proxy host and then tunnel the primary connection over that, you might well want the -nc command-line option in Plink.

If you try to use the -nc argument to open a SOCKS-5 connection your SOCKS server log might show something like this:

sockd[1234]: info: block(1): tcp/accept ]: 1.2.3.4.4711 1.2.3.5.1080: error after reading 1 byte in 0 seconds: unknown SOCKS version 83 in client request

This is an indication that an attempt was made to open an SSH session to the SOCKS-5 server.

So, unfortunately, to my knowledge your only chance is to use putty along with a netcat-like tool to establish a proxied SSH connection using an SOCKS-5 proxy.

Upvotes: 2

BlakBat
BlakBat

Reputation: 1853

If I were you I would create a "Saved Session" with Putty and launch it via command line:

putty.exe -load session_name

It will be easier to create a "Saved Session" via the PuTTY interface than toying around with the command line. And it seems like you already have it working through the PuTTY interface.

Upvotes: 3

Related Questions