Repository navigation
Expand file tree
/
Copy pathhttp_security.py
More file actions
180 lines (168 loc) · 7.11 KB
/
Copy pathhttp_security.py
File metadata and controls
180 lines (168 loc) · 7.11 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
import sys,os
import requests
from bs4 import BeautifulSoup
from rich.console import Console
from rich.table import Table
from colorama import Fore, init
import json
import re
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from utils.util import clean_domain_input, clean_url, ensure_url_format
init(autoreset=True)
console = Console()
def banner():
console.print(Fore.GREEN + """
=============================================
Argus - Advanced HTTP Security Headers Check
=============================================
""")
def get_headers(url):
try:
response = requests.get(url, timeout=10)
response.raise_for_status()
return response.headers, response.text
except requests.RequestException as e:
console.print(Fore.RED + f"[!] Error retrieving headers: {e}")
return None, None
def display_headers(headers):
table = Table(show_header=True, header_style="bold magenta")
table.add_column("Header", style="cyan", justify="left")
table.add_column("Value", style="green")
for header, value in headers.items():
table.add_row(header, value)
console.print(table)
def analyze_security_headers(headers):
security_headers = {
"Content-Security-Policy": "Not Set",
"Strict-Transport-Security": "Not Set",
"X-Content-Type-Options": "Not Set",
"X-Frame-Options": "Not Set",
"X-XSS-Protection": "Not Set",
"Referrer-Policy": "Not Set",
"Permissions-Policy": "Not Set"
}
for header in security_headers:
if header in headers:
security_headers[header] = "Configured"
table = Table(show_header=True, header_style="bold magenta")
table.add_column("Security Header", style="cyan", justify="left")
table.add_column("Status", style="green")
for header, status in security_headers.items():
table.add_row(header, status)
console.print(table)
missing = [header for header, status in security_headers.items() if status == "Not Set"]
if missing:
console.print(Fore.YELLOW + f"[!] Missing Security Headers: {', '.join(missing)}")
else:
console.print(Fore.GREEN + "[+] All critical security headers are properly configured.")
def identify_server_technology(headers):
server = headers.get("Server", "Unknown")
technology = "Unknown"
if "nginx" in server.lower():
technology = "Nginx Web Server"
elif "apache" in server.lower():
technology = "Apache Web Server"
elif "iis" in server.lower():
technology = "Microsoft IIS"
elif "cloudflare" in server.lower():
technology = "Cloudflare CDN"
console.print(Fore.YELLOW + "[*] Detecting server technology...")
table = Table(show_header=True, header_style="bold magenta")
table.add_column("Server", style="cyan", justify="left")
table.add_column("Detected Technology", style="green")
table.add_row(server, technology)
console.print(table)
def scan_vulnerabilities(headers):
vulnerabilities = []
if headers.get("X-Content-Type-Options", "").lower() != "nosniff":
vulnerabilities.append("X-Content-Type-Options is not set to 'nosniff'")
if "Strict-Transport-Security" in headers:
if "max-age=0" in headers["Strict-Transport-Security"]:
vulnerabilities.append("Strict-Transport-Security max-age is set to 0")
if "Content-Security-Policy" in headers:
if "default-src 'self'" not in headers["Content-Security-Policy"]:
vulnerabilities.append("Content-Security-Policy is not restrictive enough")
if headers.get("X-Frame-Options", "").upper() not in ["DENY", "SAMEORIGIN"]:
vulnerabilities.append("X-Frame-Options is not set to 'DENY' or 'SAMEORIGIN'")
table = Table(show_header=True, header_style="bold magenta")
table.add_column("Vulnerability", style="cyan", justify="left")
table.add_column("Issue", style="red")
for vuln in vulnerabilities:
table.add_row("Security Issue", vuln)
if vulnerabilities:
console.print(table)
else:
console.print(Fore.GREEN + "[+] No vulnerabilities detected based on HTTP headers.")
def analyze_cookies(headers):
cookies = headers.get("Set-Cookie")
if not cookies:
console.print(Fore.YELLOW + "[!] No cookies found.")
return
console.print(Fore.YELLOW + "[*] Analyzing cookies for security flags...")
table = Table(show_header=True, header_style="bold magenta")
table.add_column("Cookie", style="cyan", justify="left")
table.add_column("Attributes", style="green")
cookies = cookies.split(',')
for cookie in cookies:
cookie = cookie.strip()
parts = cookie.split(';')
name_value = parts[0]
attributes = [attr.strip() for attr in parts[1:]]
security_flags = []
for attr in attributes:
if attr.lower() == "secure":
security_flags.append("Secure")
if attr.lower() == "httponly":
security_flags.append("HttpOnly")
if attr.lower().startswith("samesite"):
security_flags.append(attr)
table.add_row(name_value, ", ".join(security_flags) if security_flags else "None")
console.print(table)
def detect_frameworks(response_text):
frameworks = {
"WordPress": "wp-content",
"Joomla": "Joomla!",
"Drupal": "Drupal.settings",
"Django": "csrftoken",
"Ruby on Rails": "Rails",
"Laravel": "laravel_session"
}
detected = []
for framework, signature in frameworks.items():
if signature in response_text:
detected.append(framework)
if detected:
console.print(Fore.GREEN + f"[+] Detected Frameworks: {', '.join(detected)}")
else:
console.print(Fore.YELLOW + "[!] No common frameworks detected.")
def main(target):
banner()
target = clean_url(clean_domain_input(target))
console.print(Fore.WHITE + f"[*] Fetching HTTP headers for: {target}")
headers, response_text = get_headers(target)
if headers:
console.print(Fore.YELLOW + "[*] Displaying HTTP headers...")
display_headers(headers)
console.print(Fore.YELLOW + "[*] Analyzing security headers...")
analyze_security_headers(headers)
identify_server_technology(headers)
console.print(Fore.YELLOW + "[*] Scanning for vulnerabilities based on headers...")
scan_vulnerabilities(headers)
console.print(Fore.YELLOW + "[*] Analyzing cookies for security flags...")
analyze_cookies(headers)
console.print(Fore.YELLOW + "[*] Detecting frameworks based on response content...")
detect_frameworks(response_text)
else:
console.print(Fore.RED + "[!] No headers found.")
console.print(Fore.WHITE + "[*] HTTP header analysis completed.")
if __name__ == "__main__":
if len(sys.argv) > 1:
try:
target = sys.argv[1]
main(target)
except KeyboardInterrupt:
console.print(Fore.RED + "\n[!] Process interrupted by user.")
sys.exit(1)
else:
console.print(Fore.RED + "[!] No target provided. Please pass a domain or URL.")
sys.exit(1)