From 1151af52bb552173f79058d1d2cea40ee1c6a29d Mon Sep 17 00:00:00 2001 From: Bernardo Damele Date: Sat, 7 May 2011 21:08:14 +0000 Subject: [PATCH] More fix for save/resume of --technique --- lib/controller/checks.py | 16 ++++++---------- lib/controller/controller.py | 17 ++++++----------- lib/core/session.py | 26 ++++++++++++++++++++++++-- 3 files changed, 36 insertions(+), 23 deletions(-) diff --git a/lib/controller/checks.py b/lib/controller/checks.py index 925d46ed4..f1abb90d2 100644 --- a/lib/controller/checks.py +++ b/lib/controller/checks.py @@ -203,17 +203,13 @@ def checkSqlInjection(place, parameter, value): logger.debug(debugMsg) continue - if len(kb.injections) > 0: - for resumedInj in kb.injections: - if resumedInj.place == place and resumedInj.parameter \ - == parameter and stype in resumedInj.data: - debugMsg = "skipping test '%s' because this " % title - debugMsg += "technique has already been detected " - debugMsg += "in a previous run" - logger.debug(debugMsg) + if len(kb.tested) > 0 and stype in kb.tested: + debugMsg = "skipping test '%s' because this " % title + debugMsg += "technique has already been detected " + debugMsg += "in a previous run" + logger.debug(debugMsg) - proceed = False - break + proceed = False if not proceed: continue diff --git a/lib/controller/controller.py b/lib/controller/controller.py index 1a4e7c459..31fa5e5cc 100644 --- a/lib/controller/controller.py +++ b/lib/controller/controller.py @@ -43,6 +43,7 @@ from lib.core.exception import sqlmapSilentQuitException from lib.core.exception import sqlmapValueException from lib.core.exception import sqlmapUserQuitException from lib.core.session import setInjection +from lib.core.session import setTestedTechniques from lib.core.settings import EMPTY_FORM_FIELDS_REGEX from lib.core.settings import IGNORE_PARAMETERS from lib.core.settings import REFERER_ALIASES @@ -317,18 +318,10 @@ def start(): # TODO: consider the following line in __setRequestParams() # __testableParameters = True - proceed = False + if len(kb.tested) > 0 and kb.tested == conf.tech: + testSqlInj = False - if len(kb.injections) > 0: - for resumedInj in kb.injections: - for tech in conf.tech: - if tech not in resumedInj.data: - proceed = True - break - else: - proceed = True - - if proceed: + if testSqlInj: if not conf.string and not conf.regexp: # NOTE: this is not needed anymore, leaving only to display # a warning message to the user in case the page is not stable @@ -436,6 +429,8 @@ def start(): warnMsg += "injectable" logger.warn(warnMsg) + setTestedTechniques() + if len(kb.injections) == 0 or (len(kb.injections) == 1 and kb.injections[0].place is None): if not conf.realTest: errMsg = "all parameters are not injectable." diff --git a/lib/core/session.py b/lib/core/session.py index ec5d7524c..0e05510d3 100644 --- a/lib/core/session.py +++ b/lib/core/session.py @@ -41,6 +41,23 @@ def unSafeFormatString(value): retVal = retVal.replace("__LEFT_SQUARE_BRACKET__", "[").replace("__RIGHT_SQUARE_BRACKET__", "]") return retVal +def setTestedTechniques(): + """ + Save information retrieved about dynamic markings to the + session file. + """ + + condition = ( + ( not kb.resumedQueries + or ( kb.resumedQueries.has_key(conf.url) and + not kb.resumedQueries[conf.url].has_key("Tested techniques")) ) + or ( kb.resumedQueries[conf.url].has_key("Tested techniques") + and base64unpickle(kb.resumedQueries[conf.url]["Tested techniques"][:-1]) != conf.tech + ) ) + + if condition: + dataToSessionFile("[%s][%s][%s][Tested techniques][%s]\n" % (conf.url, None, None, base64pickle(conf.tech))) + def setInjection(inj): """ Save information retrieved about injection place and parameter in the @@ -51,7 +68,7 @@ def setInjection(inj): or ( kb.resumedQueries.has_key(conf.url) and not kb.resumedQueries[conf.url].has_key("Injection data")) or ( kb.resumedQueries[conf.url].has_key("Injection data") - and intersect(base64unpickle(kb.resumedQueries[conf.url]["Injection data"][:-1]).data.keys(),\ + and intersect(base64unpickle(kb.resumedQueries[conf.url]["Injection data"][:-1]).data.keys(), \ inj.data.keys()) != inj.data.keys() ) ) @@ -165,7 +182,12 @@ def setXpCmdshellAvailability(available): dataToSessionFile("[%s][%s][%s][xp_cmdshell availability][%s]\n" % (conf.url, kb.injection.place, safeFormatString(conf.parameters[kb.injection.place]), str(available).lower())) def resumeConfKb(expression, url, value): - if expression == "Injection data" and url == conf.url: + if expression == "Tested techniques" and url == conf.url: + kb.tested.extend(base64unpickle(value[:-1])) + kb.tested = list(set(kb.tested)) + kb.tested.sort() + + elif expression == "Injection data" and url == conf.url: injection = base64unpickle(value[:-1]) if injection.place in conf.paramDict and \