Files
XSStrike/core/dom.py

49 lines
2.2 KiB
Python
Raw Normal View History

2018-10-27 18:58:52 +05:30
import re
2018-10-27 18:58:52 +05:30
from core.colors import red, end, yellow
2018-11-16 21:13:45 +05:30
2018-11-12 12:59:31 +05:30
def dom(response):
2018-10-27 18:58:52 +05:30
highlighted = []
allControlledVariables = set()
2018-10-27 18:58:52 +05:30
response = response.split('\n')
2018-10-30 12:49:36 +05:30
sources = r"""location\.|\.([.\[]\s*["']?\s*arguments|dialogArguments|innerHTML|write|open|showModalDialog|cookie|URL|documentURI|baseURI|referrer|name|opener|parent|top|content|self|frames)[^\w\-]|(localStorage|sessionStorage|Database)[^\w\-]"""
sinks = r"""( (src|href|data|location|code|value|action)=)|(replace|assign|navigate|getResponseHeader|open|showModalDialog|eval|evaluate|execCommand|execScript|setTimeout|setInterval)\("""
2018-10-27 18:58:52 +05:30
num = 1
2018-11-12 23:31:57 +05:30
try:
for newLine in response:
line = newLine
parts = line.split('var ')
controlledVariables = set()
if len(parts) > 1:
for part in parts:
for controlledVariable in allControlledVariables:
if controlledVariable in part:
controlledVariables.add(part.split(' ')[0])
pattern = re.findall(sources, newLine)
2018-11-12 23:31:57 +05:30
for grp in pattern:
source = ''.join(grp)
if source:
parts = newLine.split('var ')
for part in parts:
if source in part:
controlledVariables.add(part.split(' ')[0])
line = line.replace(source, yellow + source + end)
for controlledVariable in controlledVariables:
allControlledVariables.add(controlledVariable)
for controlledVariable in allControlledVariables:
matches = list(filter(None, re.findall(r'\b%s\b' % controlledVariable, line)))
if matches:
line = re.sub(r'\b%s\b' % controlledVariable, yellow + controlledVariable + end, line)
pattern = re.findall(sinks, newLine)
2018-11-12 23:31:57 +05:30
for grp in pattern:
sink = ''.join(grp)
if sink:
line = line.replace(sink, red + sink + end)
2018-11-12 23:31:57 +05:30
if line != newLine:
highlighted.append('%-3s %s' % (str(num), line.lstrip(' ')))
num += 1
except MemoryError:
pass
2018-11-12 12:59:31 +05:30
return highlighted