-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpath_crawler.py
More file actions
64 lines (53 loc) · 2.41 KB
/
Copy pathpath_crawler.py
File metadata and controls
64 lines (53 loc) · 2.41 KB
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
import requests
import urllib3
import logging
from concurrent.futures import ThreadPoolExecutor
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
#logging.getLogger("urllib3").setLevel(logging.CRITICAL)
def getwordlist(input_file="paths.txt"):
wordlist = []
with open(input_file, 'r') as f:
for line in f:
wordlist.append(line.strip())
return wordlist
#could use another function and parse http and https
def check_path(base_url, i, path):
false_pos_lengths = ()
found_paths = {}
i= i+1
try:
url = f"http://{base_url}/{path}"
print(f"requesting {url}: line {i}")
r = requests.get(url, timeout=1, verify=False)
if r.status_code != 404 and len(r.content) not in false_pos_lengths:
if not false_pos_lengths:
false_pos_lengths = (0, len(requests.get(f"https://{base_url}/GARBAGEEEMAN", timeout=3, verify=False).content))
print(f"added {len(r.content)} to false positives")
print(f"[{r.status_code}] {url} (length: {len(r.content)})")
found_paths[url] = {"status_code": r.status_code, "content_len": len(r.content)}
except requests.RequestException:
pass
try:
url = f"https://{base_url}/{path}"
print(f"requesting {url}")
r = requests.get(url, timeout=1, verify=False)
if r.status_code != 404 and len(r.content) not in false_pos_lengths:
if not false_pos_lengths:
false_pos_lengths = (0, len(requests.get(f"https://{base_url}/GARBAGEEEMAN", timeout=3, verify=False).content))
print(f"added {len(r.content)} to false positives")
print(f"[{r.status_code}] {url} (length: {len(requests.get(f"https://{base_url}/GARBAGEEEMAN", timeout=3).content)})")
found_paths[url] = {"status_code": r.status_code, "content_len": len(r.content)}
except requests.RequestException as r:
print(r)
return found_paths or None
def scan(base_url, threads=20):
i = 0
wordlist = getwordlist()
found_paths = {}
with ThreadPoolExecutor(max_workers=threads) as executor:
results = executor.map(lambda w: check_path(base_url,i, w), wordlist)
for path in results:
if path:
found_paths.update(path)
print(f"SCAN FOR {base_url} ENDED--------------------------")
return found_paths if found_paths else None