Advertisement
zerubits

SSH session not active

Sep 17th, 2018
326
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.85 KB | None | 0 0
  1. import paramiko
  2. __author__ = 'zerubits'
  3. #need an ssh account and squid proxy for this
  4. sshname = ''
  5. sshport = 22
  6. username = ''
  7. password = ''
  8. remoteproxy = ''
  9. remoteport =
  10.  
  11. ssh = paramiko.SSHClient()
  12. ssh.load_system_host_keys()
  13. ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  14. ssh.connect(sshname,sshport,username=username,password=password)
  15. print('ssh client connected to {}:{}'.format(sshname,sshport))
  16. transport = ssh.get_transport()
  17. for i in range(50):
  18.     try:
  19.         payload = 'CONNECT 0.facebook.com:80 HTTP/1.0\r\n\r\n'
  20.         channel = transport.open_channel('direct-tcpip',src_addr=('localhost',1301),dest_addr=(remoteproxy,remoteport))
  21.         channel.sendall(payload.encode())
  22.         response = channel.recv(1024)
  23.         print(response) #expected response(b'HTTP/1.0 200 Connection established\r\n\r\n')
  24.         channel.close()
  25.     except Exception as error:
  26.         print(error)
  27. transport.close()
  28. ssh.close()
  29.  
  30. """
  31. full error caught by sys.exc_info()
  32.  
  33. Socket exception: An existing connection was forcibly closed by the remote host (10054)
  34. b''
  35. (<class 'paramiko.ssh_exception.SSHException'>, SSHException('SSH session not active'), <traceback object at 0x00000205856BCA08>)
  36.  
  37.  
  38. full logged error by logging
  39. ERROR:paramiko.transport:Socket exception: An existing connection was forcibly closed by the remote host (10054)
  40. ERROR:__main__:SSH session not active
  41. Traceback (most recent call last):
  42.  File "C:\Users\CDN-deco\Desktop\xconnect.py", line 325, in <module>
  43.    channel = transport.open_channel('direct-tcpip',src_addr=('localhost',1301),dest_addr=(remoteproxy,remoteport))
  44.  File "C:\Users\CDN-deco\AppData\Local\Programs\Python\Python37\lib\site-packages\paramiko\transport.py", line 854, in open_channel
  45.    raise SSHException('SSH session not active')
  46. paramiko.ssh_exception.SSHException: SSH session not active
  47. """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement