-
Notifications
You must be signed in to change notification settings - Fork 121
/
SDomDiscover.py
216 lines (166 loc) · 6.95 KB
/
SDomDiscover.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#!/usr/bin/python3
import signal
import requests
import sys
import re, json
import argparse
import dns.zone
import dns.resolver
import pydig
from time import sleep
class c:
PURPLE = '\033[95m'
BLUE = '\033[94m'
CYAN = '\033[96m'
GREEN = '\033[92m'
YELLOW = '\033[93m'
RED = '\033[91m'
END = '\033[0m'
UNDERLINE = '\033[4m'
def ctrl_c(sig, frame):
sys.exit(c.RED + "[!] Interrupt handler received, exiting..." + c.END)
signal.signal(signal.SIGINT, ctrl_c)
def banner():
print(c.YELLOW + ' _____ ')
print(' .-" "-. ')
print(' / o o \ ')
print(' / \ / \ ')
print(' / )-"-( \ ')
print(' / ( 6 6 ) \ ')
print(' / \ " / \ ')
print(' / )=( \ - By D3Ext')
print(' / o .--"-"--. o \ ')
print(' / I / - - \ I \ ')
print(' .--( (_}y/\ /\y{_) )--. ')
print('( ".___l\/__\_____/__\/l___," ) ')
print(' \ / ')
print(' "-._ o O o O o O o _,-" ')
print(' `--Y--.___________.--Y--\' ')
print(' |==.___________.==| ')
print(' `==.___________.==\' ' + c.END)
def parseArgs():
p = argparse.ArgumentParser(description="SDomDiscover - Silent Domain Discoverer - Abusing SSL transparency")
p.add_argument("-d", "--domain", help="domain to search its subdomains", required=True)
p.add_argument("-a", "--axfr", help="try a domain zone transfer attack", action='store_true', required=False)
p.add_argument("-m", "--mail", help="try to enumerate mail servers", action='store_true', required=False)
p.add_argument("-n", "--nameservers", help="try to enumerate the name servers", action='store_true', required=False)
p.add_argument("-i", "--ip", help="it reports the ip or ips of the domain", action='store_true', required=False)
p.add_argument("-o", "--output", help="file to store the scan output", required=False)
p.add_argument("--all", help="perform all the enumeration at once", action='store_true', required=False)
p.add_argument("--version", help="display the script version", action='store_true', required=False)
return p.parse_args()
def ns_enum(domain):
print(c.BLUE + "\n[" + c.END + c.GREEN + "+" + c.END + c.BLUE + "] Trying to discover valid name servers...\n" + c.END)
sleep(0.5)
data = pydig.query(domain, 'NS')
for ns in data:
l = len(ns)
ns = ns[:l-1]
print(c.YELLOW + ns + c.END)
def ip_enum(domain):
print(c.BLUE + "\n[" + c.END + c.GREEN + "+" + c.END + c.BLUE + "] Trying to discover the IPs...\n" + c.END)
sleep(0.5)
data = pydig.query(domain, 'A')
for ip in data:
print(c.YELLOW + ip + c.END)
def mail_enum(domain):
print(c.BLUE + "\n[" + c.END + c.GREEN + "+" + c.END + c.BLUE + "] Trying to discover valid mail servers...\n" + c.END)
sleep(0.5)
data = pydig.query(domain, 'MX')
for mail_output in data:
mail_output = mail_output.split(' ')[1]
l = len(mail_output)
mail_servers = mail_output[:l-1]
print(c.YELLOW + mail_servers + c.END)
def axfr(domain):
print(c.BLUE + "\n[" + c.END + c.GREEN + "*" + c.END + c.BLUE + "] Starting Domain Zone Transfer attack...\n" + c.END)
sleep(0.5)
ns_answer = dns.resolver.resolve(domain, 'NS')
for server in ns_answer:
print(c.YELLOW + "[*] Found NS: {}".format(server) + c.END)
ip_answer = dns.resolver.resolve(server.target, 'A')
for ip in ip_answer:
print(c.YELLOW + "[*] IP for {} is {}".format(server, ip) + c.END)
try:
zone = dns.zone.from_xfr(dns.query.xfr(str(ip), domain))
for host in zone:
print(c.YELLOW + "[" + c.END + c.GREEN + "+" + c.END + c.YELLOW + "] Found Host: {}".format(host) + c.END)
except Exception as e:
print(c.YELLOW + "[" + c.END + c.RED + "-" + c.END + c.YELLOW + "] NS {} refused zone transfer!".format(server) + c.END)
continue
def SDom(domain,filename):
banner()
print(c.BLUE + "\n[" + c.END + c.GREEN + "+" + c.END + c.BLUE + "] Discovering valid subdomains...\n" + c.END)
sleep(0.5)
r = requests.get("https://crt.sh/?q=" + domain + "&output=json", timeout=20)
formatted_json = json.dumps(json.loads(r.text), indent=4)
domains = re.findall(r'"common_name": "(.*?)"', formatted_json)
doms = sorted(set(domains))
if filename != None:
f = open(filename, "a")
print(c.YELLOW + "+" + "-"*39 + "+")
for value in doms:
if not value.startswith('*' + "." + domain):
if len(value) >= 10 and len(value) <= 14:
l = len(value)
print("| " + value + " \t\t\t|")
if filename != None:
f.write(value + "\n")
if len(value) >= 15 and len(value) <= 19:
l = len(value)
print("| " + value + "\t\t\t|")
if filename != None:
f.write(value + "\n")
if len(value) >= 20 and len(value) <= 24:
l = len(value)
print("| " + value + " \t\t|")
if filename != None:
f.write(value + "\n")
if len(value) >= 25 and len(value) <= 29:
l = len(value)
print("| " + value + "\t\t|")
if filename != None:
f.write(value + "\n")
print("+" + "-"*39 + "+" + c.END)
if filename != None:
f.close()
print(c.BLUE + "\n[+] Output stored in " + filename)
if __name__ == '__main__':
parse = parseArgs()
if parse.version:
print("\nSDomDiscover v1.0 - By D3Ext")
print("Contact me: <[email protected]>\n")
sys.exit(0)
if parse.output:
store_info=1
filename = parse.output
else:
filename = None
if parse.domain and parse.all:
domain = parse.domain
if domain.startswith('https://'):
domain = domain.split('https://')[1]
if domain.startswith('http://'):
domain = domain.split('http://')[1]
SDom(domain,filename)
axfr(domain)
mail_enum(domain)
ns_enum(domain)
ip_enum(domain)
sys.exit(0)
if parse.domain:
domain = parse.domain
if domain.startswith('https://'):
domain = domain.split('https://')[1]
if domain.startswith('http://'):
domain = domain.split('http://')[1]
SDom(domain,filename)
if parse.axfr:
axfr(domain)
if parse.mail:
mail_enum(domain)
if parse.nameservers:
ns_enum(domain)
if parse.ip:
ip_enum(domain)
sys.exit(0)