#!/usr/bin/python
"""HTML source analyzer
bl4de | bloorq@gmail.com | Twitter: @_bl4de | H1: bl4de
This tool goes through HTML document and shows all interesting places,
like inline JavaScript calls, commented paths, 'debug' and similar
words occurences, possible DOM Injection points, references to
resources like images or iframes
detection_engine.py contains all specific logic which detects interesting
parts of HTML
"""
import re
from console_output_beautifier import ConsoleOutputBeautifier
from utils import print_output_line
from vulners_rules import RULES
# @TODO: libraries/framework detection
# detects frontend framework used
line_cache = []
def get_line(_line, _line_number, _chars=80):
"""returns formatted line to print"""
return (_line_number, ConsoleOutputBeautifier.getColor("grey"), '\n\t\t'
+ _line.lstrip().rstrip()[0:_chars])
def detect_framework(_line):
"""frontend framework detection (simplified)
WARNING!!!
This detection is only some assumption based on some constant
elements but can not be treat as 100% sure.
"""
return detect_framework_vulners_db(_line)
def detect_framework_vulners_db(_line):
"""using Vulners API rules, detect software
used by analyzed HTML
"""
for rule in RULES:
if re.match(RULES[rule]["regex"], _line):
print RULES[rule]["alias"]
return '{1} ({2})'.format(RULES[rule]["alias"], rule)
def identify(_line):
"""backend detection (simplified)"""
_ident = "unknown"
if "Joomla" in _line:
_ident = "Joomla CMS"
if "wp-content" in _line:
_ident = "WordPress CMS"
if 'content="Drupal"' in _line:
_ident = "Drupal CMS"
return _ident
def detect_developer_comments(_line, i):
"""detection of comments left by developers"""
developer_comments = [
'bug',
'problem',
'issue',
'fix',
'ticket',
'bad',
'todo',
'inject',
'crash',
'trust',
'dev',
'temporary',
'remove'
]
for developer_comment in developer_comments:
if developer_comment in _line.lower():
print_output_line(i, ConsoleOutputBeautifier.getColor("yellow"),
"probably developer(s) related comment string found at line %d: %s %s",
get_line(_line, i, 120), "DOM BASED XSS")
def detect_dombased_xss(_line, i):
"""detection of DOM based XSS weaknesses"""
dombased_calls = [
'document.location',
'document.url',
'document.urlencoded',
'document.referrer',
'window.location',
'document.write(',
'document.writeln('
'.innerHTML',
'eval(',
'setInterval(',
'setTimeout(',
'Function('
]
for dombased_call in dombased_calls:
if dombased_call in _line:
print_output_line(i, ConsoleOutputBeautifier.getColor("red"),
"POSSIBLE DOM BASED INJECTION POINT found at line %d: %s %s",
get_line(_line, i, 120), "DOM BASED XSS")
def detect_ajax_calls(_line, i):
ajax_calls = [
'$.ajax',
'$.getJSON',
'$http.'
]
for call in ajax_calls:
if call in _line:
print_output_line(i, ConsoleOutputBeautifier.getColor("red"),
"AJAX CALL (possible REST endpoint revealed) at line %d: %s %s",
get_line(_line, i, 120), "AJAX/REST CALL")
def detect_comments(_line, i):
"""detects comments"""
if '