|
| 1 | +import requests, argparse |
| 2 | + |
| 3 | + |
| 4 | +# Function to check if a website is vulnerable to clickjacking. |
| 5 | +def check_clickjacking(url): |
| 6 | + try: |
| 7 | + # Add https:// schema if not present in the URL. |
| 8 | + if not url.startswith('http://') and not url.startswith('https://'): |
| 9 | + url = 'https://' + url |
| 10 | + |
| 11 | + # Send a GET request to the URL. |
| 12 | + response = requests.get(url) |
| 13 | + headers = response.headers |
| 14 | + |
| 15 | + # Check for X-Frame-Options header. |
| 16 | + if 'X-Frame-Options' not in headers: |
| 17 | + return True |
| 18 | + |
| 19 | + # Get the value of X-Frame-Options and check it.. |
| 20 | + x_frame_options = headers['X-Frame-Options'].lower() |
| 21 | + if x_frame_options != 'deny' and x_frame_options != 'sameorigin': |
| 22 | + return True |
| 23 | + |
| 24 | + return False |
| 25 | + except requests.exceptions.RequestException as e: |
| 26 | + print(f"An error occurred while checking {url} - {e}") |
| 27 | + return False |
| 28 | + |
| 29 | +# Main function to parse arguments and check the URL. |
| 30 | +def main(): |
| 31 | + parser = argparse.ArgumentParser(description='Clickjacking Vulnerability Scanner') |
| 32 | + parser.add_argument('url', type=str, help='The URL of the website to check') |
| 33 | + parser.add_argument('-l', '--log', action='store_true', help='Print out the response headers for analysis') |
| 34 | + args = parser.parse_args() |
| 35 | + |
| 36 | + url = args.url |
| 37 | + is_vulnerable = check_clickjacking(url) |
| 38 | + |
| 39 | + if is_vulnerable: |
| 40 | + print(f"[+] {url} may be vulnerable to clickjacking.") |
| 41 | + else: |
| 42 | + print(f"[-] {url} is not vulnerable to clickjacking.") |
| 43 | + |
| 44 | + if args.log: |
| 45 | + # Add https:// schema if not present in the URL for response printing. |
| 46 | + if not url.startswith('http://') and not url.startswith('https://'): |
| 47 | + url = 'https://' + url |
| 48 | + |
| 49 | + print("\nResponse Headers:") |
| 50 | + response = requests.get(url) |
| 51 | + for header, value in response.headers.items(): |
| 52 | + print(f"{header}: {value}") |
| 53 | + |
| 54 | +if __name__ == '__main__': |
| 55 | + main() |
0 commit comments