Skip to content

Commit 0d014e4

Browse files
committed
add clickjacking scanner tutorial
1 parent 14ce0f7 commit 0d014e4

File tree

4 files changed

+58
-0
lines changed

4 files changed

+58
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ This is a repository of all the tutorials of [The Python Code](https://www.thepy
7070
- [How to Remove Persistent Malware in Python](https://thepythoncode.com/article/removingg-persistent-malware-in-python). ([code](ethical-hacking/remove-persistent-malware))
7171
- [How to Check Password Strength with Python](https://thepythoncode.com/article/test-password-strength-with-python). ([code](ethical-hacking/checking-password-strength))
7272
- [How to Perform Reverse DNS Lookups Using Python](https://thepythoncode.com/article/reverse-dns-lookup-with-python). ([code](ethical-hacking/reverse-dns-lookup))
73+
- [How to Make a Clickjacking Vulnerability Scanner in Python](https://thepythoncode.com/article/make-a-clickjacking-vulnerability-scanner-with-python). ([code](ethical-hacking/clickjacking-scanner))
7374

7475
- ### [Machine Learning](https://www.thepythoncode.com/topic/machine-learning)
7576
- ### [Natural Language Processing](https://www.thepythoncode.com/topic/nlp)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# [How to Make a Clickjacking Vulnerability Scanner in Python](https://thepythoncode.com/article/make-a-clickjacking-vulnerability-scanner-with-python)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
requests

0 commit comments

Comments
 (0)