-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathT-XSS.py
61 lines (61 loc) · 2.21 KB
/
T-XSS.py
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
import os
from email import contentmanager
import requests
from pprint import pprint
from bs4 import BeautifulSoup as bs
from urllib.parse import urljoin
import colorama
os.system("clear")
os.system("toilet T-XSS")
print("Coded By: ParzivalHack")
print("Github: github.com/ParzivalHack")
print("License: The source code of this tool is under the GPL v.3 License.")
print("© 2022 Tommaso Bona")
def get_all_forms(url):
soup = bs(requests.get(url).content, "html.parser")
return soup.find_all("form")
def get_form_details(form):
details = {}
action = form.attrs.get("action").lower()
method = form.attrs.get("method", "get").lower()
inputs = []
for input_tag in form.find_all("input"):
input_type = input_tag.attrs.get("type", "text")
input_name = input_tag.attrs.get("name")
inputs.append({"type": input_type, "name": input_name})
details["action"] = action
details["method"] = method
details["inputs"] = inputs
return details
def submit_form(form_details, url, value):
target_url = urljoin(url, form_details["action"])
inputs =form_details["inputs"]
data = {}
for input in inputs:
if input["type"] == "text" or input["type"] == "search":
input["value"] = value
input_name = input.get("name")
input_value = input.get("value")
if input_name and input_value:
data[input_name] = input_value
if form_details["method"] == "post":
return requests.post(target_url, data = data)
else:
return requests.get(target_url, params = data)
def scan_xss(url):
forms = get_all_forms(url)
print(f"[+] Detected {len(forms)} forms on {url}.")
js_script = "<Script>alert('XSS vulnerable')</scripT>"
is_vulnerable = False
for form in forms:
form_details = get_form_details(form)
content = submit_form(form_details, url, js_script).content.decode()
if js_script in content:
print(f"[+] XSS Detected on {url}")
print("[*] Form details: ")
pprint(form_details)
is_vulnerable = True
return is_vulnerable
if __name__ == "__main__":
url = str(input("Target URL: "))
print(scan_xss(url))