-
Notifications
You must be signed in to change notification settings - Fork 350
/
blackwidow
executable file
·317 lines (283 loc) · 13.4 KB
/
blackwidow
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
#!/usr/bin/python3
# blackwidow by @xer0dayz - Last Updated 20200717
# https://sn1persecurity.com
#
from bs4 import BeautifulSoup
from urllib.parse import urlparse
import requests, sys, os, atexit, optparse
from http import cookies
requests.packages.urllib3.disable_warnings()
OKBLUE='\033[94m'
OKRED='\033[91m'
OKGREEN='\033[92m'
OKORANGE='\033[93m'
COLOR1='\033[95m'
COLOR2='\033[96m'
RESET='\x1b[0m'
def readlinks (url):
try:
if len(cookies) > 2:
headers = {'Cookie': cookies}
r = requests.get(url, headers=headers, verify=False)
else:
r = requests.get(url, verify=False)
data = r.text
soup = BeautifulSoup(data, "lxml")
parsed_uri = urlparse(url)
domain = '{uri.netloc}'.format(uri=parsed_uri)
domain = domain.split(':')[0]
except Exception as ex:
print(ex)
urls = open("/tmp/" + domain + "_" + port + "-urls.txt","w+")
urls_saved = open(save_dir + domain + "_" + port + "-urls.txt","a")
forms_saved = open(save_dir + domain + "_" + port + "-forms.txt","a")
dynamic_saved = open(save_dir + domain + "_" + port + "-dynamic.txt","a")
emails_saved = open(save_dir + domain + "_" + port + "-emails.txt","a")
phones_saved = open(save_dir + domain + "_" + port + "-phones.txt","a")
subdomains_saved = open(save_dir + domain + "_" + port + "-subdomains.txt","a")
print ("")
print (OKGREEN + "==================================================================================================" + RESET)
print (OKGREEN + url)
print (OKGREEN + "==================================================================================================" + RESET)
for form in soup.find_all('form'):
#print (OKBLUE + "[+] Extracting form values...")
#print ("__________________________________________________________________________________________________" + OKORANGE)
#print (form)
#print (OKBLUE + "__________________________________________________________________________________________________")
#print (RESET)
forms_saved.write(url + "\n")
# PARSE LINKS
for link in soup.find_all('a'):
# IF LINK IS NOT NULL
if link.get('href') is not None:
parsed_uri = urlparse(link.get('href'))
linkdomain = '{uri.netloc}'.format(uri=parsed_uri)
if (domain != linkdomain) and (linkdomain != "") and (domain in linkdomain):
print (COLOR1 + "[+] Sub-domain found! " + linkdomain + " " + RESET)
subdomains_saved.write(linkdomain + "\n")
# IF LINK STARTS WITH HTTP
if link.get('href')[:4] == "http":
# SAME ORIGIN
if domain in link.get('href'):
# IF URL IS DYNAMIC
if "?" in link.get('href'):
print (OKRED + "[+] Dynamic URL found! " + link.get('href') + " " + RESET)
urls.write(link.get('href') + "\n")
urls_saved.write(link.get('href') + "\n")
dynamic_saved.write(link.get('href') + "\n")
else:
print (link.get('href'))
urls.write(link.get('href') + "\n")
urls_saved.write(link.get('href') + "\n")
# EXTERNAL LINK FOUND
#else:
# IF URL IS DYNAMIC
#if "?" in link.get('href'):
#print (COLOR2 + "[+] External Dynamic URL found! " + link.get('href') + " " + RESET)
#else:
#print (COLOR2 + "[i] External link found! " + link.get('href') + " " + RESET)
# IF URL IS DYNAMIC
elif "?" in link.get('href'):
print (OKRED + "[+] Dynamic URL found! " + url + "/" + link.get('href') + " " + RESET)
urls.write(url + "/" + link.get('href') + "\n")
urls_saved.write(url + "/" + link.get('href') + "\n")
dynamic_saved.write(url + "/" + link.get('href') + "\n")
# DOM BASED LINK
#elif link.get('href')[:1] == "#":
#print (OKBLUE + "[i] DOM based link found! " + link.get('href') + " " + RESET)
# TELEPHONE
elif link.get('href')[:4] == "tel:":
s = link.get('href')
phonenum = s.split(':')[1]
print (OKORANGE + "[i] Telephone # found! " + phonenum + " " + RESET)
phones_saved.write(phonenum + "\n")
# EMAIL
elif link.get('href')[:7] == "mailto:":
s = link.get('href')
email = s.split(':')[1]
print (OKORANGE + "[i] Email found! " + email + " " + RESET)
emails_saved.write(email + "\n")
# ELSE NORMAL LINK FOUND
else:
print (url + "/" + link.get('href'))
urls.write(url + "/" + link.get('href') + "\n")
urls_saved.write(url + "/" + link.get('href') + "\n")
print (OKGREEN + "__________________________________________________________________________________________________" + RESET)
def readfile():
filename = "/tmp/" + domain + "_" + port + "-urls.txt"
with open(filename) as f:
urls = f.read().splitlines()
for url in urls:
try:
readlinks(url)
except Exception as ex:
print(ex)
def logo():
version = "1.3"
print (OKRED + "")
print (OKRED + "")
print (OKRED + " _.._")
print (OKRED + " .' '.")
print (OKRED + " / __ \ ")
print (OKRED + " , | >< | ,")
print (OKRED + " . \ \ / / .")
print (OKRED + " \_'--`( )'--'_/")
print (OKRED + " .--'/()\'--.")
print (OKRED + "@xer0dayz / /` '' `\ \ ")
print (OKRED + " | |")
print (OKRED + " \ /")
print (OKRED + "")
print (RESET)
print (OKORANGE + " + -- --=[ https://sn1persecurity.com" + RESET)
print (OKORANGE + " + -- --=[ blackwidow v" + version + " by @xer0dayz " + RESET)
print (RESET)
def exit_handler():
os.system('sort -u ' + save_dir + domain + "_" + port + '-urls.txt > ' + save_dir + domain + "_" + port + '-urls-sorted.txt 2>/dev/null')
os.system('sort -u ' + save_dir + domain + "_" + port + '-forms.txt > ' + save_dir + domain + "_" + port + '-forms-sorted.txt 2>/dev/null')
os.system('sort -u ' + save_dir + domain + "_" + port + '-dynamic.txt > ' + save_dir + domain + "_" + port + '-dynamic-sorted.txt 2>/dev/null')
os.system('rm -f ' + save_dir + domain + "_" + port + '-dynamic-unique.txt 2>/dev/null')
os.system('touch ' + save_dir + domain + "_" + port + '-dynamic-unique.txt')
os.system('for a in `cat ' + save_dir + domain + "_" + port + '-dynamic-sorted.txt | cut -d \'?\' -f2 | sort -u | cut -d \'=\' -f1 | sort -u`; do for b in `egrep $a ' + save_dir + domain + "_" + port +'-dynamic.txt -m 1`; do echo $b >> ' + save_dir + domain + "_" + port + '-dynamic-unique.txt; done; done;')
os.system('sort -u ' + save_dir + domain + "_" + port + '-subdomains.txt > ' + save_dir + domain + "_" + port + '-subdomains-sorted.txt 2>/dev/null')
os.system('sort -u ' + save_dir + domain + "_" + port + '-emails.txt > ' + save_dir + domain + "_" + port + '-emails-sorted.txt 2>/dev/null')
os.system('sort -u ' + save_dir + domain + "_" + port + '-phones.txt > ' + save_dir + domain + "_" + port + '-phones-sorted.txt 2>/dev/null')
logo()
print (OKGREEN + "[+] URL's Discovered: \n" + save_dir + domain + "_" + port + "-urls-sorted.txt" + RESET)
print (OKGREEN + "__________________________________________________________________________________________________" + RESET)
os.system('cat ' + save_dir + domain + "_" + port + '-urls-sorted.txt')
print (RESET)
print (OKGREEN + "[+] Dynamic URL's Discovered: \n" + save_dir + domain + "_" + port + "-dynamic-sorted.txt" + RESET)
print (OKGREEN + "__________________________________________________________________________________________________" + RESET)
os.system('cat ' + save_dir + domain + "_" + port + '-dynamic-sorted.txt')
print (RESET)
print (OKGREEN + "[+] Form URL's Discovered: \n" + save_dir + domain + "_" + port + "-forms-sorted.txt" + RESET)
print (OKGREEN + "__________________________________________________________________________________________________" + RESET)
os.system('cat ' + save_dir + domain + "_" + port + '-forms-sorted.txt')
print (RESET)
print (OKGREEN + "[+] Unique Dynamic Parameters Discovered: \n" + save_dir + domain + "_" + port + "-dynamic-unique.txt" + RESET)
print (OKGREEN + "__________________________________________________________________________________________________" + RESET)
os.system('cat ' + save_dir + domain + "_" + port + '-dynamic-unique.txt')
print (RESET)
print (OKGREEN + "[+] Sub-domains Discovered: \n" + save_dir + domain + "_" + port + "-subdomains-sorted.txt" + RESET)
print (OKGREEN + "__________________________________________________________________________________________________" + RESET)
os.system('cat ' + save_dir + domain + "_" + port + '-subdomains-sorted.txt')
print (RESET)
print (OKGREEN + "[+] Emails Discovered: \n" + save_dir + domain + "_" + port + "-emails-sorted.txt" + RESET)
print (OKGREEN + "__________________________________________________________________________________________________" + RESET)
os.system('cat ' + save_dir + domain + "_" + port + '-emails-sorted.txt')
print (RESET)
print (OKGREEN + "[+] Phones Discovered: \n" + save_dir + domain + "_" + port + "-phones-sorted.txt" + RESET)
print (OKGREEN + "__________________________________________________________________________________________________" + RESET)
os.system('cat ' + save_dir + domain + "_" + port + '-phones-sorted.txt')
print (RESET)
print (OKRED + "[+] Loot Saved To: \n" + save_dir + RESET)
print (OKRED + "__________________________________________________________________________________________________" + RESET)
print (RESET)
os.system('rm -f ' + save_dir + domain + "_" + port + '-dynamic.txt')
os.system('rm -f ' + save_dir + domain + "_" + port + '-forms.txt')
os.system('rm -f ' + save_dir + domain + "_" + port + '-emails.txt')
os.system('rm -f ' + save_dir + domain + "_" + port + '-phones.txt')
os.system('rm -f ' + save_dir + domain + "_" + port + '-urls.txt')
os.system('rm -f ' + save_dir + domain + "_" + port + '-subdomains.txt')
os.system('rm -f /tmp/' + domain + "_" + port + '-urls.txt 2> /dev/null')
if scan == "y":
os.system('for a in `cat ' + save_dir + domain + "_" + port + '-dynamic-unique.txt`; do python3 /usr/bin/injectx.py -u $a; done;')
else:
pass
logo()
globalURL = "globalBadness"
if len(sys.argv) < 2:
print ("You need to specify a URL to scan. Use --help for all options.")
sys.exit()
else:
parser = optparse.OptionParser()
parser.add_option('-u', '--url',
action="store", dest="url",
help="Full URL to spider", default="")
parser.add_option('-d', '--domain',
action="store", dest="domain",
help="Domain name to spider", default="")
parser.add_option('-c', '--cookie',
action="store", dest="cookie",
help="Cookies to send", default="")
parser.add_option('-l', '--level',
action="store", dest="level",
help="Level of depth to traverse", default="2")
parser.add_option('-s', '--scan',
action="store", dest="scan",
help="Scan all dynamic URL's found", default="n")
parser.add_option('-p', '--port',
action="store", dest="port",
help="Port for the URL", default="80")
parser.add_option('-v', '--verbose',
action="store", dest="verbose",
help="Set verbose mode ON", default="y")
options, args = parser.parse_args()
target = str(options.url)
domain = str(options.domain)
cookies = str(options.cookie)
max_depth = str(options.level)
scan = str(options.scan)
port = str(options.port)
verbose = str(options.verbose)
ans = scan
level = 1
# using a domain and a port or a URL?
if ":" not in target:
if len(str(target)) > 6:
url = target + ":" + port #big change here
else:
url = "http://" + str(domain) + ":" + port
if len(str(domain)) > 4:
target = "http://" + domain + ":" + port
else:
print (target)
urlparse(target)
parsed_uri = urlparse(target)
domain = '{uri.netloc}'.format(uri=parsed_uri)
else:
url = target
globalURL = target
parsed_uri = urlparse(target)
domainWithPort = '{uri.netloc}'.format(uri=parsed_uri)
domain = domainWithPort.split(':')[0]
if (len(target.split(':')) > 2):
portWithPossiblePath = target.split(':')[2]
port = portWithPossiblePath.split('/')[0]
else:
port = port
save_dir = "/usr/share/blackwidow/" + domain + "_" + port + "/"
os.system('mkdir -p ' + save_dir + ' 2>/dev/null')
atexit.register(exit_handler)
# FILE INIT
urls_file = "/tmp/" + domain + "_" + port + "-urls.txt"
urls_saved_file = save_dir + domain + "_" + port + "-urls.txt"
forms_saved_file = save_dir + domain + "_" + port + "-forms.txt"
subdomain_file = save_dir + domain + "_" + port + "-subdomains.txt"
emails_file = save_dir + domain + "_" + port + "-emails.txt"
phones_file = save_dir + domain + "_" + port + "-phones.txt"
urls = open(urls_file,"w+")
urls.close()
urls_saved = open(urls_saved_file,"w+")
urls_saved.close()
forms_saved = open(forms_saved_file,"w+")
forms_saved.close()
subdomains = open(subdomain_file,"w+")
subdomains.close()
emails = open(emails_file,"w+")
emails.close()
phones = open(phones_file,"w+")
phones.close()
try:
readlinks(url)
except Exception as ex:
print(ex)
while (int(level) <= int(max_depth)):
level = level+1
if (int(level) <= int(max_depth)):
try:
readfile()
except Exception as ex:
print(ex)
else:
break