2010-01-25 03:25:58 +03:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
"""
|
2012-07-12 21:38:03 +04:00
|
|
|
Copyright (c) 2006-2012 sqlmap developers (http://sqlmap.org/)
|
2010-10-15 03:18:29 +04:00
|
|
|
See the file 'doc/COPYING' for copying permission
|
2010-01-25 03:25:58 +03:00
|
|
|
"""
|
2010-05-29 14:10:28 +04:00
|
|
|
|
|
|
|
import re
|
|
|
|
|
2010-10-07 02:43:04 +04:00
|
|
|
from lib.core.common import readXmlFile
|
2012-07-31 13:03:44 +04:00
|
|
|
from lib.core.common import urldecode
|
2010-01-25 13:06:52 +03:00
|
|
|
from lib.core.data import paths
|
2010-01-25 03:25:58 +03:00
|
|
|
from lib.core.data import logger
|
|
|
|
|
|
|
|
rules = None
|
|
|
|
|
2012-12-06 17:14:19 +04:00
|
|
|
def _adjustGrammar(string):
|
2010-01-25 13:06:52 +03:00
|
|
|
string = re.sub('\ADetects', 'Detected', string)
|
|
|
|
string = re.sub('\Afinds', 'Found', string)
|
|
|
|
string = re.sub('attempts\Z', 'attempt', string)
|
|
|
|
string = re.sub('injections\Z', 'injection', string)
|
|
|
|
string = re.sub('attacks\Z', 'attack', string)
|
2010-05-29 14:10:28 +04:00
|
|
|
|
2010-01-25 13:06:52 +03:00
|
|
|
return string
|
|
|
|
|
2010-10-25 19:37:43 +04:00
|
|
|
def checkPayload(payload):
|
2010-01-25 03:25:58 +03:00
|
|
|
"""
|
2010-05-29 14:10:28 +04:00
|
|
|
This method checks if the generated payload is detectable by the
|
|
|
|
PHPIDS filter rules
|
2010-01-25 03:25:58 +03:00
|
|
|
"""
|
2010-05-29 14:10:28 +04:00
|
|
|
|
2011-04-11 19:24:52 +04:00
|
|
|
if not payload:
|
|
|
|
return
|
|
|
|
|
2010-01-25 03:25:58 +03:00
|
|
|
global rules
|
|
|
|
|
2011-04-08 18:34:00 +04:00
|
|
|
detected = False
|
2012-10-26 13:05:44 +04:00
|
|
|
payload = urldecode(payload, convall=True)
|
2010-10-25 19:37:43 +04:00
|
|
|
|
2010-01-25 03:25:58 +03:00
|
|
|
if not rules:
|
2010-10-25 22:38:54 +04:00
|
|
|
xmlrules = readXmlFile(paths.PHPIDS_RULES_XML)
|
2010-01-25 03:25:58 +03:00
|
|
|
rules = []
|
2010-05-29 14:10:28 +04:00
|
|
|
|
2010-01-25 03:25:58 +03:00
|
|
|
for xmlrule in xmlrules.getElementsByTagName("filter"):
|
2010-10-25 19:37:43 +04:00
|
|
|
rule = "(?i)%s" % xmlrule.getElementsByTagName('rule')[0].childNodes[0].nodeValue
|
2012-12-06 17:14:19 +04:00
|
|
|
desc = _adjustGrammar(xmlrule.getElementsByTagName('description')[0].childNodes[0].nodeValue)
|
2010-10-25 19:37:43 +04:00
|
|
|
rules.append((rule, desc))
|
|
|
|
|
|
|
|
if payload:
|
|
|
|
for rule, desc in rules:
|
2012-04-03 18:34:15 +04:00
|
|
|
if re.search(rule, payload):
|
2011-04-08 18:34:00 +04:00
|
|
|
detected = True
|
2010-10-29 15:00:23 +04:00
|
|
|
logger.warn("highly probable IDS/IPS detection: '%s: %s'" % (desc, payload))
|
2011-04-08 18:34:00 +04:00
|
|
|
|
|
|
|
if not detected:
|
|
|
|
logger.warn("payload '%s' possibly gone undetected" % payload)
|