2008-10-15 19:38:22 +04:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
"""
|
2012-07-12 21:38:03 +04:00
|
|
|
Copyright (c) 2006-2012 sqlmap developers (http://sqlmap.org/)
|
2010-10-15 03:18:29 +04:00
|
|
|
See the file 'doc/COPYING' for copying permission
|
2008-10-15 19:38:22 +04:00
|
|
|
"""
|
|
|
|
|
2008-12-10 20:23:07 +03:00
|
|
|
import re
|
2008-10-15 19:38:22 +04:00
|
|
|
import time
|
|
|
|
|
2012-02-22 14:40:11 +04:00
|
|
|
from extra.safe2bin.safe2bin import safecharencode
|
2008-10-15 19:38:22 +04:00
|
|
|
from lib.core.agent import agent
|
2012-02-16 13:46:41 +04:00
|
|
|
from lib.core.bigarray import BigArray
|
2012-03-19 16:00:22 +04:00
|
|
|
from lib.core.common import arrayizeValue
|
2011-01-28 19:36:09 +03:00
|
|
|
from lib.core.common import Backend
|
2011-01-31 15:41:39 +03:00
|
|
|
from lib.core.common import calculateDeltaSeconds
|
2011-03-26 00:31:26 +03:00
|
|
|
from lib.core.common import clearConsoleLine
|
|
|
|
from lib.core.common import dataToStdout
|
2011-03-17 11:54:20 +03:00
|
|
|
from lib.core.common import extractRegexResult
|
2012-04-03 17:56:11 +04:00
|
|
|
from lib.core.common import flattenValue
|
2011-04-13 18:33:15 +04:00
|
|
|
from lib.core.common import getConsoleWidth
|
2010-06-02 16:45:40 +04:00
|
|
|
from lib.core.common import getUnicode
|
2012-02-24 17:07:20 +04:00
|
|
|
from lib.core.common import hashDBRetrieve
|
|
|
|
from lib.core.common import hashDBWrite
|
2011-12-21 15:50:49 +04:00
|
|
|
from lib.core.common import incrementCounter
|
2011-01-12 01:18:47 +03:00
|
|
|
from lib.core.common import initTechnique
|
2012-03-14 17:16:49 +04:00
|
|
|
from lib.core.common import isNoneValue
|
2011-01-19 02:02:11 +03:00
|
|
|
from lib.core.common import isNumPosStrValue
|
2011-01-31 15:41:39 +03:00
|
|
|
from lib.core.common import listToStrValue
|
2008-12-10 20:23:07 +03:00
|
|
|
from lib.core.common import parseUnionPage
|
2011-02-25 12:22:44 +03:00
|
|
|
from lib.core.common import removeReflectiveValues
|
2011-06-08 18:35:23 +04:00
|
|
|
from lib.core.common import singleTimeWarnMessage
|
2012-02-29 19:02:24 +04:00
|
|
|
from lib.core.common import wasLastRequestDBMSError
|
|
|
|
from lib.core.convert import htmlunescape
|
2008-10-15 19:38:22 +04:00
|
|
|
from lib.core.data import conf
|
|
|
|
from lib.core.data import kb
|
|
|
|
from lib.core.data import logger
|
2008-12-10 20:23:07 +03:00
|
|
|
from lib.core.data import queries
|
2012-08-21 13:19:15 +04:00
|
|
|
from lib.core.dicts import FROM_DUMMY_TABLE
|
2010-11-08 12:20:02 +03:00
|
|
|
from lib.core.enums import DBMS
|
2011-01-12 01:18:47 +03:00
|
|
|
from lib.core.enums import PAYLOAD
|
2012-12-06 17:14:19 +04:00
|
|
|
from lib.core.exception import SqlmapSyntaxException
|
2011-05-19 20:45:05 +04:00
|
|
|
from lib.core.settings import SQL_SCALAR_REGEX
|
2011-04-22 23:58:10 +04:00
|
|
|
from lib.core.settings import TURN_OFF_RESUME_INFO_LIMIT
|
2011-05-30 03:17:50 +04:00
|
|
|
from lib.core.threads import getCurrentThreadData
|
|
|
|
from lib.core.threads import runThreads
|
2008-10-15 19:38:22 +04:00
|
|
|
from lib.core.unescaper import unescaper
|
|
|
|
from lib.request.connect import Connect as Request
|
|
|
|
|
2012-12-06 17:14:19 +04:00
|
|
|
def _oneShotUnionUse(expression, unpack=True, limited=False):
|
2012-10-28 02:36:09 +04:00
|
|
|
retVal = hashDBRetrieve("%s%s" % (conf.hexConvert, expression), checkConf=True) # as union data is stored raw unconverted
|
2011-09-26 00:36:32 +04:00
|
|
|
|
2011-10-12 02:40:00 +04:00
|
|
|
threadData = getCurrentThreadData()
|
|
|
|
threadData.resumed = retVal is not None
|
|
|
|
|
2011-10-12 01:58:57 +04:00
|
|
|
if retVal is None:
|
2011-09-26 00:36:32 +04:00
|
|
|
# Prepare expression with delimiters
|
2011-12-21 15:50:49 +04:00
|
|
|
injExpression = unescaper.unescape(agent.concatQuery(expression, unpack))
|
2011-09-26 00:36:32 +04:00
|
|
|
|
2011-12-21 15:50:49 +04:00
|
|
|
where = PAYLOAD.WHERE.NEGATIVE if conf.limitStart or conf.limitStop else None
|
2011-09-26 00:36:32 +04:00
|
|
|
|
2012-10-28 02:36:09 +04:00
|
|
|
# Forge the union SQL injection request
|
2011-09-26 00:36:32 +04:00
|
|
|
vector = kb.injection.data[PAYLOAD.TECHNIQUE.UNION].vector
|
2012-06-16 00:41:53 +04:00
|
|
|
kb.unionDuplicates = vector[7]
|
2012-10-28 02:36:09 +04:00
|
|
|
query = agent.forgeUnionQuery(injExpression, vector[0], vector[1], vector[2], vector[3], vector[4], vector[5], vector[6], None, limited)
|
2011-09-26 00:36:32 +04:00
|
|
|
payload = agent.payload(newValue=query, where=where)
|
|
|
|
|
|
|
|
# Perform the request
|
|
|
|
page, headers = Request.queryPage(payload, content=True, raise404=False)
|
|
|
|
|
2011-12-21 15:50:49 +04:00
|
|
|
incrementCounter(PAYLOAD.TECHNIQUE.UNION)
|
2011-09-26 00:36:32 +04:00
|
|
|
|
|
|
|
# Parse the returned page to get the exact union-based
|
2012-06-19 12:33:51 +04:00
|
|
|
# SQL injection output
|
2012-06-29 12:31:03 +04:00
|
|
|
def _(regex):
|
|
|
|
return reduce(lambda x, y: x if x is not None else y, ( \
|
|
|
|
extractRegexResult(regex, removeReflectiveValues(page, payload), re.DOTALL | re.IGNORECASE), \
|
|
|
|
extractRegexResult(regex, removeReflectiveValues(listToStrValue(headers.headers \
|
|
|
|
if headers else None), payload, True), re.DOTALL | re.IGNORECASE)), \
|
|
|
|
None)
|
|
|
|
|
|
|
|
# Automatically patching last char trimming cases
|
2012-07-29 19:33:08 +04:00
|
|
|
if kb.chars.stop not in (page or "") and kb.chars.stop[:-1] in (page or ""):
|
2012-06-29 12:33:54 +04:00
|
|
|
warnMsg = "automatically patching output having last char trimmed"
|
2012-06-29 12:31:03 +04:00
|
|
|
singleTimeWarnMessage(warnMsg)
|
|
|
|
page = page.replace(kb.chars.stop[:-1], kb.chars.stop)
|
|
|
|
|
|
|
|
retVal = _("(?P<result>%s.*%s)" % (kb.chars.start, kb.chars.stop))
|
2011-09-26 00:36:32 +04:00
|
|
|
|
|
|
|
if retVal is not None:
|
|
|
|
retVal = getUnicode(retVal, kb.pageEncoding)
|
2012-02-29 19:02:24 +04:00
|
|
|
|
2012-10-28 02:36:09 +04:00
|
|
|
# Special case when DBMS is Microsoft SQL Server and error message is used as a result of union injection
|
2012-02-29 19:02:24 +04:00
|
|
|
if Backend.isDbms(DBMS.MSSQL) and wasLastRequestDBMSError():
|
|
|
|
retVal = htmlunescape(retVal).replace("<br>", "\n")
|
2012-05-09 18:00:07 +04:00
|
|
|
|
|
|
|
hashDBWrite("%s%s" % (conf.hexConvert, expression), retVal)
|
2011-09-26 00:36:32 +04:00
|
|
|
else:
|
2012-06-29 12:31:03 +04:00
|
|
|
trimmed = _("%s(?P<result>.*?)<" % (kb.chars.start))
|
2011-09-26 00:36:32 +04:00
|
|
|
|
|
|
|
if trimmed:
|
2012-06-29 12:31:03 +04:00
|
|
|
warnMsg = "possible server trimmed output detected (probably due to its length): "
|
2012-07-30 23:43:32 +04:00
|
|
|
warnMsg += safecharencode(trimmed)
|
2011-09-26 00:36:32 +04:00
|
|
|
logger.warn(warnMsg)
|
|
|
|
|
|
|
|
return retVal
|
2011-02-02 01:07:42 +03:00
|
|
|
|
2011-01-20 01:48:06 +03:00
|
|
|
def configUnion(char=None, columns=None):
|
2012-12-06 17:14:19 +04:00
|
|
|
def _configUnionChar(char):
|
2011-05-10 19:34:54 +04:00
|
|
|
if not isinstance(char, basestring):
|
|
|
|
return
|
|
|
|
|
|
|
|
kb.uChar = char
|
|
|
|
|
|
|
|
if conf.uChar is not None:
|
|
|
|
kb.uChar = char.replace("[CHAR]", conf.uChar if conf.uChar.isdigit() else "'%s'" % conf.uChar.strip("'"))
|
2011-01-18 01:57:33 +03:00
|
|
|
|
2012-12-06 17:14:19 +04:00
|
|
|
def _configUnionCols(columns):
|
2011-05-10 19:34:54 +04:00
|
|
|
if not isinstance(columns, basestring):
|
|
|
|
return
|
|
|
|
|
2011-01-20 01:48:06 +03:00
|
|
|
columns = columns.replace(" ", "")
|
2011-06-18 14:51:14 +04:00
|
|
|
if "-" in columns:
|
|
|
|
colsStart, colsStop = columns.split("-")
|
|
|
|
else:
|
|
|
|
colsStart, colsStop = columns, columns
|
2011-01-18 01:57:33 +03:00
|
|
|
|
2011-01-25 16:04:13 +03:00
|
|
|
if not colsStart.isdigit() or not colsStop.isdigit():
|
2012-12-06 17:14:19 +04:00
|
|
|
raise SqlmapSyntaxException, "--union-cols must be a range of integers"
|
2011-01-18 01:57:33 +03:00
|
|
|
|
2011-12-21 15:50:49 +04:00
|
|
|
conf.uColsStart, conf.uColsStop = int(colsStart), int(colsStop)
|
2011-01-18 01:57:33 +03:00
|
|
|
|
2011-01-20 01:48:06 +03:00
|
|
|
if conf.uColsStart > conf.uColsStop:
|
|
|
|
errMsg = "--union-cols range has to be from lower to "
|
|
|
|
errMsg += "higher number of columns"
|
2012-12-06 17:14:19 +04:00
|
|
|
raise SqlmapSyntaxException, errMsg
|
2011-01-18 01:57:33 +03:00
|
|
|
|
2012-12-06 17:14:19 +04:00
|
|
|
_configUnionChar(char)
|
|
|
|
_configUnionCols(conf.uCols or columns)
|
2011-01-18 01:57:33 +03:00
|
|
|
|
2011-02-07 01:32:44 +03:00
|
|
|
def unionUse(expression, unpack=True, dump=False):
|
2008-10-15 19:38:22 +04:00
|
|
|
"""
|
2012-10-28 02:36:09 +04:00
|
|
|
This function tests for an union SQL injection on the target
|
2008-10-15 19:38:22 +04:00
|
|
|
url then call its subsidiary function to effectively perform an
|
2012-10-28 02:36:09 +04:00
|
|
|
union SQL injection on the affected url
|
2008-10-15 19:38:22 +04:00
|
|
|
"""
|
|
|
|
|
2011-01-12 01:18:47 +03:00
|
|
|
initTechnique(PAYLOAD.TECHNIQUE.UNION)
|
|
|
|
|
2012-02-03 14:38:04 +04:00
|
|
|
abortedFlag = False
|
2011-01-19 02:02:11 +03:00
|
|
|
count = None
|
|
|
|
origExpr = expression
|
2008-12-10 20:23:07 +03:00
|
|
|
startLimit = 0
|
2011-01-19 02:02:11 +03:00
|
|
|
stopLimit = None
|
2012-02-23 17:31:50 +04:00
|
|
|
value = None
|
2011-12-21 15:50:49 +04:00
|
|
|
|
2011-04-13 18:33:15 +04:00
|
|
|
width = getConsoleWidth()
|
2011-02-02 01:07:42 +03:00
|
|
|
start = time.time()
|
2008-12-10 20:23:07 +03:00
|
|
|
|
2011-02-02 01:07:42 +03:00
|
|
|
_, _, _, _, _, expressionFieldsList, expressionFields, _ = agent.getFields(origExpr)
|
2008-12-10 20:23:07 +03:00
|
|
|
|
2012-02-01 14:14:23 +04:00
|
|
|
if expressionFieldsList and len(expressionFieldsList) > 1 and " ORDER BY " in expression.upper():
|
2011-11-23 19:51:48 +04:00
|
|
|
# No need for it in multicolumn dumps (one row is retrieved per request) and just slowing down on large table dumps
|
2012-02-01 14:14:23 +04:00
|
|
|
expression = expression[:expression.upper().rindex(" ORDER BY ")]
|
2011-11-23 19:38:31 +04:00
|
|
|
|
2011-02-02 01:07:42 +03:00
|
|
|
# We have to check if the SQL query might return multiple entries
|
|
|
|
# and in such case forge the SQL limiting the query output one
|
|
|
|
# entry per time
|
|
|
|
# NOTE: I assume that only queries that get data from a table can
|
|
|
|
# return multiple entries
|
2011-02-02 16:34:09 +03:00
|
|
|
if (kb.injection.data[PAYLOAD.TECHNIQUE.UNION].where == PAYLOAD.WHERE.NEGATIVE or \
|
2011-02-02 01:07:42 +03:00
|
|
|
(dump and (conf.limitStart or conf.limitStop))) and \
|
|
|
|
" FROM " in expression.upper() and ((Backend.getIdentifiedDbms() \
|
2012-02-07 18:57:48 +04:00
|
|
|
not in FROM_DUMMY_TABLE) or (Backend.getIdentifiedDbms() in FROM_DUMMY_TABLE \
|
2012-02-07 16:05:23 +04:00
|
|
|
and not expression.upper().endswith(FROM_DUMMY_TABLE[Backend.getIdentifiedDbms()]))) \
|
2011-05-19 20:45:05 +04:00
|
|
|
and not re.search(SQL_SCALAR_REGEX, expression, re.I):
|
2008-10-15 19:38:22 +04:00
|
|
|
|
2012-12-19 14:50:15 +04:00
|
|
|
limitCond = True
|
2011-02-02 01:07:42 +03:00
|
|
|
limitRegExp = re.search(queries[Backend.getIdentifiedDbms()].limitregexp.query, expression, re.I)
|
2012-12-19 14:50:15 +04:00
|
|
|
limitRegExp2 = re.search(queries[Backend.getIdentifiedDbms()].limitregexp.query2, expression, re.I)
|
2011-02-02 01:07:42 +03:00
|
|
|
topLimit = re.search("TOP\s+([\d]+)\s+", expression, re.I)
|
2008-10-15 19:38:22 +04:00
|
|
|
|
2012-12-19 14:50:15 +04:00
|
|
|
if (limitRegExp or limitRegExp2) or (Backend.getIdentifiedDbms() in (DBMS.MSSQL, DBMS.SYBASE) and topLimit):
|
|
|
|
if Backend.getIdentifiedDbms() in (DBMS.MYSQL, DBMS.PGSQL, DBMS.SQLITE):
|
2011-02-02 01:07:42 +03:00
|
|
|
limitGroupStart = queries[Backend.getIdentifiedDbms()].limitgroupstart.query
|
|
|
|
limitGroupStop = queries[Backend.getIdentifiedDbms()].limitgroupstop.query
|
2008-12-10 20:23:07 +03:00
|
|
|
|
2011-02-02 01:07:42 +03:00
|
|
|
if limitGroupStart.isdigit():
|
2012-12-19 14:50:15 +04:00
|
|
|
if limitRegExp2:
|
|
|
|
startLimit = 0
|
|
|
|
stopLimit = limitRegExp2.group(int(limitGroupStart))
|
|
|
|
else:
|
|
|
|
startLimit = int(limitRegExp.group(int(limitGroupStart)))
|
|
|
|
stopLimit = limitRegExp.group(int(limitGroupStop))
|
2011-02-02 01:07:42 +03:00
|
|
|
limitCond = int(stopLimit) > 1
|
|
|
|
|
|
|
|
elif Backend.getIdentifiedDbms() in (DBMS.MSSQL, DBMS.SYBASE):
|
|
|
|
if limitRegExp:
|
2011-01-28 19:36:09 +03:00
|
|
|
limitGroupStart = queries[Backend.getIdentifiedDbms()].limitgroupstart.query
|
|
|
|
limitGroupStop = queries[Backend.getIdentifiedDbms()].limitgroupstop.query
|
2008-12-10 20:23:07 +03:00
|
|
|
|
|
|
|
if limitGroupStart.isdigit():
|
|
|
|
startLimit = int(limitRegExp.group(int(limitGroupStart)))
|
|
|
|
|
|
|
|
stopLimit = limitRegExp.group(int(limitGroupStop))
|
|
|
|
limitCond = int(stopLimit) > 1
|
2011-02-02 01:07:42 +03:00
|
|
|
elif topLimit:
|
|
|
|
startLimit = 0
|
|
|
|
stopLimit = int(topLimit.group(1))
|
|
|
|
limitCond = int(stopLimit) > 1
|
2008-12-10 20:23:07 +03:00
|
|
|
|
2011-04-30 18:54:29 +04:00
|
|
|
elif Backend.isDbms(DBMS.ORACLE):
|
2011-02-02 01:07:42 +03:00
|
|
|
limitCond = False
|
2011-01-19 02:02:11 +03:00
|
|
|
|
2011-02-02 01:07:42 +03:00
|
|
|
# I assume that only queries NOT containing a "LIMIT #, 1"
|
2012-12-19 14:50:15 +04:00
|
|
|
# (or equivalent depending on the back-end DBMS) can return
|
2011-02-02 01:07:42 +03:00
|
|
|
# multiple entries
|
|
|
|
if limitCond:
|
2012-12-19 14:50:15 +04:00
|
|
|
if (limitRegExp or limitRegExp2) and stopLimit is not None:
|
2011-02-02 01:07:42 +03:00
|
|
|
stopLimit = int(stopLimit)
|
2011-01-06 12:48:04 +03:00
|
|
|
|
2011-02-02 01:07:42 +03:00
|
|
|
# From now on we need only the expression until the " LIMIT "
|
2012-12-19 14:50:15 +04:00
|
|
|
# (or equivalent, depending on the back-end DBMS) word
|
|
|
|
if Backend.getIdentifiedDbms() in (DBMS.MYSQL, DBMS.PGSQL, DBMS.SQLITE):
|
2011-02-02 01:07:42 +03:00
|
|
|
stopLimit += startLimit
|
|
|
|
untilLimitChar = expression.index(queries[Backend.getIdentifiedDbms()].limitstring.query)
|
|
|
|
expression = expression[:untilLimitChar]
|
2008-12-10 20:23:07 +03:00
|
|
|
|
2011-02-02 01:07:42 +03:00
|
|
|
elif Backend.getIdentifiedDbms() in (DBMS.MSSQL, DBMS.SYBASE):
|
|
|
|
stopLimit += startLimit
|
|
|
|
elif dump:
|
|
|
|
if conf.limitStart:
|
2011-07-26 14:06:28 +04:00
|
|
|
startLimit = conf.limitStart - 1
|
2011-02-02 01:07:42 +03:00
|
|
|
if conf.limitStop:
|
|
|
|
stopLimit = conf.limitStop
|
|
|
|
|
|
|
|
# Count the number of SQL query entries output
|
2012-11-15 18:06:54 +04:00
|
|
|
countedExpression = expression.replace(expressionFields, queries[Backend.getIdentifiedDbms()].count.query % ('*' if len(expressionFieldsList) > 1 else expressionFields), 1)
|
2011-02-02 01:07:42 +03:00
|
|
|
|
2012-02-01 14:14:23 +04:00
|
|
|
if " ORDER BY " in countedExpression.upper():
|
|
|
|
_ = countedExpression.upper().rindex(" ORDER BY ")
|
|
|
|
countedExpression = countedExpression[:_]
|
2011-02-02 01:07:42 +03:00
|
|
|
|
2012-12-06 17:14:19 +04:00
|
|
|
output = _oneShotUnionUse(countedExpression, unpack)
|
2012-02-17 18:22:48 +04:00
|
|
|
count = parseUnionPage(output)
|
2011-02-02 01:07:42 +03:00
|
|
|
|
2011-05-12 15:36:02 +04:00
|
|
|
if isNumPosStrValue(count):
|
2011-02-02 01:07:42 +03:00
|
|
|
if isinstance(stopLimit, int) and stopLimit > 0:
|
|
|
|
stopLimit = min(int(count), int(stopLimit))
|
|
|
|
else:
|
|
|
|
stopLimit = int(count)
|
|
|
|
|
|
|
|
infoMsg = "the SQL query used returns "
|
|
|
|
infoMsg += "%d entries" % stopLimit
|
|
|
|
logger.info(infoMsg)
|
2011-02-25 12:22:44 +03:00
|
|
|
|
2012-02-01 16:28:06 +04:00
|
|
|
elif count and (not isinstance(count, basestring) or not count.isdigit()):
|
2011-05-12 15:36:02 +04:00
|
|
|
warnMsg = "it was not possible to count the number "
|
2011-08-02 12:39:32 +04:00
|
|
|
warnMsg += "of entries for the SQL query provided. "
|
2011-05-12 15:36:02 +04:00
|
|
|
warnMsg += "sqlmap will assume that it returns only "
|
|
|
|
warnMsg += "one entry"
|
|
|
|
logger.warn(warnMsg)
|
|
|
|
|
|
|
|
stopLimit = 1
|
|
|
|
|
2012-12-19 15:40:00 +04:00
|
|
|
elif (not count or int(count) == 0):
|
2012-01-07 21:45:45 +04:00
|
|
|
if not count:
|
|
|
|
warnMsg = "the SQL query provided does not "
|
|
|
|
warnMsg += "return any output"
|
|
|
|
logger.warn(warnMsg)
|
2012-05-09 14:34:21 +04:00
|
|
|
else:
|
|
|
|
value = [] # for empty tables
|
2011-08-02 21:31:13 +04:00
|
|
|
return value
|
2011-08-02 12:39:32 +04:00
|
|
|
|
2011-07-03 02:48:56 +04:00
|
|
|
threadData = getCurrentThreadData()
|
2011-07-26 00:17:44 +04:00
|
|
|
threadData.shared.limits = iter(xrange(startLimit, stopLimit))
|
|
|
|
numThreads = min(conf.threads, (stopLimit - startLimit))
|
2011-07-25 00:36:44 +04:00
|
|
|
threadData.shared.value = BigArray()
|
2012-12-18 19:03:35 +04:00
|
|
|
threadData.shared.buffered = []
|
|
|
|
threadData.shared.lastFlushed = startLimit - 1
|
2011-06-07 21:16:01 +04:00
|
|
|
|
2011-07-03 02:48:56 +04:00
|
|
|
if stopLimit > TURN_OFF_RESUME_INFO_LIMIT:
|
|
|
|
kb.suppressResumeInfo = True
|
|
|
|
debugMsg = "suppressing possible resume console info because of "
|
|
|
|
debugMsg += "large number of rows. It might take too long"
|
|
|
|
logger.debug(debugMsg)
|
2011-04-22 23:58:10 +04:00
|
|
|
|
2011-07-03 02:48:56 +04:00
|
|
|
try:
|
2011-05-30 03:17:50 +04:00
|
|
|
def unionThread():
|
2011-06-07 13:50:00 +04:00
|
|
|
threadData = getCurrentThreadData()
|
|
|
|
|
|
|
|
while kb.threadContinue:
|
2012-06-14 17:50:36 +04:00
|
|
|
with kb.locks.limits:
|
|
|
|
try:
|
|
|
|
num = threadData.shared.limits.next()
|
|
|
|
except StopIteration:
|
|
|
|
break
|
2011-06-07 13:50:00 +04:00
|
|
|
|
|
|
|
if Backend.getIdentifiedDbms() in (DBMS.MSSQL, DBMS.SYBASE):
|
|
|
|
field = expressionFieldsList[0]
|
|
|
|
elif Backend.isDbms(DBMS.ORACLE):
|
|
|
|
field = expressionFieldsList
|
|
|
|
else:
|
|
|
|
field = None
|
|
|
|
|
|
|
|
limitedExpr = agent.limitQuery(num, expression, field)
|
2012-12-06 17:14:19 +04:00
|
|
|
output = _oneShotUnionUse(limitedExpr, unpack, True)
|
2011-06-07 13:50:00 +04:00
|
|
|
|
|
|
|
if not kb.threadContinue:
|
|
|
|
break
|
|
|
|
|
|
|
|
if output:
|
2012-12-18 19:03:35 +04:00
|
|
|
if all(map(lambda _: _ in output, (kb.chars.start, kb.chars.stop))):
|
2012-03-14 15:23:30 +04:00
|
|
|
items = parseUnionPage(output)
|
2012-12-18 19:03:35 +04:00
|
|
|
|
2012-06-14 17:50:36 +04:00
|
|
|
with kb.locks.value:
|
2012-12-18 19:03:35 +04:00
|
|
|
index = None
|
|
|
|
for index in xrange(len(threadData.shared.buffered)):
|
|
|
|
if threadData.shared.buffered[index][0] >= num:
|
|
|
|
break
|
|
|
|
threadData.shared.buffered.insert(index or 0, (num, items))
|
|
|
|
while threadData.shared.buffered and threadData.shared.lastFlushed + 1 == threadData.shared.buffered[0][0]:
|
|
|
|
threadData.shared.lastFlushed += 1
|
|
|
|
_ = threadData.shared.buffered[0][1]
|
|
|
|
if not isNoneValue(_):
|
|
|
|
threadData.shared.value.extend(arrayizeValue(_))
|
|
|
|
del threadData.shared.buffered[0]
|
2011-07-25 00:36:44 +04:00
|
|
|
else:
|
2012-12-18 19:03:35 +04:00
|
|
|
with kb.locks.value:
|
|
|
|
index = None
|
|
|
|
for index in xrange(len(threadData.shared.buffered)):
|
|
|
|
if threadData.shared.buffered[index][0] >= num:
|
|
|
|
break
|
|
|
|
threadData.shared.buffered.insert(index or 0, (num, None))
|
2011-09-26 01:10:45 +04:00
|
|
|
items = output.replace(kb.chars.start, "").replace(kb.chars.stop, "").split(kb.chars.delimiter)
|
2011-06-07 13:50:00 +04:00
|
|
|
|
2012-06-25 20:19:51 +04:00
|
|
|
if conf.verbose == 1 and not (threadData.resumed and kb.suppressResumeInfo):
|
2012-04-03 17:56:11 +04:00
|
|
|
status = "[%s] [INFO] %s: %s" % (time.strftime("%X"), "resumed" if threadData.resumed else "retrieved", safecharencode(",".join("\"%s\"" % _ for _ in flattenValue(arrayizeValue(items)))))
|
2011-06-07 13:50:00 +04:00
|
|
|
|
|
|
|
if len(status) > width:
|
|
|
|
status = "%s..." % status[:width - 3]
|
|
|
|
|
2012-02-12 23:11:54 +04:00
|
|
|
dataToStdout("%s\r\n" % status, True)
|
2011-05-30 03:17:50 +04:00
|
|
|
|
|
|
|
runThreads(numThreads, unionThread)
|
|
|
|
|
2011-03-26 00:31:26 +03:00
|
|
|
if conf.verbose == 1:
|
|
|
|
clearConsoleLine(True)
|
2008-12-10 20:23:07 +03:00
|
|
|
|
2011-02-02 01:07:42 +03:00
|
|
|
except KeyboardInterrupt:
|
2012-02-03 14:38:04 +04:00
|
|
|
abortedFlag = True
|
|
|
|
|
2011-04-06 18:40:45 +04:00
|
|
|
warnMsg = "user aborted during enumeration. sqlmap "
|
2011-03-31 18:13:53 +04:00
|
|
|
warnMsg += "will display partial output"
|
2011-02-02 01:07:42 +03:00
|
|
|
logger.warn(warnMsg)
|
2008-10-15 19:38:22 +04:00
|
|
|
|
2011-04-22 23:58:10 +04:00
|
|
|
finally:
|
2012-12-18 19:03:35 +04:00
|
|
|
for _ in sorted(threadData.shared.buffered):
|
|
|
|
if not isNoneValue(_[1]):
|
|
|
|
threadData.shared.value.extend(arrayizeValue(_[1]))
|
2011-06-07 21:16:01 +04:00
|
|
|
value = threadData.shared.value
|
2011-04-22 23:58:10 +04:00
|
|
|
kb.suppressResumeInfo = False
|
|
|
|
|
2012-02-03 14:38:04 +04:00
|
|
|
if not value and not abortedFlag:
|
2012-10-28 02:36:09 +04:00
|
|
|
expression = re.sub("\s*ORDER BY\s+[\w,]+", "", expression, re.I) # full union doesn't play well with ORDER BY
|
2012-12-06 17:14:19 +04:00
|
|
|
value = _oneShotUnionUse(expression, unpack)
|
2008-10-15 19:38:22 +04:00
|
|
|
|
2011-02-02 01:07:42 +03:00
|
|
|
duration = calculateDeltaSeconds(start)
|
2008-10-15 19:38:22 +04:00
|
|
|
|
2011-04-08 15:02:21 +04:00
|
|
|
if not kb.bruteMode:
|
2011-12-21 15:50:49 +04:00
|
|
|
debugMsg = "performed %d queries in %d seconds" % (kb.counters[PAYLOAD.TECHNIQUE.UNION], duration)
|
2011-04-08 15:02:21 +04:00
|
|
|
logger.debug(debugMsg)
|
2008-10-15 19:38:22 +04:00
|
|
|
|
|
|
|
return value
|