-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweb application vulnerability scanner
More file actions
134 lines (102 loc) · 4.19 KB
/
Copy pathweb application vulnerability scanner
File metadata and controls
134 lines (102 loc) · 4.19 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
import requests
from bs4 import BeautifulSoup
# List of payloads to test for vulnerabilities
xss_payloads = ["<script>alert(1)</script>", "<img src=x onerror=alert(1)>"]
sql_payloads = ["' OR '1'='1", "'; DROP TABLE users; --"]
# Function to test XSS vulnerability
def test_xss(url, forms):
print("[*] Testing for XSS Vulnerabilities...")
for form in forms:
action = form.get("action")
method = form.get("method", "get").lower()
inputs = form.find_all("input")
form_data = {}
for input_field in inputs:
name = input_field.get("name")
form_data[name] = xss_payloads[0] # Inject XSS payload
form_url = url + action if action else url
if method == "post":
response = requests.post(form_url, data=form_data)
else:
response = requests.get(form_url, params=form_data)
if xss_payloads[0] in response.text:
print(f"[+] XSS Vulnerability Found at {form_url}")
else:
print(f"[-] No XSS Vulnerability Found at {form_url}")
# Function to test SQL Injection vulnerability
def test_sql_injection(url, forms):
print("[*] Testing for SQL Injection Vulnerabilities...")
for form in forms:
action = form.get("action")
method = form.get("method", "get").lower()
inputs = form.find_all("input")
form_data = {}
for input_field in inputs:
name = input_field.get("name")
form_data[name] = sql_payloads[0] # Inject SQL payload
form_url = url + action if action else url
if method == "post":
response = requests.post(form_url, data=form_data)
else:
response = requests.get(form_url, params=form_data)
if "error" in response.text.lower():
print(f"[+] SQL Injection Vulnerability Found at {form_url}")
else:
print(f"[-] No SQL Injection Vulnerability Found at {form_url}")
# Function to fetch forms from a web page
def get_forms(url):
print(f"[*] Fetching forms from {url}...")
response = requests.get(url)
soup = BeautifulSoup(response.text, "html.parser")
forms = soup.find_all("form")
print(f"[*] Found {len(forms)} form(s).")
return forms
# Main function
def main():
target_url = input("Enter the target URL: ").strip()
forms = get_forms(target_url)
test_xss(target_url, forms)
test_sql_injection(target_url, forms)
if __name__ == "__main__":
main()
Explanation:
Payloads:
The code uses two sets of payloads:
XSS payloads: <script>alert(1)</script> and <img src=x onerror=alert(1)>
SQL Injection payloads: ' OR '1'='1 and '; DROP TABLE users; --
Functions:
test_xss(): Tests for Cross-Site Scripting (XSS) vulnerabilities by injecting the XSS payload into each form input.
test_sql_injection(): Tests for SQL Injection vulnerabilities by injecting SQL payloads into each form input.
get_forms(): Extracts all forms from the provided URL using BeautifulSoup and returns them.
Main Function:
Asks the user for a target URL.
Calls get_forms() to extract forms from the given URL.
Tests for XSS and SQL Injection vulnerabilities using the respective functions.
How to Use:
Install the required libraries:
You'll need to install the required Python libraries (if you haven't already):
bash
Copy code
pip install requests beautifulsoup4
Run the script:
Save the script as a .py file (e.g., vuln_scanner.py).
Run the script from the command line:
bash
Copy code
python vuln_scanner.py
Input the target URL:
The script will ask you to enter the target URL.
The script will then fetch the forms on the page and attempt to detect XSS and SQL Injection vulnerabilities.
Output Example:
bash
Copy code
Enter the target URL: http://example.com
[*] Fetching forms from http://example.com...
[*] Found 3 form(s).
[*] Testing for XSS Vulnerabilities...
[+] XSS Vulnerability Found at http://example.com/login
[-] No XSS Vulnerability Found at http://example.com/contact
[*] Testing for SQL Injection Vulnerabilities...
[+] SQL Injection Vulnerability Found at http://example.com/login
[-] No SQL Injection Vulnerability Found at http://example.com/contact
You can replace the URL in the input prompt with the website you want to scan.