|
| 1 | +importrequests |
| 2 | +fromthreadingimportThread, active_count |
| 3 | +fromqueueimportQueue |
| 4 | +importtime |
| 5 | + |
| 6 | +q=Queue() |
| 7 | + |
| 8 | +defscan_subdomains(domain): |
| 9 | +globalq |
| 10 | +whileTrue: |
| 11 | +# get the subdomain from the queue |
| 12 | +subdomain=q.get() |
| 13 | +# scan the subdomain |
| 14 | +url=f"http://{subdomain}.{domain}" |
| 15 | +try: |
| 16 | +requests.get(url) |
| 17 | +exceptrequests.ConnectionError: |
| 18 | +pass |
| 19 | +else: |
| 20 | +print("[+] Discovered subdomain:", url) |
| 21 | + |
| 22 | +# we're done with scanning that subdomain |
| 23 | +q.task_done() |
| 24 | + |
| 25 | + |
| 26 | +defmain(domain, n_threads, subdomains): |
| 27 | +globalq |
| 28 | + |
| 29 | +# fill the queue with all the subdomains |
| 30 | +forsubdomaininsubdomains: |
| 31 | +q.put(subdomain) |
| 32 | + |
| 33 | +fortinrange(n_threads): |
| 34 | +# start all threads |
| 35 | +worker=Thread(target=scan_subdomains, args=(domain,)) |
| 36 | +# daemon thread means a thread that will end when the main thread ends |
| 37 | +worker.daemon=True |
| 38 | +worker.start() |
| 39 | + |
| 40 | + |
| 41 | + |
| 42 | + |
| 43 | +defprint_n_threads(): |
| 44 | +whileTrue: |
| 45 | +print("Number of alive threads:", active_count()) |
| 46 | +time.sleep(10) |
| 47 | + |
| 48 | + |
| 49 | +if__name__=="__main__": |
| 50 | +importargparse |
| 51 | +parser=argparse.ArgumentParser(description="Faster Subdomain Scanner using Threads") |
| 52 | +parser.add_argument("domain", help="Domain to scan for subdomains without protocol (e.g without 'http://' or 'https://')") |
| 53 | +parser.add_argument("-l", "--wordlist", help="File that contains all subdomains to scan, line by line. Default is subdomains.txt", |
| 54 | +default="subdomains.txt") |
| 55 | +parser.add_argument("-t", "--num-threads", help="Number of threads to use to scan the domain. Default is 10", default=10, type=int) |
| 56 | + |
| 57 | +args=parser.parse_args() |
| 58 | +domain=args.domain |
| 59 | +wordlist=args.wordlist |
| 60 | +num_threads=args.num_threads |
| 61 | + |
| 62 | +# t = Thread(target=print_n_threads) |
| 63 | +# t.daemon = True |
| 64 | +# t.start() |
| 65 | + |
| 66 | +main(domain=domain, n_threads=num_threads, subdomains=open(wordlist).read().splitlines()) |
| 67 | +q.join() |
| 68 | + |
0 commit comments