-
-
Notifications
You must be signed in to change notification settings - Fork 53
/
cwff.py
629 lines (589 loc) · 25.1 KB
/
cwff.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
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
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
import os, requests, concurrent.futures, sys, time, datetime, re, tldextract, argparse
from bs4 import BeautifulSoup as bs
from user_agent import generate_user_agent
from urllib import parse
import api_keys, filter_model
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
class color:
reset = '\033[0m'
green = reset + '\033[32m'
blue = reset + '\033[94m'
red = reset + '\033[31m'
white = reset + '\x1b[37m'
magneta = reset + '\x1b[35m'
cyan = reset + '\x1b[36m'
Bold = "\033[1m"
underline = "\033[4m"
class collector:
def __init__(self, domain, threads=1000, recursion=False):
self.scheme = parse.urlparse(domain).scheme or "http"
self.__parsed_domain = tldextract.extract(domain)
if self.__parsed_domain.subdomain:
self.domain = ".".join(
[
self.__parsed_domain.subdomain,
self.__parsed_domain.domain,
self.__parsed_domain.suffix
]
)
else:
self.domain = self.__parsed_domain.registered_domain
self.__headers = {
'Accept': 'text/html,application/xhtml+xml,application/xml,application/json;q=0.9,image/webp,*/*;q=0.8',
'Accept-Language': 'en-US,en;q=0.8', 'Accept-Encoding': 'gzip, deflate', 'User-agent': generate_user_agent(),
'Cache-Control': 'max-age=0', 'Upgrade-Insecure-Requests': '1', 'Connection': 'close'
}
self.endpoints = set()
self.parameters = set()
self.js_files = []
self.wayback_urls = []
self.builtwith_connected_websites = set()
self.recursion = recursion
# Regex is borrowed from https://github.com/GerbenJavado/LinkFinder but mine m ThreadPoolExecutorodified/improved :)
self.endpoint_regex = re.compile(r"""
(%s(?:"|')
(?:
((?:/|\.\./|\./)
[^"'><,;| *()(%%$^/\\\[\]]
[^"'><,;|()]{1,})
|
([a-zA-Z0-9_\-/]{1,}/
[a-zA-Z0-9_\-/]{1,}\.[a-z]{1,4}
(?:[\?|/][^"|']{0,}|))
|
([a-zA-Z0-9_\-]{1,}
\.(?:php|asp|aspx|jsp)
(?:\?[^"|']{0,}|))
)
(?:"|')%s)
""" % ("",""), re.VERBOSE)
self.__max_connections = threads
#### First helper functions
def __add_endpoints(self, endpoints_list):
# Just to avoid the repeat of converting list to set for removing dups and so on
for endpoint in endpoints_list:
if endpoint.startswith("/"):
endpoint = endpoint[1:]
if endpoint.endswith("/"):
enpoint = endpoint[:-1]
self.endpoints.add(endpoint)
self.endpoints = set(sorted(self.endpoints))
def remove_endpoints(self, end=[], contain=[], matches=[]):
# Hmm, just to be sure
old = len(self.endpoints)
self.endpoints = { e[1:] if e.startswith("/") else e for e in self.endpoints}
self.endpoints = { e[:-1] if e.endswith("/") else e for e in self.endpoints}
# Brace yourself I'm gonna use magic :D
if end or contain or matches:
if end:
end = [ e.strip().replace("*","") for e in end]
self.endpoints = set(filter( lambda x: not x.endswith(tuple(end)), self.endpoints))
if contain:
self.endpoints = set([
e for e in self.endpoints if
all(s.strip().replace("*","") not in e for s in contain)
])
if matches:
for regex in matches:
search = re.compile(regex)
self.endpoints = set([e for e in self.endpoints if not search.match(e)])
print(f"{color.green}[+] {color.reset}Filtered unwanted endpoints. (Gone from {old} to {len(self.endpoints)})", flush=True)
def splitter(self):
old = len(self.endpoints)
result = set()
for path in self.endpoints:
result.add(path)
current = path
if current.startswith("/"):
current = current[1:]
while current:
s = os.path.split(current)
current = s[0]
for sub in s:
if sub.startswith("/"):
sub = sub[1:]
if sub!="":
result.add(sub)
self.endpoints = set(sorted(result))
print(f"{color.green} [+] {color.reset}Generated new endpoints with recursion, increased from {old} to {len(self.endpoints)}", flush=True)
def cleaner(self, url):
for parameter in list(parse.parse_qs(parse.urlparse(url).query).keys()):
self.parameters.add(parameter)
path = parse.urlparse(url).path.replace("//","/").split("?")[0]
return path
### Now let's get to work
def get_urls_from_waybackarchive(self,endswith="", search_subdomains=False):
if search_subdomains:
count_url = f"https://web.archive.org/cdx/search/cdx?url=*.{self.domain}/*&showNumPages=true"
page_url = f"https://web.archive.org/cdx/search/cdx?url=*.{self.domain}/*&filter=statuscode:200&output=json&fl=original&collapse=urlkey&page="
else:
count_url = f"https://web.archive.org/cdx/search/cdx?url={self.domain}/*&showNumPages=true"
page_url = f"https://web.archive.org/cdx/search/cdx?url={self.domain}/*&filter=statuscode:200&output=json&fl=original&collapse=urlkey&page="
def scrape( wanted_urls, url, end):
try:
session = requests.session()
data = session.get(url, headers=self.__headers, timeout=20, verify=False).json()
if data:
urls = set([ x[0] for x in data[1:]])
for u in urls:
# My funny workaround for fixing shitty results lol
u = u.split("?")[0].strip().replace("://",":blah~rrr~blah:").replace("//","/").replace(":blah~rrr~blah:","://").replace("\/","/") # Mainly to get the real js files
fu = u.strip().replace("://",":blah~rrr~blah:").replace("//","/").replace(":blah~rrr~blah:","://").replace("\/","/") # To extract parameters later
if u not in self.wayback_urls:
self.wayback_urls.append(u)
if end:
if u.endswith(end) and u not in wanted_urls:
wanted_urls.append(fu)
else:
if u not in wanted_urls:
wanted_urls.append(fu)
if end:
sys.stdout.write("\r | "+f"Collected a total of {len(self.wayback_urls)} valid unique urls, and {len(wanted_urls)} (*{endswith}) file(s). (Real-time filtering) ")
sys.stdout.flush()
else:
sys.stdout.write("\r | "+f"Collected a total of {len(self.wayback_urls)} valid unique urls. (Real-time filtering) ")
sys.stdout.flush()
session.close()
except Exception as e:
# print(e)
# print(url) # some pages from web archive would be empty so it would give json error
pass
wanted_urls = []
try:
count = int(requests.get(count_url).text)
sys.stdout.write(f" | Querying wayback machine for urls in concurrent...\n")
sys.stdout.flush()
with concurrent.futures.ThreadPoolExecutor(max_workers=self.__max_connections) as executor:
futures = []
start = time.time()
if endswith:
sys.stdout.write("\r | "+f"Collected a total of {len(self.wayback_urls)} valid unique urls, and {len(wanted_urls)} (*{endswith}) file(s). (Real-time filtering) ")
sys.stdout.flush()
else:
sys.stdout.write("\r | "+f"Collected a total of {len(self.wayback_urls)} valid unique urls. (Real-time filtering) ")
sys.stdout.flush()
for page in range(count):
futures.append( executor.submit(scrape, wanted_urls, page_url+str(page), endswith) )
time.sleep(0.5)
for cdx_search in concurrent.futures.as_completed(futures):
pass
del futures[:]
sys.stdout.write(f"\n{color.blue} |{color.reset} Wayback Elapsed time {time.strftime('%M.%Sm', time.gmtime(time.time()-start))}.\n")
sys.stdout.flush()
except Exception as e:
print(e)
pass
return wanted_urls
def collect_js_files(self, search_subdomains=False):
sys.stdout.write(f"{color.green}[+]{color.reset} Collecting js files..\n")
sys.stdout.flush()
start = time.time()
while True:
collected = []
sys.stdout.write("\r | "+"Collected a total of 0 valid unique js files using parser.")
sys.stdout.flush()
try:
data = requests.get(f"{self.scheme}://{self.domain}", headers=self.__headers, timeout=10).text
soup = bs(data,'html.parser')
script_tags = soup.findAll("script", {"type" : "text/javascript"})
for tag in script_tags:
sys.stdout.write("\r | "+f"Collected a total of {len(collected)} valid unique js files using parser.")
sys.stdout.flush()
try:
url = tag["src"]
uu = parse.urlparse(url)
if url.startswith("/"):
url = f"{self.scheme}://{self.domain}"+uu.path
else:
url = uu.scheme+"://"+uu.netloc.split(":")[0].split("/")[0]+uu.path
if url not in collected:
collected.append(url)#+uu.params)
except:
pass
break
except Exception as e:
# print(e)
pass
sys.stdout.write(f"\n{color.blue} |{color.reset} Parser Elapsed time {time.strftime('%M.%Sm', time.gmtime(time.time()-start))}.\n | \n")
sys.stdout.flush()
collected.extend(self.get_urls_from_waybackarchive(endswith=".js", search_subdomains=search_subdomains))
collected = sorted(set(collected))
worth_read = []
for js in collected:
not_lib = False
for keyword in [".min.", "jquery", "bootstrap", "tether", "popper", "backbone", "vue", "react", "ember", "angular", "polymer", "ext"]:
if keyword in js.lower():
break
else:
# If no keyword is found in this js files,
not_lib = True
if not_lib:
worth_read.append(js)
sys.stdout.write(f"{color.cyan} |{color.green} Total collected: {len(collected)} js files! (Possible {len(worth_read)} written by them){color.reset}\n\n")
self.js_files = collected
return {"all":collected, "worth_read":worth_read}
def collect_endpoints_from_js_files(self, js_urls=[]):
total_endpoints = list()
def grabber(js_file):
result = {"file":js_file, "endpoints":set()}
try:
req = requests.get(js_file, verify=False, timeout=30)
js = req.text.replace("\/","/")
except requests.exceptions.RequestException:
return result
except Exception as e:
print(e, flush=True)
return result
else:
endpoints = self.endpoint_regex.findall(js)
if endpoints:
endpoints = [e[1] for e in endpoints]
for endpoint in endpoints:
if endpoint:
result['endpoints'].add(endpoint)
return result
###################################
if not js_urls:
js_urls = self.js_files
if js_urls:
sys.stdout.write(f"{color.green}[+]{color.reset} Collecting endpoints from {len(js_urls)} js file(s)...\n")
sys.stdout.flush()
with concurrent.futures.ThreadPoolExecutor(max_workers=(self.__max_connections) ) as executor:
futures = []
start = time.time()
for js_url in js_urls:
sys.stdout.write("\r | Parsing js files in concurrent...")
sys.stdout.flush()
futures.append(executor.submit(grabber, js_url))
sys.stdout.write("\r | Collected 0 endpoint(s) from js files...")
sys.stdout.flush()
try:
for check in concurrent.futures.as_completed(futures):
result = check.result()
if result and result['endpoints']:
for endpoint in result['endpoints']:
total_endpoints.append(self.cleaner(endpoint))
total_endpoints = sorted(set(total_endpoints))
sys.stdout.write("\r | Collected {} endpoint(s) from js files...".format(len(total_endpoints)))
sys.stdout.flush()
except Exception as e:
print(e, flush=True)
pass
finally:
del futures[:]
sys.stdout.write(f"\n{color.blue} |{color.reset} Elapsed time {time.strftime('%M.%Sm', time.gmtime(time.time()-start))}.\n | \n")
sys.stdout.flush()
self.__add_endpoints(total_endpoints)
def wayback_endpoints(self):
total_endpoints = []
if self.wayback_urls:
sys.stdout.write(f"{color.green}[+]{color.reset} Collecting endpoints from collected wayback url(s)...\n")
sys.stdout.flush()
start = time.time()
# Figured out that sequential parsing in this CPU-Bound function is faster 1.5x than concurrent processs pool
sys.stdout.write("\r | Sequential parsing...")
sys.stdout.flush()
number = 0
for wayback_url in self.wayback_urls:
number +=1
total_endpoints.append(self.cleaner(wayback_url))
total_endpoints = sorted(set(total_endpoints))
sys.stdout.write("\r | Found {} endpoint(s) (Total progress:{}/{})".format( len(total_endpoints),number,len(self.wayback_urls)) )
sys.stdout.flush()
sys.stdout.write(f"\n{color.blue} |{color.reset} Elapsed time {time.strftime('%M.%Sm', time.gmtime(time.time()-start))}.\n |\n")
sys.stdout.flush()
self.__add_endpoints(total_endpoints)
def commoncrawl_endpoints(self, search_subdomains=False):
def scrape(wanted_urls, url):
try:
session = requests.session()
data = session.get(url, headers=self.__headers, timeout=20).text
if data:
urls = set(data.splitlines())
for u in urls:
# My funny workaround for fixing shitty results lol
u = u.replace("://",":blah~rrr~blah:").replace("//","/").replace(":blah~rrr~blah:","://").replace("\/","/")
wanted_urls.add(u)
sys.stdout.write("\r | "+f"Collected a total of {len(urls)} valid unique urls. (Real-time filtering) ")
sys.stdout.flush()
session.close()
except Exception as e:
# print(e)
pass
wanted_urls,total_endpoints = set(),[]
try:
# Dynamically allocating cdx indexes
while True:
try:
cdx_json = requests.get("http://index.commoncrawl.org/collinfo.json").json()
cdx_urls = [cdx['cdx-api'] for cdx in cdx_json]
if search_subdomains:
domain_part = f"?url=*.{self.domain}/*&fl=url&filter==status:200"#&output=json"
else:
domain_part = f"?url={self.domain}/*&fl=url&filter==status:200"#&output=json"
break
except:
continue
sys.stdout.write(f"{color.green}[+]{color.reset} Querying commoncrawl cdx for urls in concurrent...\n")
sys.stdout.flush()
with concurrent.futures.ThreadPoolExecutor(max_workers=self.__max_connections ) as executor:
futures = []
sys.stdout.write("\r | "+f"Collected a total of {len(wanted_urls)} valid unique urls. (Real-time filtering) ")
sys.stdout.flush()
start = time.time()
for cdx_part in cdx_urls:
url = cdx_part + domain_part
futures.append( executor.submit(scrape, wanted_urls, url) )
time.sleep(0.5)
for cdx_index in concurrent.futures.as_completed(futures):
pass
sys.stdout.write("\r | "+f"Collected a total of {len(wanted_urls)} valid unique urls. (Real-time filtering) ")
sys.stdout.flush()
del futures[:]
except Exception as e:
# print(e)
# traceback.print_exc()
pass
else:
# Now let's collect endpoints, code copied from above ofc
sys.stdout.write(f"\n{color.green} | {color.reset}Collecting endpoints from collected commoncrawl url(s)...\n")
sys.stdout.flush()
sys.stdout.write("\r | Sequential parsing...")
sys.stdout.flush()
number = 0
for commoncrawl_url in wanted_urls:
number +=1
total_endpoints.append(self.cleaner(commoncrawl_url))
total_endpoints = sorted(set(total_endpoints))
sys.stdout.write("\r | Found {} endpoint(s) (Total progress:{}/{})".format( len(total_endpoints),number,len(wanted_urls)) )
sys.stdout.flush()
sys.stdout.write(f"\n{color.blue} |{color.reset} Total elapsed time {time.strftime('%M.%Sm', time.gmtime(time.time()-start))}.\n |\n")
sys.stdout.flush()
self.__add_endpoints(total_endpoints)
def alienvault_endpoints(self):
url = f"https://otx.alienvault.com/api/v1/indicators/hostname/{self.domain}/url_list?limit=200&page="
sys.stdout.write(f"{color.green}[+]{color.reset} Collecting endpoints from Alienvault OTX url(s)...\n")
sys.stdout.flush()
total_endpoints = []
start = time.time()
for page in range(10000):
try:
req = requests.get(url+str(page), headers=self.__headers)
json = req.json()
if json["url_list"]:
for domain in json["url_list"]:
total_endpoints.append(self.cleaner(domain["url"]))
total_endpoints = sorted(set(total_endpoints))
sys.stdout.write("\r | Found {} endpoint(s).".format(len(total_endpoints)))
sys.stdout.flush()
if not json["has_next"]:
break
except requests.exceptions.RequestException:
break
except Exception as e:
print(e, flush=True)
break
sys.stdout.write(f"\n{color.blue} |{color.reset} Elapsed time {time.strftime('%M.%Sm', time.gmtime(time.time()-start))}.\n |\n")
sys.stdout.flush()
self.__add_endpoints(total_endpoints)
def builtwith_relationships(self):
total_endpoints = []
def grabber(url):
result = set()
try:
req = requests.get(url, verify=False, timeout=30)
data = req.text.replace("\/","/")
except requests.exceptions.RequestException:
return result
except Exception as e:
print(e, flush=True)
return result
else:
endpoints = self.endpoint_regex.findall(data)
if endpoints:
endpoints = [e[1] for e in endpoints]
for endpoint in endpoints:
if endpoint:
result.add(endpoint)
return result
##########################
if api_keys.builtwith:
print(f"{color.green}[+]{color.reset} Collecting connected website using builtwith api...")
start = time.time()
req = requests.get(f"https://api.builtwith.com/rv1/api.json?KEY={api_keys.builtwith}&LOOKUP={self.domain}", headers=self.__headers)
if req:
sys.stdout.write("\r | Found {} connected website(s) in the relationship profile!".format(len(self.builtwith_connected_websites)))
sys.stdout.flush()
j = req.json()
for Id in j["Relationships"][0]["Identifiers"]:
for match in Id["Matches"]:
d = match.get("Domain","")
if d:
self.builtwith_connected_websites.add(d)
sys.stdout.write("\r | Found {} connected website(s) in the relationship profile!".format(len(self.builtwith_connected_websites)))
sys.stdout.flush()
# and we are in business :v
with concurrent.futures.ThreadPoolExecutor(max_workers=self.__max_connections ) as executor:
futures = []
sys.stdout.write("\n | Collecting endpoints from connected websites...")
sys.stdout.flush()
for url in self.builtwith_connected_websites:
futures.append(executor.submit(grabber, "https://"+url))
sys.stdout.write("\r | Collected 0 endpoint(s) from connected websites...")
sys.stdout.flush()
try:
for check in concurrent.futures.as_completed(futures):
result = check.result()
if result:
for endpoint in result:
total_endpoints.append(self.cleaner(endpoint))
total_endpoints = sorted(set(total_endpoints))
sys.stdout.write("\r | Collected {} endpoint(s) from connected websites...".format(len(total_endpoints)))
sys.stdout.flush()
except Exception as e:
print(e, flush=True)
pass
finally:
del futures[:]
sys.stdout.write(f"\n{color.blue} |{color.reset} Elapsed time {time.strftime('%M.%Sm', time.gmtime(time.time()-start))}.\n")
sys.stdout.flush()
self.__add_endpoints(total_endpoints)
else:
print(f"{color.red} [!] Please set builtwith api key first in {color.underline}api_keys.py{color.red} ( Free account at: https://builtwith.com/signup )")
def github_endpoints(self, repo_url):
url = "https://api.github.com/repos/{}/{}/git/trees/master?recursive={}"
total_endpoints,recursion = set(),0
if self.recursion:
recursion = 1
try:
parse = repo_url.split("github.com/")[1].split("/")
user = parse[0]
repo = parse[1]
except:
print(color.red+" [!] Invalid github url! Example: https://github.com/google/flax")
else:
sys.stdout.write(f"{color.green}[+]{color.reset} Collecting endpoints from Github repo...\n")
sys.stdout.flush()
start = time.time()
req = requests.get(url.format(user, repo, recursion), verify=False)
data = req.json()
for path in data["tree"]:
total_endpoints.add(path["path"])
sys.stdout.write("\r | Collected {} endpoint(s) from github...".format(len(total_endpoints)))
sys.stdout.flush()
sys.stdout.write(f"\n{color.blue} |{color.reset} Elapsed time {time.strftime('%M.%Sm', time.gmtime(time.time()-start))}.\n |\n")
sys.stdout.flush()
self.__add_endpoints(total_endpoints)
def juicy_files_endpoints(self):
sys.stdout.write(f"{color.green}[+]{color.reset} Checking sitemap and robots for endpoints...\n")
sys.stdout.flush()
start = time.time()
# First let's take a look at sitemap
total_endpoints = []
try:
req = requests.get(f"{self.scheme}://{self.domain}/sitemap.xml")
if req:
xml = req.text
# I wrote this simple regex instead of the headache of xml parsers and installing them
xml_regex = re.compile("<loc>(.*)</loc>")
urls = xml_regex.findall(xml)
for url in urls:
total_endpoints.append(self.cleaner(url))
sys.stdout.write("\r | Found {} endpoint(s)...".format(len(total_endpoints)))
sys.stdout.flush()
except requests.exceptions.RequestException:
pass
except Exception as e:
print(e, flush=True)
# Now let's check robots file
try:
req = requests.get(f"{self.scheme}://{self.domain}/robots.txt")
if req:
data = req.text
# It ain't much but it's honest work :"D
endpoints = re.compile("/.*/").findall(data)
endpoints = [e.replace("/*/","") for e in endpoints]
for endpoint in endpoints:
total_endpoints.append(self.cleaner(endpoint))
sys.stdout.write("\r | Found {} endpoint(s)...".format(len(total_endpoints)))
sys.stdout.flush()
except requests.exceptions.RequestException:
pass
except Exception as e:
print(e, flush=True)
# May add more files in the future
total_endpoints = sorted(set(total_endpoints))
sys.stdout.write("\r | Found {} endpoint(s)...".format(len(total_endpoints)))
sys.stdout.flush()
sys.stdout.write(f"\n{color.blue} |{color.reset} Elapsed time {time.strftime('%M.%Sm', time.gmtime(time.time()-start))}.\n |\n")
sys.stdout.flush()
self.__add_endpoints(total_endpoints)
# TODO: recursive merge of endpoints directories
def main_logic(site, args):
threads = 1000
if args.threads:
threads = int(args.threads)
collect = collector(site, threads, bool(args.recursive))
print(f"{color.white}\t\t - Maximum concurrent threads:{color.reset}{color.white} {collect._collector__max_connections}{color.reset}\n")
if collect.domain:
js_files = collect.collect_js_files(bool(args.subdomains))
if args.js_libraries:
collect.collect_endpoints_from_js_files(js_files["all"])
else:
collect.collect_endpoints_from_js_files(js_files["worth_read"])
collect.wayback_endpoints()
collect.commoncrawl_endpoints(bool(args.subdomains))
collect.alienvault_endpoints()
if args.juicy_files:
collect.juicy_files_endpoints()
if args.github:
collect.github_endpoints(args.github)
if args.connected_websites:
collect.builtwith_relationships()
if args.use_filter_model:
collect.remove_endpoints(filter_model.exclude_endswith, filter_model.exclude_contain, filter_model.remove_regex)
else:
collect.remove_endpoints()
if args.recursive:
collect.splitter()
outdir = collect.domain
if args.o:
if not os.path.isdir(args.o):
os.mkdir(args.o)
outdir = args.o
else:
if not os.path.isdir(outdir):
os.mkdir(outdir)
with open(os.path.join(outdir,"endpoints.txt"), "w") as f:
for line in sorted(collect.endpoints):
f.write(line+"\n")
if collect.parameters:
with open(os.path.join(outdir,"parameters.txt"), "w") as f:
for line in sorted(collect.parameters):
f.write(line+"\n")
print(f"{color.blue}[>] Written a total of unique {len(collect.endpoints)} endpoint(s) and {len(collect.parameters)} parameter(s).{color.reset}", flush=True)
if __name__ == '__main__':
print(f"""{color.green}
e88'Y88 Y8b Y8b Y888P 888'Y88 888'Y88
d888 'Y Y8b Y8b Y8P 888 ,'Y 888 ,'Y
C8888 Y8b Y8b Y 888C8 888C8
Y888 ,d Y8b Y8b 888 " 888 " {color.red}CWFF By {color.Bold}Karim 'D4Vinci' Shoair{color.red} - {color.magneta}V1.0{color.green}
"88,d88 Y8P Y 888 888 {color.blue}{color.Bold} - Creating your (C)ustom (W)ordlist (F)or (F)uzzing -{color.reset}""")
parser = argparse.ArgumentParser(prog='CWFF')
parser.add_argument("domain", help="Target website(ofc)")
parser.add_argument("--threads", help="The number of maximum concurrent threads to use (Default:1000)")
parser.add_argument("--github", help="Collect endpoints from a given github repo (ex:https://github.com/google/flax)")
parser.add_argument("--subdomains", help="Extract endpoints from subdomains also while search in the wayback machine!",action="store_true")
parser.add_argument("--recursive", help="Work on extracted endpoints recursively (Adds more endpoints but less accurate sometimes)!",action="store_true")
parser.add_argument("--js-libraries", help="Extract endpoints from JS libraries also, not just the JS written by them!",action="store_true")
parser.add_argument("--connected-websites", help="Include endpoints extracted from connected websites",action="store_true")
parser.add_argument("--juicy-files", help="Include endpoints extracted from juicy files like sitemap.xml and robots.txt",action="store_true")
# Using filter model is better because argparse could mess up the regex flag :3
# parser.add_argument("--exclude-endswith", help="Exclude from the results the endpoints that end with the given strings (separated with comma)")
# parser.add_argument("--exclude-contain", help="Exclude from the results the endpoints that has the given strings (separated with comma)")
# parser.add_argument("--remove-regex", help="Remove any endpoint that 'match' this regex.", action='append')
parser.add_argument("--use-filter-model", help="Filter result endpoints with filter_model file", action='store_true')
parser.add_argument("-o", help="The output directory for the endpoints and parameters. (Default: website name)")
args = parser.parse_args()
main_logic(args.domain, args)