-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathxsscheckmate-gruyere-demo.py
67 lines (58 loc) · 2.25 KB
/
xsscheckmate-gruyere-demo.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
#
# Copyrights licensed under the New BSD License.
# See the accompanying LICENSE.txt file for terms.
#
# Dependency:
# 1. chromedriver
# https://sites.google.com/a/chromium.org/chromedriver/downloads
# Default path is './', but may change it using CHROMEDRIVER var below
# 2. Gruyere XSS codelab.
# To access Gruyere, go to http://google-gruyere.appspot.com/start. AppEngine
# will start a new instance of Gruyere for you, assign it a unique id and
# redirect you to http://google-gruyere.appspot.com/123/ (where 123 is your
# unique id). Replace the GRUYERE_ID below (eg. 123) to make this program
# work with your instance
#
# To run the selenium test:
# % python ./xsscheckmate-gruyere-demo.py
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from string import Template
import unittest, json
CHROMEDRIVER = './chromedriver'
GRUYERE_ID = '932695469192'
TESTID_PREFIX = '444' # int
urls = [ """http://google-gruyere.appspot.com/${GID}/${INPUT}""" ]
payloads = [ """<script>console.error(${TID})</script>""",
"""console.error(${TID})//<svg/onload=console.error(${TID})>'-console.error(${TID})-'""" ]
class XSSTest(unittest.TestCase):
def setUp(self):
d = DesiredCapabilities.CHROME
d['loggingPrefs'] = { 'browser':'ALL' }
chrome_options = Options()
chrome_options.add_argument("--disable-web-security")
chrome_options.add_argument("--disable-xss-auditor")
self.driver = webdriver.Chrome(CHROMEDRIVER, chrome_options=chrome_options)
def tearDown(self):
self.driver.quit()
def test_run(self):
id = int(TESTID_PREFIX)*10;
for url in urls:
for xss in payloads:
xss1 = Template(xss).substitute(TID=str(id))
url1 = Template(url).substitute(GID=GRUYERE_ID, INPUT=xss1)
print url1
id = id + 1
self.driver.get(url1)
self.result()
def result(self):
n = 0
for cmsg in self.driver.get_log('browser'):
if -1 != str(cmsg).find(" " + TESTID_PREFIX):
print(json.dumps(cmsg))
n += 1
self.assertEqual(0, n)
# entry point
if __name__ == "__main__":
unittest.main()