mirror of
https://github.com/sqlmapproject/sqlmap.git
synced 2025-12-06 12:41:30 +00:00
More replacements from open() to codecs.open(). conf.dataEncoding has to be used only for non-binary files.
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user