diff --git a/lib/core/common.py b/lib/core/common.py index fe23b0f18..56a838875 100644 --- a/lib/core/common.py +++ b/lib/core/common.py @@ -661,6 +661,9 @@ def filePathToString(filePath): return strRepl +def singleTimeDebugMessage(message): + singleTimeLogMessage(message, logging.DEBUG) + def singleTimeWarnMessage(message): singleTimeLogMessage(message, logging.WARN) diff --git a/lib/techniques/union/use.py b/lib/techniques/union/use.py index 02ff14191..85e810fd1 100644 --- a/lib/techniques/union/use.py +++ b/lib/techniques/union/use.py @@ -29,6 +29,7 @@ from lib.core.common import isNumPosStrValue from lib.core.common import listToStrValue from lib.core.common import parseUnionPage from lib.core.common import removeReflectiveValues +from lib.core.common import singleTimeDebugMessage from lib.core.common import singleTimeWarnMessage from lib.core.common import wasLastRequestDBMSError from lib.core.convert import htmlunescape @@ -159,6 +160,13 @@ def unionUse(expression, unpack=True, dump=False): _, _, _, _, _, expressionFieldsList, expressionFields, _ = agent.getFields(origExpr) + if expressionFieldsList and len(expressionFieldsList) > 1 and "ORDER BY" in expression.upper(): + # Removed ORDER BY clause because UNION does not play well with it + expression = re.sub("\s*ORDER BY\s+[\w,]+", "", expression, re.I) + debugMsg = "stripping ORDER BY clause from statement because " + debugMsg += "it does not play well with UNION query SQL injection" + singleTimeDebugMessage(debugMsg) + # We have to check if the SQL query might return multiple entries # if the technique is partial UNION query and in such case forge the # SQL limiting the query output one entry at a time @@ -301,7 +309,6 @@ def unionUse(expression, unpack=True, dump=False): kb.suppressResumeInfo = False if not value and not abortedFlag: - expression = re.sub("\s*ORDER BY\s+[\w,]+", "", expression, re.I) # full union does not play well with ORDER BY value = _oneShotUnionUse(expression, unpack) duration = calculateDeltaSeconds(start) diff --git a/xml/livetests.xml b/xml/livetests.xml index 2617b5a06..2ffa01e19 100644 --- a/xml/livetests.xml +++ b/xml/livetests.xml @@ -283,11 +283,14 @@ - + + + @@ -632,5 +635,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +