Repository navigation
Expand file tree
/
Copy pathprint_utils.py
More file actions
67 lines (60 loc) · 2.19 KB
/
Copy pathprint_utils.py
File metadata and controls
67 lines (60 loc) · 2.19 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
65
66
67
#!/usr/bin/env python3
import requests
from utils.style import Colors, Identify
def cache_tag_verify(req: requests.Response) -> str:
cachetag = False
for rh in req.headers:
if "age" in rh.lower() or "hit" in rh.lower() or "cache" in rh.lower():
cachetag = True
else:
pass
colored_cachetag = (
f"{Colors.GREEN} " if cachetag else f"{Colors.RED}"
) + f"{str(cachetag)}{Colors.RESET}"
return colored_cachetag
def _escape_bytewise(s: str) -> str:
"""
- backslash -> \\
- \n -> \\n, \r -> \\r, \t -> \\t
- quote simple -> \'
- printable ASCII (0x20..0x7e)
- other octets -> \\xHH
"""
if s is None:
return ""
b = s.encode("utf-8", errors="surrogatepass")
out_parts = []
for byte in b:
ch = chr(byte)
if ch == "\\":
out_parts.append("\\\\")
elif ch == "\n":
out_parts.append("\\n")
elif ch == "\r":
out_parts.append("\\r")
elif ch == "\t":
out_parts.append("\\t")
elif ch == "'":
out_parts.append("\\'")
elif 32 <= byte <= 126:
out_parts.append(ch)
else:
out_parts.append(f"\\x{byte:02x}")
return "".join(out_parts)
def format_payload(payload: dict) -> str:
if not isinstance(payload, str):
parts = []
for k, v in payload.items():
ks_escaped = _escape_bytewise(str(k))
vs_escaped = _escape_bytewise(str(v))
if len(vs_escaped) > 60:
vs_escaped = f"{vs_escaped[:60]}...({len(vs_escaped)} total chars)"
parts.append(f"{ks_escaped}: {vs_escaped}")
return "" + ", ".join(parts) + ""
else:
return payload
def print_results(identify, vulnerability_type, reason, cachetag, url, payload):
print(f" {identify} | {vulnerability_type} | {reason} | CACHETAG: {cachetag} | {Colors.BLUE}{url}{Colors.RESET} | PAYLOAD: {Colors.THISTLE}{format_payload(payload)}{Colors.RESET}")
if identify == Identify.confirmed:
from utils.screenshot import take_screenshot
take_screenshot(url)