-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclickjacking_checker.py
More file actions
52 lines (40 loc) · 1.68 KB
/
Copy pathclickjacking_checker.py
File metadata and controls
52 lines (40 loc) · 1.68 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
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()
def check_clickjacking(url):
"""
Checks for headers that prevent clickjacking attacks.
"""
print(f"[*] Checking for Clickjacking vulnerability on: {url}")
try:
response = requests.get(url, timeout=10, verify=False)
headers = response.headers
xfo = headers.get('X-Frame-Options', '').lower()
csp = headers.get('Content-Security-Policy', '')
if xfo in ['deny', 'sameorigin']:
print(f"[+] Site is protected with X-Frame-Options: {xfo}")
return
if 'frame-ancestors' in csp:
print(f"[+] Site is protected with Content-Security-Policy: frame-ancestors directive found.")
return
finding = "VULNERABILITY: Site may be vulnerable to Clickjacking"
print(f"[-] {finding}")
print(" Reason: Missing 'X-Frame-Options' or 'Content-Security-Policy' with 'frame-ancestors'.")
print_suggestions(finding)
except requests.RequestException as e:
print(f"Error: Could not connect to {url}. Details: {e}")
def main():
parser = argparse.ArgumentParser(description="Check for Clickjacking vulnerability.")
parser.add_argument("url", help="The target URL or domain to analyze (e.g., example.com).")
args = parser.parse_args()
target_url = args.url
if not urlparse(target_url).scheme:
target_url = "http://" + target_url
check_clickjacking(target_url)
if __name__ == "__main__":
main()