More replacements from open() to codecs.open(). conf.dataEncoding has to be used only for non-binary files.

This commit is contained in:
Bernardo Damele
2010-05-29 10:10:28 +00:00
parent 84778f0e6c
commit 89c721a451
7 changed files with 35 additions and 19 deletions

View File

@@ -21,10 +21,15 @@ 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
"""
import re, sre_constants
import codecs
import re
import sre_constants
from xml.dom import minidom
from lib.core.common import getCompiledRegex
from lib.core.data import conf
from lib.core.data import paths
from lib.core.data import logger
@@ -36,28 +41,33 @@ def __adjustGrammar(string):
string = re.sub('attempts\Z', 'attempt', string)
string = re.sub('injections\Z', 'injection', string)
string = re.sub('attacks\Z', 'attack', string)
return string
def checkPayload(string):
"""
This method checks if the generated payload is detectable by the PHPIDS filter rules
This method checks if the generated payload is detectable by the
PHPIDS filter rules
"""
global rules
if not rules:
file = open(paths.DETECTION_RULES_XML, 'r')
xmlrules = minidom.parse(file).documentElement
file.close()
xfile = codecs.open(paths.DETECTION_RULES_XML, 'r', conf.dataEncoding)
xmlrules = minidom.parse(xfile).documentElement
xfile.close()
rules = []
for xmlrule in xmlrules.getElementsByTagName("filter"):
try:
rule = "(?i)%s" % xmlrule.getElementsByTagName('rule')[0].childNodes[0].nodeValue
desc = __adjustGrammar(xmlrule.getElementsByTagName('description')[0].childNodes[0].nodeValue)
rules.append((rule, desc))
except sre_constants.error: #some issues with some regex expressions in Python 2.5
except sre_constants.error: # Some issues with some regex expressions in Python 2.5
pass
for rule, desc in rules:
regObj = getCompiledRegex(rule)
if regObj.search(string):
logger.warn("highly probable IDS/IPS detection: '%s'" % desc)