-
Notifications
You must be signed in to change notification settings - Fork 0
/
sslyze.py
88 lines (73 loc) · 2.95 KB
/
sslyze.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
import csv
import subprocess
import requests
from urllib.parse import urlparse, urljoin
def check_ssl(domain):
result = subprocess.run(['sslyze', '--regular', domain], capture_output=True, text=True)
return result.stdout
def check_security_headers(url):
try:
response = requests.get(url, timeout=10)
headers = response.headers
security_headers = {
'Content-Security-Policy': headers.get('Content-Security-Policy', 'Missing'),
'Strict-Transport-Security': headers.get('Strict-Transport-Security', 'Missing'),
'X-Content-Type-Options': headers.get('X-Content-Type-Options', 'Missing'),
'X-Frame-Options': headers.get('X-Frame-Options', 'Missing'),
'X-XSS-Protection': headers.get('X-XSS-Protection', 'Missing'),
'Referrer-Policy': headers.get('Referrer-Policy', 'Missing'),
'Permissions-Policy': headers.get('Permissions-Policy', 'Missing'),
'Expect-CT': headers.get('Expect-CT', 'Missing')
}
return security_headers
except requests.RequestException as e:
print(f"Failed to fetch headers for {url}: {e}")
return {
'Content-Security-Policy': 'Error',
'Strict-Transport-Security': 'Error',
'X-Content-Type-Options': 'Error',
'X-Frame-Options': 'Error',
'X-XSS-Protection': 'Error',
'Referrer-Policy': 'Error',
'Permissions-Policy': 'Error',
'Expect-CT': 'Error'
}
def process_url(url):
parsed_url = urlparse(url)
if not parsed_url.scheme:
url = urljoin("https://", url)
parsed_url = urlparse(url)
domain = parsed_url.netloc
# Debugging information
print(f"Parsed URL: {parsed_url.geturl()}")
print(f"Domain: {domain}")
if not domain:
print(f"Invalid URL: {url}")
return
# Check SSL
try:
ssl_report = check_ssl(domain)
except subprocess.CalledProcessError as e:
ssl_report = f"Error running sslyze: {e}"
# Check Security Headers
security_headers = check_security_headers(url)
# Prepare report content
report_content = f"SSL Report for {domain}:\n{ssl_report}\n\n"
report_content += f"Security Headers for {url}:\n"
for header, value in security_headers.items():
report_content += f"{header}: {value}\n"
# Save report to file
report_filename = f"{domain}_report.txt"
with open(report_filename, 'w') as report_file:
report_file.write(report_content)
def main():
csv_filename = 'drive.csv'
with open(csv_filename, newline='') as csvfile:
csv_reader = csv.reader(csvfile)
for row in csv_reader:
url = row[0].strip()
if url and not url.startswith("#"):
print(f"Processing URL: {url}")
process_url(url)
if __name__ == "__main__":
main()