SSH Tunnel with socat and tor

2

1

I'm trying out tor by attempting to access my development server using socat to create a tunnel, like this:

# start TOR
tor

# create tunnel
socat TCP-LISTEN:4141 SOCKS4A:localhost:remotehost:22,socksport=9050

# login through local tunnel
ssh localhost -p 4141

This is the output when ssh is used normally:

$ ssh -v remotehost -p 22
OpenSSH_6.1p1 Debian-4, OpenSSL 1.0.1c 10 May 2012
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to remotehost [remoteip] port 22.
debug1: Connection established.
debug1: identity file /home/alainus/.ssh/id_rsa type 1
debug1: Checking blacklist file /usr/share/ssh/blacklist.RSA-2048
debug1: Checking blacklist file /etc/ssh/blacklist.RSA-2048
debug1: identity file /home/alainus/.ssh/id_rsa-cert type -1
debug1: identity file /home/alainus/.ssh/id_dsa type -1
debug1: identity file /home/alainus/.ssh/id_dsa-cert type -1
debug1: identity file /home/alainus/.ssh/id_ecdsa type -1
debug1: identity file /home/alainus/.ssh/id_ecdsa-cert type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.9p1 Debian-5ubuntu1
debug1: match: OpenSSH_5.9p1 Debian-5ubuntu1 pat OpenSSH_5*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.1p1 Debian-4
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: sending SSH2_MSG_KEX_ECDH_INIT
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ECDSA ...
debug1: Host 'remotehost' is known and matches the ECDSA host key.
debug1: Found key in /home/alainus/.ssh/known_hosts:5
debug1: ssh_ecdsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/alainus/.ssh/id_rsa
debug1: Authentications that can continue: publickey,password
debug1: Trying private key: /home/alainus/.ssh/id_dsa
debug1: Trying private key: /home/alainus/.ssh/id_ecdsa
debug1: Next authentication method: password
alainus@remotehost's password: 

But when I attempt to ssh using the socat tunnel, I get this:

$ ssh -vvv localhost -p 4141
OpenSSH_6.1p1 Debian-4, OpenSSL 1.0.1c 10 May 2012
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug2: ssh_connect: needpriv 0
debug1: Connecting to localhost [127.0.0.1] port 4141.
debug1: Connection established.
debug3: Incorrect RSA1 identifier
debug3: Could not load "/home/alainus/.ssh/id_rsa" as a RSA1 public key
debug1: identity file /home/alainus/.ssh/id_rsa type 1
debug1: Checking blacklist file /usr/share/ssh/blacklist.RSA-2048
debug1: Checking blacklist file /etc/ssh/blacklist.RSA-2048
debug1: identity file /home/alainus/.ssh/id_rsa-cert type -1
debug1: identity file /home/alainus/.ssh/id_dsa type -1
debug1: identity file /home/alainus/.ssh/id_dsa-cert type -1
debug1: identity file /home/alainus/.ssh/id_ecdsa type -1
debug1: identity file /home/alainus/.ssh/id_ecdsa-cert type -1
ssh_exchange_identification: Connection closed by remote host

Additionally, when this happens, socat exits with:

2013/07/03 13:30:08 socat[9650] E connect(3, AF=2 127.0.0.1:9050, 16): Connection refused

Any ideas?

Alain Jacomet Forte

Posted 2013-07-03T17:48:38.957

Reputation: 211

Answers

1

Try to use torsocks instead of socat. Torsocks based on tsocks proxifier for Tor:

# dpkg -l torsocks
ii  torsocks      1.2-3    amd64   use SOCKS-friendly applications with Tor
# torsocks ssh user@server
#Enter a password

# Welcome !

shell:~/$ who
me pts/16       2013-08-31 22:41 (tor2.tedesca.net)

I'm from: tor2.tedesca.net

innocent-world

Posted 2013-07-03T17:48:38.957

Reputation: 141