-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathheader-with-log-module.py
49 lines (39 loc) · 1.71 KB
/
header-with-log-module.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
import requests
HEADER_REFERENCES = {
'Content-Security-Policy': 'OWASP Content Security Policy',
'X-XSS-Protection': 'OWASP XSS (Cross Site Scripting) Prevention Cheat Sheet',
'X-Frame-Options': 'OWASP Clickjacking Defense Cheat Sheet',
'Strict-Transport-Security': 'OWASP Transport Layer Protection Cheat Sheet',
'Access-Control-Allow-Origin': 'OWASP Cross-Origin Resource Sharing (CORS) Cheat Sheet',
'Authorization': 'OWASP JSON Web Token Cheat Sheet',
}
def scan_header(url):
"""
Scans the security headers of a given URL and performs vulnerability checks.
Args:
url (str): The URL of the web application to scan.
Returns:
None
Raises:
ValueError: If the provided URL is invalid or inaccessible.
"""
try:
response = requests.head(url)
headers = response.headers
for header, reference in HEADER_REFERENCES.items():
if header in headers:
print(f"[+] {header} header found.")
# Perform further checks or actions related to the header
else:
print(f"[-] {header} header not found.")
print(f"Reference: [{reference}]")
# Access specific header values
content_type = headers.get('Content-Type')
server = headers.get('Server')
# ... Perform actions based on specific header values
# Perform additional tasks or analysis based on the headers
# Call the scan_csp function
scan_csp(url=url)
except requests.exceptions.RequestException as e:
print(f"[-] Error occurred while scanning URL: {url}")
print(f"Error details: {str(e)}")