-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsub_enumerator.py
75 lines (57 loc) · 2.27 KB
/
sub_enumerator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# Sub Enumerator Tool By manthanghasadiya
import argparse
import threading
import requests
# Global variables for thread synchronization
checked_subdomains = 0
lock = threading.Lock()
unique_subdomains = set()
def enumerate_subdomains(subdomain_list, base_domain, thread_id):
global checked_subdomains
for subdomain in subdomain_list:
with lock:
if checked_subdomains >= total_subdomains:
break
checked_subdomains += 1
print(f"\rChecked {checked_subdomains} subdomains out of {total_subdomains}", end='')
flush()
url = f"http://{subdomain}.{base_domain}"
try:
response = requests.get(url)
if response.status_code == 200:
with lock:
unique_subdomains.add(url)
except requests.exceptions.RequestException:
pass
def flush():
import sys
sys.stdout.flush()
def save_subdomains(filename):
with open(filename, 'w') as file:
for subdomain in unique_subdomains:
file.write(subdomain + '\n')
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Subdomain Enumerator')
parser.add_argument('-d', '--domain', type=str, required=True, help='Base domain')
parser.add_argument('-w', '--wordlist', type=str, required=True, help='Path to subdomain wordlist')
parser.add_argument('-o', '--output', type=str, required=True, help='Path to output file')
parser.add_argument('--threads', type=int, default=4, help='Number of threads (default: 4)')
args = parser.parse_args()
base_domain = args.domain
with open(args.wordlist) as file:
subdomain_list = file.read().splitlines()
total_subdomains = len(subdomain_list)
num_threads = args.threads
threads = []
for i in range(num_threads):
thread = threading.Thread(target=enumerate_subdomains, args=(subdomain_list, base_domain, i))
threads.append(thread)
thread.start()
try:
for thread in threads:
thread.join()
except KeyboardInterrupt:
print("\n\nEnumeration interrupted. Saving valid subdomains...")
save_subdomains(args.output)
print("\nEnumeration Complete.")
print(f"\nUnique Valid Subdomains saved in {args.output}")