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
|
|
|
|
|
2010-12-04 01:44:29 +03:00
|
|
|
from lib.core.common import aliasToDbmsEnum
|
2008-10-15 19:38:22 +04:00
|
|
|
from lib.core.common import dataToSessionFile
|
2009-04-22 15:48:07 +04:00
|
|
|
from lib.core.common import formatFingerprintString
|
2008-10-15 19:38:22 +04:00
|
|
|
from lib.core.common import readInput
|
2010-12-01 20:09:52 +03:00
|
|
|
from lib.core.convert import base64pickle
|
|
|
|
from lib.core.convert import base64unpickle
|
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
|
2010-11-29 04:04:42 +03:00
|
|
|
from lib.core.datatype import injectionDict
|
2010-11-28 21:10:54 +03:00
|
|
|
from lib.core.enums import PAYLOAD
|
2010-11-08 12:20:02 +03:00
|
|
|
from lib.core.enums import PLACE
|
2008-10-15 19:38:22 +04:00
|
|
|
from lib.core.settings import MSSQL_ALIASES
|
|
|
|
from lib.core.settings import MYSQL_ALIASES
|
2009-07-09 15:05:24 +04:00
|
|
|
from lib.core.settings import PGSQL_ALIASES
|
|
|
|
from lib.core.settings import ORACLE_ALIASES
|
2008-10-15 19:38:22 +04:00
|
|
|
|
2010-10-11 00:51:11 +04:00
|
|
|
def safeFormatString(value):
|
|
|
|
retVal = value
|
|
|
|
if retVal:
|
|
|
|
retVal = retVal.replace("[", "__LEFT_SQUARE_BRACKET__").replace("]", "__RIGHT_SQUARE_BRACKET__")
|
|
|
|
return retVal
|
|
|
|
|
|
|
|
def unSafeFormatString(value):
|
|
|
|
retVal = value
|
|
|
|
if retVal:
|
|
|
|
retVal = retVal.replace("__LEFT_SQUARE_BRACKET__", "[").replace("__RIGHT_SQUARE_BRACKET__", "]")
|
|
|
|
return retVal
|
|
|
|
|
2008-10-15 19:38:22 +04:00
|
|
|
def setString():
|
|
|
|
"""
|
|
|
|
Save string to match in session file.
|
|
|
|
"""
|
|
|
|
|
|
|
|
condition = (
|
2008-10-16 19:31:02 +04:00
|
|
|
not kb.resumedQueries or ( kb.resumedQueries.has_key(conf.url) and
|
|
|
|
not kb.resumedQueries[conf.url].has_key("String") )
|
2008-10-15 19:38:22 +04:00
|
|
|
)
|
|
|
|
|
|
|
|
if condition:
|
2010-10-11 00:51:11 +04:00
|
|
|
dataToSessionFile("[%s][None][None][String][%s]\n" % (conf.url, safeFormatString(conf.string)))
|
2008-10-15 19:38:22 +04:00
|
|
|
|
2008-12-12 22:06:31 +03:00
|
|
|
def setRegexp():
|
|
|
|
"""
|
|
|
|
Save regular expression to match in session file.
|
|
|
|
"""
|
|
|
|
|
|
|
|
condition = (
|
|
|
|
not kb.resumedQueries or ( kb.resumedQueries.has_key(conf.url) and
|
|
|
|
not kb.resumedQueries[conf.url].has_key("Regular expression") )
|
|
|
|
)
|
|
|
|
|
|
|
|
if condition:
|
2010-10-11 00:51:11 +04:00
|
|
|
dataToSessionFile("[%s][None][None][Regular expression][%s]\n" % (conf.url, safeFormatString(conf.regexp)))
|
2008-12-12 22:06:31 +03:00
|
|
|
|
2009-04-22 15:48:07 +04:00
|
|
|
def setMatchRatio():
|
|
|
|
condition = (
|
2010-11-12 13:31:42 +03:00
|
|
|
isinstance(conf.matchRatio, (int, float))
|
|
|
|
and ( not kb.resumedQueries
|
|
|
|
or ( kb.resumedQueries.has_key(conf.url) and not
|
|
|
|
kb.resumedQueries[conf.url].has_key("Match ratio") ) )
|
2009-04-22 15:48:07 +04:00
|
|
|
)
|
|
|
|
|
|
|
|
if condition:
|
2010-11-28 21:10:54 +03:00
|
|
|
dataToSessionFile("[%s][%s][%s][Match ratio][%s]\n" % (conf.url, kb.injection.place, safeFormatString(conf.parameters[kb.injection.place]), conf.matchRatio))
|
2009-04-22 15:48:07 +04:00
|
|
|
|
2010-11-28 21:10:54 +03:00
|
|
|
def setInjection(inj):
|
2008-10-15 19:38:22 +04:00
|
|
|
"""
|
|
|
|
Save information retrieved about injection place and parameter in the
|
|
|
|
session file.
|
|
|
|
"""
|
|
|
|
|
|
|
|
condition = (
|
2010-11-28 21:10:54 +03:00
|
|
|
( not kb.resumedQueries
|
2008-10-15 19:38:22 +04:00
|
|
|
or ( kb.resumedQueries.has_key(conf.url) and
|
2010-12-01 20:09:52 +03:00
|
|
|
not kb.resumedQueries[conf.url].has_key("Injection data")
|
|
|
|
) )
|
2008-10-15 19:38:22 +04:00
|
|
|
)
|
|
|
|
|
|
|
|
if condition:
|
2010-12-01 20:09:52 +03:00
|
|
|
dataToSessionFile("[%s][%s][%s][Injection data][%s]\n" % (conf.url, inj.place, safeFormatString(conf.parameters[inj.place]), base64pickle(inj)))
|
2010-11-29 04:04:42 +03:00
|
|
|
|
2008-10-15 19:38:22 +04:00
|
|
|
def setDbms(dbms):
|
|
|
|
"""
|
|
|
|
@param dbms: database management system to be set into the knowledge
|
|
|
|
base as fingerprint.
|
|
|
|
@type dbms: C{str}
|
|
|
|
"""
|
|
|
|
|
|
|
|
condition = (
|
2008-10-16 19:31:02 +04:00
|
|
|
not kb.resumedQueries
|
2008-10-15 19:38:22 +04:00
|
|
|
or ( kb.resumedQueries.has_key(conf.url) and
|
2008-10-16 19:31:02 +04:00
|
|
|
not kb.resumedQueries[conf.url].has_key("DBMS") )
|
2008-10-15 19:38:22 +04:00
|
|
|
)
|
|
|
|
|
|
|
|
if condition:
|
2010-11-28 21:10:54 +03:00
|
|
|
dataToSessionFile("[%s][%s][%s][DBMS][%s]\n" % (conf.url, kb.injection.place, safeFormatString(conf.parameters[kb.injection.place]), safeFormatString(dbms)))
|
2008-10-15 19:38:22 +04:00
|
|
|
|
2009-07-09 15:05:24 +04:00
|
|
|
firstRegExp = "(%s|%s|%s|%s)" % ("|".join([alias for alias in MSSQL_ALIASES]),
|
|
|
|
"|".join([alias for alias in MYSQL_ALIASES]),
|
|
|
|
"|".join([alias for alias in PGSQL_ALIASES]),
|
|
|
|
"|".join([alias for alias in ORACLE_ALIASES]))
|
2008-10-15 19:38:22 +04:00
|
|
|
dbmsRegExp = re.search("^%s" % firstRegExp, dbms, re.I)
|
|
|
|
|
|
|
|
if dbmsRegExp:
|
|
|
|
dbms = dbmsRegExp.group(1)
|
|
|
|
|
|
|
|
kb.dbms = dbms
|
|
|
|
|
2008-12-31 00:24:01 +03:00
|
|
|
logger.info("the back-end DBMS is %s" % kb.dbms)
|
|
|
|
|
2009-04-22 15:48:07 +04:00
|
|
|
def setOs():
|
|
|
|
"""
|
|
|
|
Example of kb.bannerFp dictionary:
|
|
|
|
|
|
|
|
{
|
|
|
|
'sp': set(['Service Pack 4']),
|
|
|
|
'dbmsVersion': '8.00.194',
|
|
|
|
'dbmsServicePack': '0',
|
|
|
|
'distrib': set(['2000']),
|
|
|
|
'dbmsRelease': '2000',
|
|
|
|
'type': set(['Windows'])
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
infoMsg = ""
|
|
|
|
condition = (
|
|
|
|
not kb.resumedQueries
|
|
|
|
or ( kb.resumedQueries.has_key(conf.url) and
|
|
|
|
not kb.resumedQueries[conf.url].has_key("OS") )
|
|
|
|
)
|
|
|
|
|
|
|
|
if not kb.bannerFp:
|
|
|
|
return
|
|
|
|
|
|
|
|
if "type" in kb.bannerFp:
|
|
|
|
kb.os = formatFingerprintString(kb.bannerFp["type"])
|
|
|
|
infoMsg = "the back-end DBMS operating system is %s" % kb.os
|
|
|
|
|
|
|
|
if "distrib" in kb.bannerFp:
|
|
|
|
kb.osVersion = formatFingerprintString(kb.bannerFp["distrib"])
|
|
|
|
infoMsg += " %s" % kb.osVersion
|
|
|
|
|
|
|
|
if "sp" in kb.bannerFp:
|
|
|
|
kb.osSP = int(formatFingerprintString(kb.bannerFp["sp"]).replace("Service Pack ", ""))
|
|
|
|
|
|
|
|
elif "sp" not in kb.bannerFp and kb.os == "Windows":
|
|
|
|
kb.osSP = 0
|
|
|
|
|
2009-07-29 14:44:24 +04:00
|
|
|
if kb.os and kb.osVersion and kb.osSP:
|
2009-04-22 15:48:07 +04:00
|
|
|
infoMsg += " Service Pack %d" % kb.osSP
|
|
|
|
|
|
|
|
if infoMsg:
|
|
|
|
logger.info(infoMsg)
|
|
|
|
|
|
|
|
if condition:
|
2010-11-28 21:10:54 +03:00
|
|
|
dataToSessionFile("[%s][%s][%s][OS][%s]\n" % (conf.url, kb.injection.place, safeFormatString(conf.parameters[kb.injection.place]), safeFormatString(kb.os)))
|
2009-04-22 15:48:07 +04:00
|
|
|
|
2010-11-28 21:10:54 +03:00
|
|
|
def setBooleanBased(place, parameter, payload):
|
|
|
|
condition = (
|
|
|
|
not kb.resumedQueries or ( kb.resumedQueries.has_key(conf.url) and
|
|
|
|
not kb.resumedQueries[conf.url].has_key("Boolean-based blind injection") )
|
|
|
|
)
|
|
|
|
|
|
|
|
if condition:
|
|
|
|
dataToSessionFile("[%s][%s][%s][Boolean-based blind injection][%s]\n" % (conf.url, place, safeFormatString(conf.parameters[place]), payload))
|
|
|
|
|
|
|
|
def setStacked(place, parameter, payload):
|
2009-04-22 15:48:07 +04:00
|
|
|
condition = (
|
|
|
|
not kb.resumedQueries or ( kb.resumedQueries.has_key(conf.url) and
|
|
|
|
not kb.resumedQueries[conf.url].has_key("Stacked queries") )
|
|
|
|
)
|
|
|
|
|
2010-11-28 21:10:54 +03:00
|
|
|
if condition:
|
|
|
|
dataToSessionFile("[%s][%s][%s][Stacked queries][%s]\n" % (conf.url, place, safeFormatString(conf.parameters[place]), payload))
|
|
|
|
|
|
|
|
def setError(place, parameter, payload):
|
|
|
|
condition = (
|
|
|
|
not kb.resumedQueries or ( kb.resumedQueries.has_key(conf.url) and
|
|
|
|
not kb.resumedQueries[conf.url].has_key("Error-based injection") )
|
|
|
|
)
|
2009-04-22 15:48:07 +04:00
|
|
|
|
|
|
|
if condition:
|
2010-11-28 21:10:54 +03:00
|
|
|
dataToSessionFile("[%s][%s][%s][Error-based injection][%s]\n" % (conf.url, place, safeFormatString(conf.parameters[place]), payload))
|
2009-04-22 15:48:07 +04:00
|
|
|
|
2010-11-28 21:10:54 +03:00
|
|
|
def setTimeBased(place, parameter, payload):
|
2010-10-19 22:17:34 +04:00
|
|
|
condition = (
|
|
|
|
not kb.resumedQueries or ( kb.resumedQueries.has_key(conf.url) and
|
2010-11-28 21:10:54 +03:00
|
|
|
not kb.resumedQueries[conf.url].has_key("Time-based blind injection") )
|
2010-10-19 22:17:34 +04:00
|
|
|
)
|
|
|
|
|
|
|
|
if condition:
|
2010-11-28 21:10:54 +03:00
|
|
|
dataToSessionFile("[%s][%s][%s][Time-based blind injection][%s]\n" % (conf.url, place, safeFormatString(conf.parameters[place]), payload))
|
2010-10-19 22:17:34 +04:00
|
|
|
|
2010-12-01 13:59:58 +03:00
|
|
|
def setUnion(comment=None, count=None, position=None, negative=False, falseCond=False, char=None, payload=None):
|
2008-10-15 19:38:22 +04:00
|
|
|
"""
|
|
|
|
@param comment: union comment to save in session file
|
|
|
|
@type comment: C{str}
|
|
|
|
|
|
|
|
@param count: union count to save in session file
|
|
|
|
@type count: C{str}
|
|
|
|
|
|
|
|
@param position: union position to save in session file
|
|
|
|
@type position: C{str}
|
|
|
|
"""
|
|
|
|
|
2010-11-18 20:55:43 +03:00
|
|
|
if comment:
|
2008-10-15 19:38:22 +04:00
|
|
|
condition = (
|
2008-10-16 19:31:02 +04:00
|
|
|
not kb.resumedQueries or ( kb.resumedQueries.has_key(conf.url) and
|
2010-11-18 20:55:43 +03:00
|
|
|
not kb.resumedQueries[conf.url].has_key("Union comment") )
|
2008-10-15 19:38:22 +04:00
|
|
|
)
|
|
|
|
|
|
|
|
if condition:
|
2010-11-28 21:10:54 +03:00
|
|
|
dataToSessionFile("[%s][%s][%s][Union comment][%s]\n" % (conf.url, kb.injection.place, safeFormatString(conf.parameters[kb.injection.place]), safeFormatString(comment)))
|
2008-10-15 19:38:22 +04:00
|
|
|
|
|
|
|
kb.unionComment = comment
|
2010-11-18 20:55:43 +03:00
|
|
|
|
|
|
|
if count:
|
|
|
|
condition = (
|
|
|
|
not kb.resumedQueries or ( kb.resumedQueries.has_key(conf.url) and
|
|
|
|
not kb.resumedQueries[conf.url].has_key("Union count") )
|
|
|
|
)
|
|
|
|
|
|
|
|
if condition:
|
2010-11-28 21:10:54 +03:00
|
|
|
dataToSessionFile("[%s][%s][%s][Union count][%d]\n" % (conf.url, kb.injection.place, safeFormatString(conf.parameters[kb.injection.place]), count))
|
2010-11-18 20:55:43 +03:00
|
|
|
|
2008-10-15 19:38:22 +04:00
|
|
|
kb.unionCount = count
|
|
|
|
|
2010-10-26 03:39:55 +04:00
|
|
|
if position is not None:
|
2008-10-15 19:38:22 +04:00
|
|
|
condition = (
|
2008-10-16 19:31:02 +04:00
|
|
|
not kb.resumedQueries or ( kb.resumedQueries.has_key(conf.url) and
|
2010-11-18 20:55:43 +03:00
|
|
|
not kb.resumedQueries[conf.url].has_key("Union position") )
|
2008-10-15 19:38:22 +04:00
|
|
|
)
|
|
|
|
|
|
|
|
if condition:
|
2010-11-28 21:10:54 +03:00
|
|
|
dataToSessionFile("[%s][%s][%s][Union position][%s]\n" % (conf.url, kb.injection.place, safeFormatString(conf.parameters[kb.injection.place]), position))
|
2008-10-15 19:38:22 +04:00
|
|
|
|
|
|
|
kb.unionPosition = position
|
|
|
|
|
2010-03-22 18:39:29 +03:00
|
|
|
if negative:
|
|
|
|
condition = (
|
|
|
|
not kb.resumedQueries or ( kb.resumedQueries.has_key(conf.url) and
|
|
|
|
( not kb.resumedQueries[conf.url].has_key("Union negative")
|
|
|
|
) )
|
|
|
|
)
|
|
|
|
|
|
|
|
if condition:
|
2010-11-28 21:10:54 +03:00
|
|
|
dataToSessionFile("[%s][%s][%s][Union negative][Yes]\n" % (conf.url, kb.injection.place, safeFormatString(conf.parameters[kb.injection.place])))
|
2010-03-22 18:39:29 +03:00
|
|
|
|
|
|
|
kb.unionNegative = True
|
|
|
|
|
|
|
|
if falseCond:
|
|
|
|
condition = (
|
|
|
|
not kb.resumedQueries or ( kb.resumedQueries.has_key(conf.url) and
|
|
|
|
( not kb.resumedQueries[conf.url].has_key("Union false condition")
|
|
|
|
) )
|
|
|
|
)
|
|
|
|
|
|
|
|
if condition:
|
2010-11-28 21:10:54 +03:00
|
|
|
dataToSessionFile("[%s][%s][%s][Union false condition][Yes]\n" % (conf.url, kb.injection.place, safeFormatString(conf.parameters[kb.injection.place])))
|
2010-03-22 18:39:29 +03:00
|
|
|
|
|
|
|
kb.unionFalseCond = True
|
|
|
|
|
2010-12-01 13:59:58 +03:00
|
|
|
if char:
|
|
|
|
condition = (
|
|
|
|
not kb.resumedQueries or ( kb.resumedQueries.has_key(conf.url) and
|
|
|
|
( not kb.resumedQueries[conf.url].has_key("Union char")
|
|
|
|
) )
|
|
|
|
)
|
|
|
|
|
|
|
|
if condition:
|
|
|
|
dataToSessionFile("[%s][%s][%s][Union char][%s]\n" % (conf.url, kb.injection.place, safeFormatString(conf.parameters[kb.injection.place]), char))
|
|
|
|
|
2010-11-14 02:24:41 +03:00
|
|
|
if payload:
|
|
|
|
condition = (
|
|
|
|
not kb.resumedQueries or ( kb.resumedQueries.has_key(conf.url) and
|
|
|
|
( not kb.resumedQueries[conf.url].has_key("Union payload")
|
|
|
|
) )
|
|
|
|
)
|
|
|
|
|
|
|
|
if condition:
|
2010-11-28 21:10:54 +03:00
|
|
|
dataToSessionFile("[%s][%s][%s][Union payload][%s]\n" % (conf.url, kb.injection.place, safeFormatString(conf.parameters[kb.injection.place]), payload))
|
2010-11-14 02:24:41 +03:00
|
|
|
|
|
|
|
kb.unionTest = payload
|
|
|
|
|
2009-04-22 15:48:07 +04:00
|
|
|
def setRemoteTempPath():
|
|
|
|
condition = (
|
|
|
|
not kb.resumedQueries or ( kb.resumedQueries.has_key(conf.url) and
|
|
|
|
not kb.resumedQueries[conf.url].has_key("Remote temp path") )
|
|
|
|
)
|
|
|
|
|
|
|
|
if condition:
|
2010-11-28 21:10:54 +03:00
|
|
|
dataToSessionFile("[%s][%s][%s][Remote temp path][%s]\n" % (conf.url, kb.injection.place, safeFormatString(conf.parameters[kb.injection.place]), safeFormatString(conf.tmpPath)))
|
2009-04-22 15:48:07 +04:00
|
|
|
|
2008-10-15 19:38:22 +04:00
|
|
|
def resumeConfKb(expression, url, value):
|
|
|
|
if expression == "String" and url == conf.url:
|
2010-10-11 00:51:11 +04:00
|
|
|
string = unSafeFormatString(value[:-1])
|
2008-10-15 19:38:22 +04:00
|
|
|
|
2010-11-29 04:04:42 +03:00
|
|
|
logMsg = "resuming string match '%s' from session file" % string
|
2008-10-15 19:38:22 +04:00
|
|
|
logger.info(logMsg)
|
|
|
|
|
|
|
|
if string and ( not conf.string or string != conf.string ):
|
|
|
|
if not conf.string:
|
|
|
|
message = "you did not provide any string to match. "
|
|
|
|
else:
|
|
|
|
message = "The string you provided does not match "
|
|
|
|
message += "the resumed string. "
|
|
|
|
|
|
|
|
message += "Do you want to use the resumed string "
|
|
|
|
message += "to be matched in page when the query "
|
|
|
|
message += "is valid? [Y/n] "
|
|
|
|
test = readInput(message, default="Y")
|
|
|
|
|
|
|
|
if not test or test[0] in ("y", "Y"):
|
|
|
|
conf.string = string
|
|
|
|
|
2008-12-12 22:06:31 +03:00
|
|
|
elif expression == "Regular expression" and url == conf.url:
|
2010-10-11 00:51:11 +04:00
|
|
|
regexp = unSafeFormatString(value[:-1])
|
2008-12-12 22:06:31 +03:00
|
|
|
|
2010-11-29 04:04:42 +03:00
|
|
|
logMsg = "resuming regular expression match '%s' from session file" % regexp
|
2008-12-12 22:06:31 +03:00
|
|
|
logger.info(logMsg)
|
|
|
|
|
|
|
|
if regexp and ( not conf.regexp or regexp != conf.regexp ):
|
|
|
|
if not conf.regexp:
|
|
|
|
message = "you did not provide any regular expression "
|
|
|
|
message += "to match. "
|
|
|
|
else:
|
|
|
|
message = "The regular expression you provided does not "
|
|
|
|
message += "match the resumed regular expression. "
|
|
|
|
|
|
|
|
message += "Do you want to use the resumed regular expression "
|
|
|
|
message += "to be matched in page when the query "
|
|
|
|
message += "is valid? [Y/n] "
|
|
|
|
test = readInput(message, default="Y")
|
|
|
|
|
|
|
|
if not test or test[0] in ("y", "Y"):
|
|
|
|
conf.regexp = regexp
|
|
|
|
|
2010-08-10 23:57:59 +04:00
|
|
|
elif expression == "Match ratio" and url == conf.url and conf.matchRatio is None:
|
2009-04-22 15:48:07 +04:00
|
|
|
matchRatio = value[:-1]
|
|
|
|
|
2010-11-29 04:04:42 +03:00
|
|
|
logMsg = "resuming match ratio '%s' from session file" % matchRatio
|
2009-04-22 15:48:07 +04:00
|
|
|
logger.info(logMsg)
|
|
|
|
|
2010-11-19 12:02:44 +03:00
|
|
|
try:
|
2010-11-18 17:32:52 +03:00
|
|
|
conf.matchRatio = round(float(matchRatio), 3)
|
2010-11-19 12:02:44 +03:00
|
|
|
except ValueError:
|
|
|
|
pass
|
2009-04-22 15:48:07 +04:00
|
|
|
|
2010-12-01 20:09:52 +03:00
|
|
|
elif expression == "Injection data" and url == conf.url:
|
|
|
|
injection = base64unpickle(value[:-1])
|
|
|
|
kb.injections.append(injection)
|
2010-11-29 04:04:42 +03:00
|
|
|
|
2010-12-03 13:51:27 +03:00
|
|
|
logMsg = "resuming injection data from session file"
|
2010-11-29 04:04:42 +03:00
|
|
|
logger.info(logMsg)
|
|
|
|
|
|
|
|
elif expression == "Boolean-based blind injection" and url == conf.url:
|
|
|
|
kb.booleanTest = unSafeFormatString(value[:-1])
|
|
|
|
|
|
|
|
logMsg = "resuming boolean-based blind injection "
|
|
|
|
logMsg += "'%s' from session file" % kb.booleanTest
|
|
|
|
logger.info(logMsg)
|
|
|
|
|
|
|
|
elif expression == "Error-based injection" and url == conf.url:
|
|
|
|
kb.errorTest = unSafeFormatString(value[:-1])
|
|
|
|
|
|
|
|
logMsg = "resuming error-based injection "
|
|
|
|
logMsg += "'%s' from session file" % kb.errorTest
|
|
|
|
logger.info(logMsg)
|
|
|
|
|
|
|
|
elif expression == "Stacked queries" and url == conf.url:
|
|
|
|
kb.stackedTest = unSafeFormatString(value[:-1])
|
|
|
|
|
|
|
|
logMsg = "resuming stacked queries syntax "
|
|
|
|
logMsg += "'%s' from session file" % kb.stackedTest
|
|
|
|
logger.info(logMsg)
|
|
|
|
|
|
|
|
elif expression == "Time-based blind injection" and url == conf.url:
|
|
|
|
kb.timeTest = unSafeFormatString(value[:-1])
|
|
|
|
|
|
|
|
logMsg = "resuming time-based blind injection "
|
|
|
|
logMsg += "'%s' from session file" % kb.timeTest
|
2008-10-15 19:38:22 +04:00
|
|
|
logger.info(logMsg)
|
|
|
|
|
|
|
|
elif expression == "DBMS" and url == conf.url:
|
2010-10-11 00:51:11 +04:00
|
|
|
dbms = unSafeFormatString(value[:-1])
|
2009-07-09 15:05:24 +04:00
|
|
|
dbms = dbms.lower()
|
|
|
|
dbmsVersion = None
|
2008-10-15 19:38:22 +04:00
|
|
|
|
2010-11-29 04:04:42 +03:00
|
|
|
logMsg = "resuming back-end DBMS '%s' " % dbms
|
2008-10-15 19:38:22 +04:00
|
|
|
logMsg += "from session file"
|
|
|
|
logger.info(logMsg)
|
|
|
|
|
2009-07-09 15:05:24 +04:00
|
|
|
firstRegExp = "(%s|%s|%s|%s)" % ("|".join([alias for alias in MSSQL_ALIASES]),
|
|
|
|
"|".join([alias for alias in MYSQL_ALIASES]),
|
|
|
|
"|".join([alias for alias in PGSQL_ALIASES]),
|
|
|
|
"|".join([alias for alias in ORACLE_ALIASES]))
|
2008-10-15 19:38:22 +04:00
|
|
|
dbmsRegExp = re.search("%s ([\d\.]+)" % firstRegExp, dbms)
|
|
|
|
|
|
|
|
if dbmsRegExp:
|
2009-07-09 15:05:24 +04:00
|
|
|
dbms = dbmsRegExp.group(1)
|
|
|
|
dbmsVersion = [ dbmsRegExp.group(2) ]
|
2008-10-15 19:38:22 +04:00
|
|
|
|
|
|
|
if conf.dbms and conf.dbms.lower() != dbms:
|
|
|
|
message = "you provided '%s' as back-end DBMS, " % conf.dbms
|
|
|
|
message += "but from a past scan information on the target URL "
|
|
|
|
message += "sqlmap assumes the back-end DBMS is %s. " % dbms
|
|
|
|
message += "Do you really want to force the back-end "
|
|
|
|
message += "DBMS value? [y/N] "
|
|
|
|
test = readInput(message, default="N")
|
|
|
|
|
|
|
|
if not test or test[0] in ("n", "N"):
|
2010-12-04 01:44:29 +03:00
|
|
|
kb.dbms = aliasToDbmsEnum(dbms)
|
2009-07-09 15:05:24 +04:00
|
|
|
kb.dbmsVersion = dbmsVersion
|
2008-10-15 19:38:22 +04:00
|
|
|
else:
|
2010-12-04 01:44:29 +03:00
|
|
|
kb.dbms = aliasToDbmsEnum(dbms)
|
2009-07-09 15:05:24 +04:00
|
|
|
kb.dbmsVersion = dbmsVersion
|
2008-10-15 19:38:22 +04:00
|
|
|
|
2009-04-22 15:48:07 +04:00
|
|
|
elif expression == "OS" and url == conf.url:
|
2010-10-11 00:51:11 +04:00
|
|
|
os = unSafeFormatString(value[:-1])
|
2009-04-22 15:48:07 +04:00
|
|
|
|
2010-11-29 04:04:42 +03:00
|
|
|
logMsg = "resuming back-end DBMS operating system '%s' " % os
|
2009-04-22 15:48:07 +04:00
|
|
|
logMsg += "from session file"
|
|
|
|
logger.info(logMsg)
|
|
|
|
|
|
|
|
if conf.os and conf.os.lower() != os.lower():
|
|
|
|
message = "you provided '%s' as back-end DBMS operating " % conf.os
|
|
|
|
message += "system, but from a past scan information on the "
|
|
|
|
message += "target URL sqlmap assumes the back-end DBMS "
|
|
|
|
message += "operating system is %s. " % os
|
|
|
|
message += "Do you really want to force the back-end DBMS "
|
|
|
|
message += "OS value? [y/N] "
|
|
|
|
test = readInput(message, default="N")
|
|
|
|
|
|
|
|
if not test or test[0] in ("n", "N"):
|
|
|
|
conf.os = os
|
|
|
|
else:
|
|
|
|
conf.os = os
|
|
|
|
|
2008-10-15 19:38:22 +04:00
|
|
|
elif expression == "Union comment" and url == conf.url:
|
2010-10-11 00:51:11 +04:00
|
|
|
kb.unionComment = unSafeFormatString(value[:-1])
|
2008-10-15 19:38:22 +04:00
|
|
|
|
2010-11-29 04:04:42 +03:00
|
|
|
logMsg = "resuming union comment "
|
2008-10-15 19:38:22 +04:00
|
|
|
logMsg += "'%s' from session file" % kb.unionComment
|
|
|
|
logger.info(logMsg)
|
|
|
|
|
|
|
|
elif expression == "Union count" and url == conf.url:
|
|
|
|
kb.unionCount = int(value[:-1])
|
|
|
|
|
2010-11-29 04:04:42 +03:00
|
|
|
logMsg = "resuming union count "
|
2008-10-15 19:38:22 +04:00
|
|
|
logMsg += "%s from session file" % kb.unionCount
|
|
|
|
logger.info(logMsg)
|
|
|
|
|
|
|
|
elif expression == "Union position" and url == conf.url:
|
|
|
|
kb.unionPosition = int(value[:-1])
|
|
|
|
|
2010-11-29 04:04:42 +03:00
|
|
|
logMsg = "resuming union position "
|
2008-10-15 19:38:22 +04:00
|
|
|
logMsg += "%s from session file" % kb.unionPosition
|
|
|
|
logger.info(logMsg)
|
2009-04-22 15:48:07 +04:00
|
|
|
|
2010-03-22 18:39:29 +03:00
|
|
|
elif expression == "Union negative" and url == conf.url:
|
|
|
|
kb.unionNegative = True if value[:-1] == "Yes" else False
|
|
|
|
|
2010-11-18 20:55:43 +03:00
|
|
|
logMsg = "resuming union negative from session file"
|
2010-03-22 18:39:29 +03:00
|
|
|
logger.info(logMsg)
|
|
|
|
|
|
|
|
elif expression == "Union false condition" and url == conf.url:
|
|
|
|
kb.unionFalseCond = True if value[:-1] == "Yes" else False
|
|
|
|
|
2010-11-18 20:55:43 +03:00
|
|
|
logMsg = "resuming union false condition from session file"
|
2010-03-22 18:39:29 +03:00
|
|
|
logger.info(logMsg)
|
|
|
|
|
2010-12-01 13:59:58 +03:00
|
|
|
elif expression == "Union char" and url == conf.url:
|
|
|
|
conf.uChar = value[:-1]
|
|
|
|
|
|
|
|
logMsg = "resuming union char %s from session file" % conf.uChar
|
|
|
|
logger.info(logMsg)
|
|
|
|
|
2010-11-14 02:24:41 +03:00
|
|
|
elif expression == "Union payload" and url == conf.url:
|
|
|
|
kb.unionTest = value[:-1]
|
|
|
|
|
2010-11-29 04:04:42 +03:00
|
|
|
logMsg = "resuming union payload "
|
2010-11-14 02:24:41 +03:00
|
|
|
logMsg += "%s from session file" % kb.unionTest
|
|
|
|
logger.info(logMsg)
|
|
|
|
|
2009-04-22 15:48:07 +04:00
|
|
|
elif expression == "Remote temp path" and url == conf.url:
|
2010-10-11 00:51:11 +04:00
|
|
|
conf.tmpPath = unSafeFormatString(value[:-1])
|
2009-04-22 15:48:07 +04:00
|
|
|
|
2010-11-29 04:04:42 +03:00
|
|
|
logMsg = "resuming remote absolute path of temporary "
|
2009-04-22 15:48:07 +04:00
|
|
|
logMsg += "files directory '%s' from session file" % conf.tmpPath
|
|
|
|
logger.info(logMsg)
|