python - Paramiko ssh with tor sock proxy -


i trying use tor proxy ssh.

first simple connection without ~/.ssh/config

~$ ssh -p <server_post> <user>@<server_host> <user>@<server_host>'s password:   ~$ echo $ssh_connection <my_real_host> <my_real_port> <server_host> <server_port> 

second next ~/.ssh/config:

host * proxycommand connect -4 -s 127.0.0.1:9050 $(tor-resolve %h 127.0.0.1:9050) %p 

and connect:

~$ ssh -p <server_post> <user>@<server_host> <user>@<server_host>'s password:   ~$ echo $ssh_connection <not_my_real_host> <not_my_real_host> <server_host> <server_port> 

now paramiko:

>>> import paramiko >>> client = paramiko.sshclient() >>> proxy = none >>> client.set_missing_host_key_policy(paramiko.autoaddpolicy()) >>> client.connect(hostname=host, username=user, password=password, ...                port=port, sock=proxy) >>> stdin, stdout, stderr = client.exec_command('echo $ssh_connection') >>> print((stdout.read() + stderr.read()).decode('utf8')) <my_real_host> <my_real_port> <server_host> <server_port> 

all work fine. when try set proxy:

>>> import paramiko >>> client = paramiko.sshclient() >>> proxy = paramiko.proxycommand( ...     'connect -4 -s 127.0.0.1:9050 $(tor-resolve %h 127.0.0.1:9050) %p') >>> client.set_missing_host_key_policy(paramiko.autoaddpolicy()) >>> client.connect(hostname=host, username=user, password=password, ...                port=port, sock=proxy) >>> stdin, stdout, stderr = client.exec_command('echo $ssh_connection') >>> print((stdout.read() + stderr.read()).decode('utf8')) 

i have next exception python 3.4:

exception: error reading ssh protocol bannersequence item 0: expected str instance, bytes found traceback (most recent call last):   file "/home/tbicr/project/env34/lib/python3.4/site-packages/paramiko/transport.py", line 1535, in _check_banner     buf = self.packetizer.readline(timeout)   file "/home/tbicr/project/env34/lib/python3.4/site-packages/paramiko/packet.py", line 271, in readline     buf += self._read_timeout(timeout)   file "/home/tbicr/project/env34/lib/python3.4/site-packages/paramiko/packet.py", line 424, in _read_timeout     x = self.__socket.recv(128)   file "/home/tbicr/project/env34/lib/python3.4/site-packages/paramiko/proxy.py", line 93, in recv     result = ''.join(self.buffer) typeerror: sequence item 0: expected str instance, bytes found  during handling of above exception, exception occurred:  traceback (most recent call last):   file "/home/tbicr/project/env34/lib/python3.4/site-packages/paramiko/transport.py", line 1412, in run     self._check_banner()   file "/home/tbicr/project/env34/lib/python3.4/site-packages/paramiko/transport.py", line 1539, in _check_banner     raise sshexception('error reading ssh protocol banner' + str(e)) paramiko.ssh_exception.sshexception: error reading ssh protocol bannersequence item 0: expected str instance, bytes found  traceback (most recent call last):   file "/home/tbicr/project/env34/lib/python3.4/site-packages/paramiko/transport.py", line 1535, in _check_banner     buf = self.packetizer.readline(timeout)   file "/home/tbicr/project/env34/lib/python3.4/site-packages/paramiko/packet.py", line 271, in readline     buf += self._read_timeout(timeout)   file "/home/tbicr/project/env34/lib/python3.4/site-packages/paramiko/packet.py", line 424, in _read_timeout     x = self.__socket.recv(128)   file "/home/tbicr/project/env34/lib/python3.4/site-packages/paramiko/proxy.py", line 93, in recv     result = ''.join(self.buffer) typeerror: sequence item 0: expected str instance, bytes found  during handling of above exception, exception occurred:  traceback (most recent call last):   file "/home/tbicr/project/registrator/main.py", line 70, in <module>     client.connect(hostname=host, username=user, password=password, port=port, sock=proxy)   file "/home/tbicr/project/env34/lib/python3.4/site-packages/paramiko/client.py", line 242, in connect     t.start_client()   file "/home/tbicr/project/env34/lib/python3.4/site-packages/paramiko/transport.py", line 346, in start_client     raise e   file "/home/tbicr/project/env34/lib/python3.4/site-packages/paramiko/transport.py", line 1412, in run     self._check_banner()   file "/home/tbicr/project/env34/lib/python3.4/site-packages/paramiko/transport.py", line 1539, in _check_banner     raise sshexception('error reading ssh protocol banner' + str(e)) paramiko.s 

for python 2.7 same exception other stacktrace:

no handlers found logger "paramiko.transport" traceback (most recent call last):   file "/home/tbicr/project/registrator/main.py", line 70, in <module>     client.connect(hostname=host, username=user, password=password, port=port, sock=proxy)   file "/home/tbicr/project/env27/local/lib/python2.7/site-packages/paramiko/client.py", line 242, in connect     t.start_client()   file "/home/tbicr/project/env27/local/lib/python2.7/site-packages/paramiko/transport.py", line 339, in start_client     raise e paramiko.ssh_exception.sshexception: error reading ssh protocol banner 

so connection ssh client , tor work fine, paramiko not.

why it's not work , how can fix python?


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -