2010-01-25 03:25:58 +03:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
"""
|
2010-01-25 12:21:39 +03:00
|
|
|
$Id$
|
2010-01-25 03:25:58 +03:00
|
|
|
|
|
|
|
This file is part of the sqlmap project, http://sqlmap.sourceforge.net.
|
|
|
|
|
2010-03-03 18:26:27 +03:00
|
|
|
Copyright (c) 2007-2010 Bernardo Damele A. G. <bernardo.damele@gmail.com>
|
2010-01-25 03:25:58 +03:00
|
|
|
Copyright (c) 2006 Daniele Bellucci <daniele.bellucci@gmail.com>
|
|
|
|
|
|
|
|
sqlmap is free software; you can redistribute it and/or modify it under
|
|
|
|
the terms of the GNU General Public License as published by the Free
|
|
|
|
Software Foundation version 2 of the License.
|
|
|
|
|
|
|
|
sqlmap is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
|
|
details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License along
|
|
|
|
with sqlmap; if not, write to the Free Software Foundation, Inc., 51
|
|
|
|
Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
"""
|
2010-05-29 14:10:28 +04:00
|
|
|
|
|
|
|
import codecs
|
|
|
|
import re
|
|
|
|
import sre_constants
|
|
|
|
|
2010-01-25 03:25:58 +03:00
|
|
|
from xml.dom import minidom
|
|
|
|
|
2010-05-21 18:42:59 +04:00
|
|
|
from lib.core.common import getCompiledRegex
|
2010-05-29 14:10:28 +04:00
|
|
|
from lib.core.data import conf
|
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
|
|
|
|
|
2010-01-25 13:06:52 +03:00
|
|
|
def __adjustGrammar(string):
|
|
|
|
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-01-25 03:25:58 +03:00
|
|
|
def checkPayload(string):
|
|
|
|
"""
|
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
|
|
|
|
2010-01-25 03:25:58 +03:00
|
|
|
global rules
|
|
|
|
|
|
|
|
if not rules:
|
2010-05-29 14:10:28 +04:00
|
|
|
xfile = codecs.open(paths.DETECTION_RULES_XML, 'r', conf.dataEncoding)
|
|
|
|
xmlrules = minidom.parse(xfile).documentElement
|
|
|
|
xfile.close()
|
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"):
|
|
|
|
try:
|
2010-05-21 19:03:40 +04:00
|
|
|
rule = "(?i)%s" % xmlrule.getElementsByTagName('rule')[0].childNodes[0].nodeValue
|
2010-01-25 13:06:52 +03:00
|
|
|
desc = __adjustGrammar(xmlrule.getElementsByTagName('description')[0].childNodes[0].nodeValue)
|
2010-01-25 03:25:58 +03:00
|
|
|
rules.append((rule, desc))
|
2010-05-29 14:10:28 +04:00
|
|
|
except sre_constants.error: # Some issues with some regex expressions in Python 2.5
|
2010-01-25 03:25:58 +03:00
|
|
|
pass
|
|
|
|
|
|
|
|
for rule, desc in rules:
|
2010-05-21 18:42:59 +04:00
|
|
|
regObj = getCompiledRegex(rule)
|
2010-05-29 14:10:28 +04:00
|
|
|
|
2010-05-21 19:03:40 +04:00
|
|
|
if regObj.search(string):
|
2010-01-25 03:25:58 +03:00
|
|
|
logger.warn("highly probable IDS/IPS detection: '%s'" % desc)
|