web-dev-qa-db-ja.com

socatとtorを備えたSSHトンネル

次のように、socatを使用して開発サーバーにアクセスしてトンネルを作成しようとしています。

# start TOR
tor

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

# login through local tunnel
ssh localhost -p 4141

これは、sshが通常使用されている場合の出力です。

$ 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: 

しかし、socatトンネルを使用してsshを実行しようとすると、次のようになります。

$ 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

さらに、これが発生すると、socatは次のように終了します。

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

何か案は?

2

Socatの代わりにtorsocksを使用してみてください。 Torの tsocksproxifier に基づくTorsocks:

# 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)

私の出身地:tor2.tedesca.net

1
innocent-world