-
Notifications
You must be signed in to change notification settings - Fork 11
/
core.py
219 lines (176 loc) · 7.49 KB
/
core.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
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Import Modules
from random import randint
from Log import *
from bs4 import BeautifulSoup
from helper import *
from urllib.parse import urljoin, urlparse, parse_qs, urlencode
# Information About Project.
__Name__ = "scancss"
__description__ = "scancss is a xss vulnariblity scanner tool."
__author__ = "Md. Nur habib"
__copyright__ = "Copyright 2022."
__license__ = "GNU v.20"
__version__ = "v1.0.1"
__email__ = "thenurhabib@gmail.com"
# Style class
class Style:
reset = '\033[0m'
bold = '\033[01m'
underline = '\033[04m'
red = '\033[31m'
blue = '\033[34m'
cyan = '\033[36m'
lightgrey = '\033[37m'
darkgrey = '\033[90m'
yellow = '\033[93m'
class core:
@classmethod
def generate(self, eff):
FUNCTION = [
"prompt(5000/200)",
"alert(6000/3000)",
"alert(document.cookie)",
"prompt(document.cookie)",
"console.log(5000/3000)"
]
if eff == 1:
return "<script/>"+FUNCTION[randint(0, 4)]+"<\script\>"
elif eff == 2:
return "<\script/>"+FUNCTION[randint(0, 4)]+"<\\script>"
elif eff == 3:
return "<\script\> "+FUNCTION[randint(0, 4)]+"<//script>"
elif eff == 4:
return "<script>"+FUNCTION[randint(0, 4)]+"<\script/>"
elif eff == 5:
return "<script>"+FUNCTION[randint(0, 4)]+"<//script>"
elif eff == 6:
return "<script>"+FUNCTION[randint(0, 4)]+"</script>"
@classmethod
def post_method(self):
bsObj = BeautifulSoup(self.body, "html.parser")
forms = bsObj.find_all("form", method=True)
for form in forms:
try:
action = form["action"]
except KeyError:
action = self.url
if form["method"].lower().strip() == "post":
Log.warning("Target have form with POST method: " +
C+urljoin(self.url, action))
Log.info("Collecting form input key.....")
keys = {}
for key in form.find_all(["input", "textarea"]):
try:
if key["type"] == "submit":
Log.info(
"Form key name: "+G+key["name"]+N+" value: "+G+"<Submit Confirm>")
keys.update({key["name"]: key["name"]})
else:
Log.info("Form key name: "+G +
key["name"]+N+" value: "+G+self.payload)
keys.update({key["name"]: self.payload})
except Exception as e:
Log.info("Internal error: "+str(e))
Log.info("Sending payload (POST) method...")
req = self.session.post(urljoin(self.url, action), data=keys)
if self.payload in req.text:
Log.high("Detected XSS (POST) at " +
urljoin(self.url, req.url))
Log.high("Post data: "+str(keys))
else:
Log.info(
"This page is safe from XSS (POST) attack but not 100% yet...")
@classmethod
def get_method_form(self):
bsObj = BeautifulSoup(self.body, "html.parser")
forms = bsObj.find_all("form", method=True)
for form in forms:
try:
action = form["action"]
except KeyError:
action = self.url
if form["method"].lower().strip() == "get":
Log.warning("Target have form with GET method: " +
C+urljoin(self.url, action))
Log.info("Collecting form input key.....")
keys = {}
for key in form.find_all(["input", "textarea"]):
try:
if key["type"] == "submit":
Log.info(
"Form key name: "+G+key["name"]+N+" value: "+G+"<Submit Confirm>")
keys.update({key["name"]: key["name"]})
else:
Log.info("Form key name: "+G +
key["name"]+N+" value: "+G+self.payload)
keys.update({key["name"]: self.payload})
except Exception as e:
Log.info("Internal error: "+str(e))
try:
Log.info("Form key name: "+G +
key["name"]+N+" value: "+G+self.payload)
keys.update({key["name"]: self.payload})
except KeyError as e:
Log.info("Internal error: "+str(e))
Log.info("Sending payload (GET) method...")
req = self.session.get(urljoin(self.url, action), params=keys)
if self.payload in req.text:
Log.high("Detected XSS (GET) at " +
urljoin(self.url, req.url))
Log.high("GET data: "+str(keys))
else:
Log.info("Not vulnerable.")
@classmethod
def get_method(self):
bsObj = BeautifulSoup(self.body, "html.parser")
links = bsObj.find_all("a", href=True)
for a in links:
url = a["href"]
if url.startswith("http://") is False or url.startswith("https://") is False or url.startswith("mailto:") is False:
base = urljoin(self.url, a["href"])
query = urlparse(base).query
if query != "":
Log.warning("Found link with query: "+G +
query+N+" Maybe a vulnerable XSS point.")
query_payload = query.replace(
query[query.find("=")+1:len(query)], self.payload, 1)
test = base.replace(query, query_payload, 1)
query_all = base.replace(query, urlencode(
{x: self.payload for x in parse_qs(query)}))
Log.info("Query (GET) : "+test)
Log.info("Query (GET) : "+query_all)
_respon = self.session.get(test)
if self.payload in _respon.text or self.payload in self.session.get(query_all).text:
Log.high("Detected XSS (GET) at "+_respon.url)
else:
Log.info(
"This page is safe from XSS (GET) attack but not 100% yet...")
@classmethod
def main(self, url, proxy, headers, payload, cookie, method=2):
print(W+"*"*15)
self.payload = payload
self.url = url
self.session = session(proxy, headers, cookie)
Log.info("Checking connection to: "+Y+url)
try:
ctr = self.session.get(url)
self.body = ctr.text
except Exception as e:
Log.high("Internal error: "+str(e))
return
if ctr.status_code > 400:
Log.info("Connection failed "+G+str(ctr.status_code))
return
else:
Log.info("Connection estabilished "+G+str(ctr.status_code))
if method >= 2:
self.post_method()
self.get_method()
self.get_method_form()
elif method == 1:
self.post_method()
elif method == 0:
self.get_method()
self.get_method_form()