-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathdead_records.py
169 lines (140 loc) · 5.69 KB
/
dead_records.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#!/usr/bin/python3
# Dependencies
import sys
import subprocess
import argparse
import os
import re
import pathlib
from time import sleep
from termcolor import colored, cprint
from concurrent.futures import ThreadPoolExecutor
from shlex import quote
# Banner
def banner():
print("\033[91m")
print(" ------------------------ ______")
print(" / |\ |\ | ----- \ |\_______________ (_____\\______________")
print(" / | \ | \ | / \ HH======#H###############H#######################")
print(' / | \ | \ | ------ \ \' ~""""""""""""""`##(_))#H\"""""Y########')
print(' / | / | \ | / \ )) \#H\ `"Y###')
print(' / | / | \| ----/ \ " }#H)')
print(' / _____ _____ \ _')
print(' / ( * ) ( * ) \ _ __ ___ ___ ___ _ __ __| |___')
print(" / \ | '__/ _ \/ __/ _ \| '__/ _` / __|")
print(' \ ___________________ / | | | __/ (_| (_) | | | (_| \__ \ ')
print(' \ /___________________\ / |_| \___|\___\___/|_| \__,_|___/')
print(' \ / ')
print(' ----------------------------------- ')
print("Press Control+C to stop anytime\033[0m\n")
# Check args
def args():
global subdomains_file
global threads
parser = argparse.ArgumentParser()
print("Usage example: python3 dead_records.py -w subdomains.txt -o1 dead.txt -o2 cname.txt\n")
parser.add_argument('-w', help='path to the list of subdomain file (required)', required=True)
parser.add_argument('-o1', help='found dead records output (required)', required=True)
parser.add_argument('-o2', help="found CNAME's from dead records output (required)", required=True)
parser.add_argument('-t', help='specify threads to be used (default: 2)', required=False, dest='threads')
args = parser.parse_args()
subdomains_file = open(sys.argv[2], "r").readlines()
if args.threads == None:
threads = 2
else:
threads = int(args.threads.rstrip())
# Filter dns records
def filter_dns(wordz):
filtration = str(wordz)
filt = "b'|Host|not found:|3|NXDOMAIN|\\n"
filt1 = re.sub(filt, '', filtration)
filt2 = filt1.replace("()", "")
filt3 = filt2.replace('[" ', '').replace('"]', "")
filt4 = filt3.replace("\\n'", "")
formatted = filt4.replace("\\", "\n").replace(" ", "")
return formatted
# Find dead DNS records
def dead_check(subz):
global show_dead
for s in subz:
cmd = "host " + quote(s).replace("\n", "");
p = subprocess.Popen([cmd], stdout=subprocess.PIPE, shell=True)
dead = p.stdout.read()
if "not found" in str(dead):
dead_temp = open("dead-temp.txt", "a+")
dead_temp.write(str(dead))
else:
continue
exist_check = pathlib.Path("dead-temp.txt")
if exist_check.exists() == True:
pass
else:
print("\033[91mNO DEAD RECORDS FOUND :(")
sys.exit(1)
cprint("\033[96m\033[4mFOUND DEAD RECORDS:\n\033[0m", attrs=['blink'])
read_dead = open("dead-temp.txt", "r").readlines()
show_dead = filter_dns(read_dead)
print("\033[93m")
return show_dead
# Check for CNAME's inside dead records
def CNAME_check(deadz):
for d in deadz:
cmd = "dig CNAME +short " + quote(d).replace("\n","")
p = subprocess.Popen([cmd], stdout=subprocess.PIPE, shell=True)
check = p.stdout.read()
if len(check) == 0:
print("\033[91m" + str(d), " --> \033[0m")
else:
print("\033[92m\033[4m" + str(d) + "\033[0m" + " --> " + "\033[92m\033[4m" + check.decode() + "\033[0m")
write_cname = open("cname-temp.txt", "a+")
cnamez = str(d) + " --> " + check.decode() + "\n"
write_cname.write(cnamez)
exist_check = pathlib.Path("cname-temp.txt")
if exist_check.exists() == True:
pass
else:
print("\033[91mNO CNAME'S FOUND :(")
sys.exit(1)
# Output
def output():
if len(sys.argv) > 4:
o1 = sys.argv[4]
found_dead = open(o1, "w")
found_dead.write(str(multithread()))
os.remove("dead-temp.txt")
cprint("\033[96m\033[4mCHECKING FOR CNAME's: \n\033[0m", attrs=['blink'])
dead = show_dead.split("\n")
dead.pop()
CNAME_check(dead)
# Write to temp file
def writeTemp():
if len(sys.argv) > 5:
o2 = sys.argv[6]
cname_temp = open("cname-temp.txt", "r").readlines()
found_dead_cnames = open(o2, "w")
found_dead_cnames.write(str(cname_temp))
os.remove("cname-temp.txt")
#Multithreadz
def multithread():
executor = ThreadPoolExecutor(threads)
future = executor.submit(dead_check, subdomains_file)
print(future.result())
#Informationz
def info():
print("\033[1m\033[95m\033[4mSEARCHING FOR DEAD DNS RECORDS: \033[00m\n")
print("\033[93m[-_-] Please sit back and grab a caffe, this might take a bit depending on the file size.\033[00m\n")
#Start from here
def main():
args()
banner()
info()
output()
writeTemp()
try:
if __name__ == "__main__":
main()
except KeyboardInterrupt:
print("\033[91mCtrl+C detected.\n Exiting..\033[0m")
os.remove("cname-temp.txt")
os.remove("dead-temp.txt")
sys.exit(1)