This repository has been archived by the owner on Apr 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 53
/
main.py
77 lines (58 loc) · 2.54 KB
/
main.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
# -*- coding: utf-8 -*-
import webapp2
import json
from gae_utils import BaseHandler, HTTP
from domxss import DOMXSS
class MainHandler(BaseHandler):
def get(self):
self.generate('text/html', 'index.html')
class ScanHandler(BaseHandler):
def error(self, message):
self.set_template_value('error', message)
self.set_template_value('title', message)
if self.is_ajax():
self.generate('text/html', 'error.html')
else:
self.generate('text/html', '404.html')
def get(self):
self.jinja_env.cache = None
url = self.get_param('url', '', 'url')
if url:
self.set_template_value('url', url)
self.set_template_value('title', 'DOM XSS Scanner - Scan %s' % url)
response = HTTP().request(url)
if response:
content = response.content
encoding = False
dxs = DOMXSS()
# try to determine charset from request headers
ctype = response.headers['content-type'].strip()
pos = ctype.find('charset=')
if pos > 0:
encoding = ctype[pos+8:len(ctype)].lower()
if ctype.startswith('text/html') or ctype.startswith('text/xml'):
# try to determine charset from html if not set before
if not encoding:
encoding = dxs.get_charset_from_html(content)
script_urls = dxs.get_script_urls(url, content)
self.set_template_value('script_urls', json.dumps(script_urls))
if not encoding:
encoding = 'utf-8'
response_text = content.decode(encoding, 'ignore')
self.set_template_value('response_text', response_text)
if self.is_ajax():
self.generate('text/javascript', 'response.html')
else:
self.generate('text/html', 'scan.html')
else:
self.error('Error: Supplied URL could not be fetched.')
else:
self.error('Error: Supplied URL is not valid.')
class PageHandler(BaseHandler):
def get(self, name):
self.set_template_value('title', '%s DOM XSS Scanner' % name)
self.generate('text/html', '%s.html' % name)
app = webapp2.WSGIApplication([('/', MainHandler),
('/scan.*', ScanHandler),
('/info/([\w-]*)', PageHandler),
], debug=True)