2121with sqlmap; if not, write to the Free Software Foundation, Inc., 51
2222Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2323"""
24- import re , sre_constants
24+
25+ import codecs
26+ import re
27+ import sre_constants
28+
2529from xml .dom import minidom
2630
2731from lib .core .common import getCompiledRegex
32+ from lib .core .data import conf
2833from lib .core .data import paths
2934from lib .core .data import logger
3035
@@ -36,28 +41,33 @@ def __adjustGrammar(string):
3641 string = re .sub ('attempts\Z' , 'attempt' , string )
3742 string = re .sub ('injections\Z' , 'injection' , string )
3843 string = re .sub ('attacks\Z' , 'attack' , string )
44+
3945 return string
4046
4147def checkPayload (string ):
4248 """
43- This method checks if the generated payload is detectable by the PHPIDS filter rules
49+ This method checks if the generated payload is detectable by the
50+ PHPIDS filter rules
4451 """
52+
4553 global rules
4654
4755 if not rules :
48- file = open (paths .DETECTION_RULES_XML , 'r' )
49- xmlrules = minidom .parse (file ).documentElement
50- file .close ()
56+ xfile = codecs . open (paths .DETECTION_RULES_XML , 'r' , conf . dataEncoding )
57+ xmlrules = minidom .parse (xfile ).documentElement
58+ xfile .close ()
5159 rules = []
60+
5261 for xmlrule in xmlrules .getElementsByTagName ("filter" ):
5362 try :
5463 rule = "(?i)%s" % xmlrule .getElementsByTagName ('rule' )[0 ].childNodes [0 ].nodeValue
5564 desc = __adjustGrammar (xmlrule .getElementsByTagName ('description' )[0 ].childNodes [0 ].nodeValue )
5665 rules .append ((rule , desc ))
57- except sre_constants .error : #some issues with some regex expressions in Python 2.5
66+ except sre_constants .error : # Some issues with some regex expressions in Python 2.5
5867 pass
5968
6069 for rule , desc in rules :
6170 regObj = getCompiledRegex (rule )
71+
6272 if regObj .search (string ):
6373 logger .warn ("highly probable IDS/IPS detection: '%s'" % desc )
0 commit comments