2019-05-08 13:47:52 +03:00
|
|
|
#!/usr/bin/env python
|
2010-11-28 21:10:54 +03:00
|
|
|
|
|
|
|
"""
|
2022-01-03 13:30:34 +03:00
|
|
|
Copyright (c) 2006-2022 sqlmap developers (https://sqlmap.org/)
|
2017-10-11 15:50:46 +03:00
|
|
|
See the file 'LICENSE' for copying permission
|
2010-11-28 21:10:54 +03:00
|
|
|
"""
|
|
|
|
|
2015-02-15 19:31:35 +03:00
|
|
|
import os
|
2018-09-14 11:30:58 +03:00
|
|
|
import re
|
2015-02-15 19:31:35 +03:00
|
|
|
|
2010-11-28 21:10:54 +03:00
|
|
|
from xml.etree import ElementTree as et
|
|
|
|
|
2015-10-23 15:29:48 +03:00
|
|
|
from lib.core.common import getSafeExString
|
2019-03-28 18:04:38 +03:00
|
|
|
from lib.core.compat import xrange
|
2010-11-28 21:10:54 +03:00
|
|
|
from lib.core.data import conf
|
|
|
|
from lib.core.data import paths
|
2011-07-08 10:02:31 +04:00
|
|
|
from lib.core.datatype import AttribDict
|
2014-11-10 15:41:53 +03:00
|
|
|
from lib.core.exception import SqlmapInstallationException
|
2016-07-17 01:21:16 +03:00
|
|
|
from lib.core.settings import PAYLOAD_XML_FILES
|
2010-11-28 21:10:54 +03:00
|
|
|
|
2010-12-03 13:51:27 +03:00
|
|
|
def cleanupVals(text, tag):
|
2018-09-14 11:30:58 +03:00
|
|
|
if tag == "clause" and '-' in text:
|
|
|
|
text = re.sub(r"(\d+)-(\d+)", lambda match: ','.join(str(_) for _ in xrange(int(match.group(1)), int(match.group(2)) + 1)), text)
|
|
|
|
|
2010-12-03 13:51:27 +03:00
|
|
|
if tag in ("clause", "where"):
|
|
|
|
text = text.split(',')
|
2010-12-01 20:09:52 +03:00
|
|
|
|
2019-03-28 15:53:54 +03:00
|
|
|
if hasattr(text, "isdigit") and text.isdigit():
|
|
|
|
text = int(text)
|
2010-12-03 13:51:27 +03:00
|
|
|
|
|
|
|
elif isinstance(text, list):
|
|
|
|
count = 0
|
|
|
|
|
2012-12-10 20:20:04 +04:00
|
|
|
for _ in text:
|
2015-12-23 10:55:45 +03:00
|
|
|
text[count] = int(_) if _.isdigit() else _
|
2010-12-03 13:51:27 +03:00
|
|
|
count += 1
|
2010-11-28 21:10:54 +03:00
|
|
|
|
2010-12-03 13:51:27 +03:00
|
|
|
if len(text) == 1 and tag not in ("clause", "where"):
|
|
|
|
text = text[0]
|
2010-11-28 21:10:54 +03:00
|
|
|
|
2010-12-03 13:51:27 +03:00
|
|
|
return text
|
2010-11-28 21:10:54 +03:00
|
|
|
|
|
|
|
def parseXmlNode(node):
|
2020-02-28 16:08:43 +03:00
|
|
|
for element in node.findall("boundary"):
|
2011-07-08 10:02:31 +04:00
|
|
|
boundary = AttribDict()
|
2010-11-28 21:10:54 +03:00
|
|
|
|
2020-02-28 16:24:50 +03:00
|
|
|
for child in element:
|
2010-11-28 21:10:54 +03:00
|
|
|
if child.text:
|
2010-12-03 13:51:27 +03:00
|
|
|
values = cleanupVals(child.text, child.tag)
|
2010-11-28 21:10:54 +03:00
|
|
|
boundary[child.tag] = values
|
|
|
|
else:
|
|
|
|
boundary[child.tag] = None
|
|
|
|
|
|
|
|
conf.boundaries.append(boundary)
|
|
|
|
|
2020-02-28 16:08:43 +03:00
|
|
|
for element in node.findall("test"):
|
2011-07-08 10:02:31 +04:00
|
|
|
test = AttribDict()
|
2010-11-28 21:10:54 +03:00
|
|
|
|
2020-02-28 16:24:50 +03:00
|
|
|
for child in element:
|
2010-11-28 21:10:54 +03:00
|
|
|
if child.text and child.text.strip():
|
2010-12-03 13:51:27 +03:00
|
|
|
values = cleanupVals(child.text, child.tag)
|
2010-11-28 21:10:54 +03:00
|
|
|
test[child.tag] = values
|
|
|
|
else:
|
2020-02-28 16:24:50 +03:00
|
|
|
if len(child.findall("*")) == 0:
|
2010-11-28 21:10:54 +03:00
|
|
|
test[child.tag] = None
|
|
|
|
continue
|
|
|
|
else:
|
2011-07-08 10:02:31 +04:00
|
|
|
test[child.tag] = AttribDict()
|
2010-11-28 21:10:54 +03:00
|
|
|
|
2020-02-28 16:24:50 +03:00
|
|
|
for gchild in child:
|
2010-11-28 21:10:54 +03:00
|
|
|
if gchild.tag in test[child.tag]:
|
|
|
|
prevtext = test[child.tag][gchild.tag]
|
|
|
|
test[child.tag][gchild.tag] = [prevtext, gchild.text]
|
|
|
|
else:
|
|
|
|
test[child.tag][gchild.tag] = gchild.text
|
|
|
|
|
|
|
|
conf.tests.append(test)
|
|
|
|
|
2015-02-15 19:31:35 +03:00
|
|
|
def loadBoundaries():
|
2020-02-28 16:24:50 +03:00
|
|
|
"""
|
|
|
|
Loads boundaries from XML
|
|
|
|
|
|
|
|
>>> conf.boundaries = []
|
|
|
|
>>> loadBoundaries()
|
|
|
|
>>> len(conf.boundaries) > 0
|
|
|
|
True
|
|
|
|
"""
|
|
|
|
|
2014-11-10 15:41:53 +03:00
|
|
|
try:
|
2015-02-15 19:31:35 +03:00
|
|
|
doc = et.parse(paths.BOUNDARIES_XML)
|
2019-01-22 02:40:48 +03:00
|
|
|
except Exception as ex:
|
2016-05-22 22:44:17 +03:00
|
|
|
errMsg = "something appears to be wrong with "
|
2015-10-23 15:29:48 +03:00
|
|
|
errMsg += "the file '%s' ('%s'). Please make " % (paths.BOUNDARIES_XML, getSafeExString(ex))
|
2014-11-10 15:41:53 +03:00
|
|
|
errMsg += "sure that you haven't made any changes to it"
|
2018-03-13 13:13:38 +03:00
|
|
|
raise SqlmapInstallationException(errMsg)
|
2014-11-10 15:41:53 +03:00
|
|
|
|
2010-11-28 21:10:54 +03:00
|
|
|
root = doc.getroot()
|
|
|
|
parseXmlNode(root)
|
2015-02-15 19:31:35 +03:00
|
|
|
|
|
|
|
def loadPayloads():
|
2020-02-28 16:24:50 +03:00
|
|
|
"""
|
|
|
|
Loads payloads/tests from XML
|
|
|
|
|
|
|
|
>>> conf.tests = []
|
|
|
|
>>> loadPayloads()
|
|
|
|
>>> len(conf.tests) > 0
|
|
|
|
True
|
|
|
|
"""
|
|
|
|
|
2016-07-17 01:21:16 +03:00
|
|
|
for payloadFile in PAYLOAD_XML_FILES:
|
2015-02-15 19:31:35 +03:00
|
|
|
payloadFilePath = os.path.join(paths.SQLMAP_XML_PAYLOADS_PATH, payloadFile)
|
|
|
|
|
|
|
|
try:
|
|
|
|
doc = et.parse(payloadFilePath)
|
2019-01-22 02:40:48 +03:00
|
|
|
except Exception as ex:
|
2016-05-22 22:44:17 +03:00
|
|
|
errMsg = "something appears to be wrong with "
|
2015-10-23 15:29:48 +03:00
|
|
|
errMsg += "the file '%s' ('%s'). Please make " % (payloadFilePath, getSafeExString(ex))
|
2015-02-15 19:31:35 +03:00
|
|
|
errMsg += "sure that you haven't made any changes to it"
|
2018-03-13 13:13:38 +03:00
|
|
|
raise SqlmapInstallationException(errMsg)
|
2015-02-15 19:31:35 +03:00
|
|
|
|
2015-02-18 13:13:28 +03:00
|
|
|
root = doc.getroot()
|
|
|
|
parseXmlNode(root)
|