-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathheader_checker.py
More file actions
62 lines (50 loc) · 1.73 KB
/
Copy pathheader_checker.py
File metadata and controls
62 lines (50 loc) · 1.73 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
import warnings
warnings.filterwarnings('ignore')
warnings.simplefilter('ignore')
import requests
import argparse
from urllib.parse import urlparse
from suggestions import print_suggestions
requests.packages.urllib3.disable_warnings()
SECURITY_HEADERS = [
"Strict-Transport-Security",
"Content-Security-Policy",
"X-Content-Type-Options",
"X-Frame-Options",
"Referrer-Policy",
"Permissions-Policy"
]
def check_headers(url):
"""
Checks for the presence of recommended security headers.
"""
print(f"[*] Checking security headers for: {url}")
try:
response = requests.get(url, timeout=10, verify=False)
headers = response.headers
missing_headers = []
print("\n[+] Found Headers:")
for header in SECURITY_HEADERS:
if header in headers:
print(f" - {header}: {headers[header]}")
else:
missing_headers.append(header)
except requests.RequestException as e:
print(f"Error: Could not connect to {url}. Details: {e}")
return
if missing_headers:
print("\n[-] Missing Recommended Security Headers:")
for header in missing_headers:
finding = f"Missing Header: {header}"
print(f" - {finding}")
print_suggestions(finding)
def main():
parser = argparse.ArgumentParser(description="Check for recommended security headers.")
parser.add_argument("url", help="The target URL to analyze (e.g., https://example.com or example.com)")
args = parser.parse_args()
target_url = args.url
if not urlparse(target_url).scheme:
target_url = "http://" + target_url
check_headers(target_url)
if __name__ == "__main__":
main()