Repository navigation
Expand file tree
/
Copy pathvulnerability_scanner.py
More file actions
62 lines (53 loc) · 2.57 KB
/
Copy pathvulnerability_scanner.py
File metadata and controls
62 lines (53 loc) · 2.57 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
import requests
from bs4 import BeautifulSoup
# Test for SQL Injection vulnerability
def test_sql_injection(url):
sql_payloads = ["' OR '1'='1", "'; DROP TABLE users; --", "admin' --", "' OR 'a'='a", "' OR 1=1--", "1' OR '1'='1' --"]
for payload in sql_payloads:
test_url = f"{url}?id={payload}"
try:
response = requests.get(test_url, timeout=10, verify=False)
# Check for SQL errors or HTTP status codes that may suggest vulnerability
if response.status_code == 500 or "mysql" in response.text.lower() or "sql syntax" in response.text.lower():
print(f"[!] SQL Injection vulnerability detected with payload: {payload}")
else:
print(f"[+] No SQL Injection vulnerability found with payload: {payload}")
except Exception as e:
print(f"[Error] Could not test for SQL Injection: {e}")
# Test for XSS vulnerability
def test_xss(url):
xss_payloads = ["<script>alert('XSS')</script>", "<img src=x onerror=alert(1)>", "<svg/onload=alert(1)>"]
input_fields = ["input", "search", "comment", "q"] # Common form input fields
for payload in xss_payloads:
for field in input_fields:
data = {field: payload}
try:
response = requests.post(url, data=data, timeout=10, verify=False)
if payload in response.text:
print(f"[!] XSS vulnerability detected with payload: {payload} in field: {field}")
else:
print(f"[+] No XSS vulnerability found with payload: {payload} in field: {field}")
except Exception as e:
print(f"[Error] Could not test for XSS: {e}")
# Test for outdated software
def test_outdated_software(url):
outdated_software = ["Apache", "nginx", "PHP", "OpenSSL", "MySQL"]
try:
response = requests.get(url, timeout=10, verify=False)
headers = response.headers
for software in outdated_software:
if software.lower() in str(headers).lower():
print(f"[!] Outdated software detected: {software}")
else:
print(f"[+] No outdated software detected.")
except Exception as e:
print(f"[Error] Could not test for outdated software: {e}")
# Main scanner function
def scan_website(url):
print(f"Scanning {url} for vulnerabilities...\n")
test_sql_injection(url)
test_xss(url)
test_outdated_software(url)
if __name__ == "__main__":
url = input("Enter the URL of the website to scan (e.g., https://example.com): ")
scan_website(url)