-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathsqlirunner.py
More file actions
66 lines (61 loc) · 1.93 KB
/
sqlirunner.py
File metadata and controls
66 lines (61 loc) · 1.93 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
# coding=utf-8
from config import SERVER
from AutoSqli import AutoSqli
from urlparse import urlparse
class SqliRunner(object):
"""
SqliRunner is used to detect a request from proxy is
injectable or not.
"""
def __init__(self, request):
self.request = request
self.url = request.url
self.data = request.body
self.cookie = self.get_from_headers('cookie')
self.referer = self.get_from_headers('referer')
self.req_text = self.get_raw_request(self.request)
def get_raw_request(self, request):
"""
Get raw http request body
"""
text = ""
method = request.method
url = request.url
urlp = urlparse(url)
body = request.body
headers = request.headers
protocol = 'HTTP/1.1'
if not urlp.fragment and not urlp.query:
link = "%s" % urlp.path
elif not urlp.fragment:
link = "%s?%s" % (urlp.path, urlp.query)
elif not urlp.query:
link = "%s#%s" % (urlp.path, urlp.fragment)
else:
link = "%s?%s#%s" % (urlp.path, urlp.query, urlp.fragment)
text += "%s %s %s\r\n" % (method, link, protocol)
for h in headers.get_all():
text += "%s: %s\r\n" % (h[0], h[1])
text += "\r\n"
if body: text += body
return text
def get_from_headers(self, key):
try:
item = self.request.headers.get_list(key)
if not item:
return ''
else:
return item[0]
except Exception, e:
return ''
def run(self):
"""
Run the sqli detection using HTTPRequest object.
"""
try:
detecter = AutoSqli(SERVER, self.url, self.data,
self.referer, self.cookie, self.req_text)
detecter.deamon = True
detecter.start()
except Exception, e:
print e