mirror of
https://github.com/sqlmapproject/sqlmap.git
synced 2025-12-06 04:31:30 +00:00
lots of refactoring regarding removal of already obsolete session file mechanism
This commit is contained in:
@@ -11,7 +11,7 @@ import re
|
||||
|
||||
from lib.core.common import Backend
|
||||
from lib.core.common import Format
|
||||
from lib.core.common import dataToSessionFile
|
||||
from lib.core.common import hashDBWrite
|
||||
from lib.core.common import intersect
|
||||
from lib.core.common import readInput
|
||||
from lib.core.common import singleTimeWarnMessage
|
||||
@@ -20,42 +20,25 @@ from lib.core.convert import base64unpickle
|
||||
from lib.core.data import conf
|
||||
from lib.core.data import kb
|
||||
from lib.core.data import logger
|
||||
from lib.core.enums import HASHDB_KEYS
|
||||
from lib.core.enums import OS
|
||||
from lib.core.settings import SUPPORTED_DBMS
|
||||
from lib.core.settings import UNKNOWN_DBMS_VERSION
|
||||
|
||||
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
|
||||
|
||||
def setDbms(dbms):
|
||||
"""
|
||||
@param dbms: database management system to be set into the knowledge
|
||||
base as fingerprint.
|
||||
@type dbms: C{str}
|
||||
"""
|
||||
condition = (
|
||||
not kb.resumedQueries
|
||||
or ( kb.resumedQueries.has_key(conf.url) and
|
||||
not kb.resumedQueries[conf.url].has_key("DBMS") )
|
||||
)
|
||||
|
||||
if condition:
|
||||
dataToSessionFile("[%s][%s][%s][DBMS][%s]\n" % (conf.url, kb.injection.place, safeFormatString(conf.parameters[kb.injection.place]), safeFormatString(dbms)))
|
||||
hashDBWrite(HASHDB_KEYS.DBMS, dbms)
|
||||
|
||||
firstRegExp = "(%s)" % ("|".join([alias for alias in SUPPORTED_DBMS]))
|
||||
dbmsRegExp = re.search("^%s" % firstRegExp, dbms, re.I)
|
||||
_ = "(%s)" % ("|".join([alias for alias in SUPPORTED_DBMS]))
|
||||
_ = re.search("^%s" % _, dbms, re.I)
|
||||
|
||||
if dbmsRegExp:
|
||||
dbms = dbmsRegExp.group(1)
|
||||
if _:
|
||||
dbms = _.group(1)
|
||||
|
||||
Backend.setDbms(dbms)
|
||||
|
||||
@@ -76,11 +59,6 @@ def setOs():
|
||||
"""
|
||||
|
||||
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
|
||||
@@ -105,82 +83,4 @@ def setOs():
|
||||
if infoMsg:
|
||||
logger.info(infoMsg)
|
||||
|
||||
if condition:
|
||||
dataToSessionFile("[%s][%s][%s][OS][%s]\n" % (conf.url, kb.injection.place, safeFormatString(conf.parameters[kb.injection.place]), Backend.getOs()))
|
||||
|
||||
def resumeConfKb(expression, url, value):
|
||||
if expression == "Dynamic markings" and url == conf.url:
|
||||
kb.dynamicMarkings = base64unpickle(value[:-1])
|
||||
infoMsg = "resuming dynamic markings from session file"
|
||||
logger.info(infoMsg)
|
||||
|
||||
elif expression == "DBMS" and url == conf.url:
|
||||
dbms = unSafeFormatString(value[:-1])
|
||||
dbms = dbms.lower()
|
||||
dbmsVersion = [UNKNOWN_DBMS_VERSION]
|
||||
|
||||
firstRegExp = "(%s)" % ("|".join([alias for alias in SUPPORTED_DBMS]))
|
||||
dbmsRegExp = re.search("%s ([\d\.]+)" % firstRegExp, dbms)
|
||||
|
||||
if dbmsRegExp:
|
||||
dbms = dbmsRegExp.group(1)
|
||||
dbmsVersion = [ dbmsRegExp.group(2) ]
|
||||
|
||||
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"):
|
||||
conf.dbms = None
|
||||
Backend.setDbms(dbms)
|
||||
Backend.setVersionList(dbmsVersion)
|
||||
else:
|
||||
infoMsg = "resuming back-end DBMS '%s' " % dbms
|
||||
infoMsg += "from session file"
|
||||
logger.info(infoMsg)
|
||||
|
||||
Backend.setDbms(dbms)
|
||||
Backend.setVersionList(dbmsVersion)
|
||||
|
||||
elif expression == "OS" and url == conf.url:
|
||||
os = unSafeFormatString(value[:-1])
|
||||
|
||||
if os and os != 'None':
|
||||
infoMsg = "resuming back-end DBMS operating system '%s' " % os
|
||||
infoMsg += "from session file"
|
||||
logger.info(infoMsg)
|
||||
|
||||
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
|
||||
|
||||
Backend.setOs(conf.os)
|
||||
|
||||
elif expression == "Remote temp path" and url == conf.url and conf.tmpPath is None:
|
||||
conf.tmpPath = unSafeFormatString(value[:-1])
|
||||
|
||||
infoMsg = "resuming remote absolute path of temporary "
|
||||
infoMsg += "files directory '%s' from session file" % conf.tmpPath
|
||||
logger.info(infoMsg)
|
||||
|
||||
elif conf.freshQueries:
|
||||
pass
|
||||
|
||||
elif expression == "xp_cmdshell availability" and url == conf.url:
|
||||
kb.xpCmdshellAvailable = True if unSafeFormatString(value[:-1]).lower() == "true" else False
|
||||
infoMsg = "resuming xp_cmdshell availability"
|
||||
logger.info(infoMsg)
|
||||
hashDBWrite(HASHDB_KEYS.OS, Backend.getOs())
|
||||
|
||||
Reference in New Issue
Block a user