From 58d54b6515b57871f9756dd9660ccc50c994b0ec Mon Sep 17 00:00:00 2001 From: Miroslav Stampar Date: Thu, 4 Mar 2010 13:01:18 +0000 Subject: [PATCH] added new option --flush-session --- lib/core/optiondict.py | 1 + lib/core/target.py | 80 +++++++++++++++++++--------------- lib/parse/cmdline.py | 3 ++ plugins/generic/enumeration.py | 1 - sqlmap.conf | 4 ++ 5 files changed, 52 insertions(+), 37 deletions(-) diff --git a/lib/core/optiondict.py b/lib/core/optiondict.py index 278700e6d..c2e034f90 100644 --- a/lib/core/optiondict.py +++ b/lib/core/optiondict.py @@ -139,6 +139,7 @@ optDict = { "Miscellaneous": { "sessionFile": "string", + "flushSession": "boolean", "eta": "boolean", "googlePage": "integer", "updateAll": "boolean", diff --git a/lib/core/target.py b/lib/core/target.py index e16e0185d..19ccbf9f4 100644 --- a/lib/core/target.py +++ b/lib/core/target.py @@ -117,42 +117,50 @@ def __setOutputResume(): logger.info("using '%s' as session file" % conf.sessionFile) if os.path.exists(conf.sessionFile): - readSessionFP = open(conf.sessionFile, "r") - lines = readSessionFP.readlines() - - for line in lines: - if line.count("][") == 4: - line = line.split("][") - - if len(line) != 5: - continue - - url, _, _, expression, value = line - - if not value: - continue - - if url[0] == "[": - url = url[1:] - - if value[-1] == "\n": - value = value[:-1] - - if url != conf.url: - continue - - if url not in kb.resumedQueries.keys(): - kb.resumedQueries[url] = {} - kb.resumedQueries[url][expression] = value - - resumeConfKb(expression, url, value) - - if expression not in kb.resumedQueries[url].keys(): - kb.resumedQueries[url][expression] = value - elif len(value) >= len(kb.resumedQueries[url][expression]): - kb.resumedQueries[url][expression] = value - - readSessionFP.close() + if not conf.flushSession: + readSessionFP = open(conf.sessionFile, "r") + lines = readSessionFP.readlines() + + for line in lines: + if line.count("][") == 4: + line = line.split("][") + + if len(line) != 5: + continue + + url, _, _, expression, value = line + + if not value: + continue + + if url[0] == "[": + url = url[1:] + + if value[-1] == "\n": + value = value[:-1] + + if url != conf.url: + continue + + if url not in kb.resumedQueries.keys(): + kb.resumedQueries[url] = {} + kb.resumedQueries[url][expression] = value + + resumeConfKb(expression, url, value) + + if expression not in kb.resumedQueries[url].keys(): + kb.resumedQueries[url][expression] = value + elif len(value) >= len(kb.resumedQueries[url][expression]): + kb.resumedQueries[url][expression] = value + + readSessionFP.close() + else: + try: + os.remove(conf.sessionFile) + logger.info("flushing session file") + except OSError, msg: + errMsg = "unable to flush the session file (%s)" % msg + raise sqlmapFilePathException, errMsg try: conf.sessionFP = open(conf.sessionFile, "a") diff --git a/lib/parse/cmdline.py b/lib/parse/cmdline.py index 91975ef68..7b1dde42f 100644 --- a/lib/parse/cmdline.py +++ b/lib/parse/cmdline.py @@ -397,6 +397,9 @@ def cmdLineParser(): help="Save and resume all data retrieved " "on a session file") + miscellaneous.add_option("--flush-session", dest="flushSession", action="store_true", + help="Flush session file for current target") + miscellaneous.add_option("--eta", dest="eta", action="store_true", help="Display for each output the " "estimated time of arrival") diff --git a/plugins/generic/enumeration.py b/plugins/generic/enumeration.py index fead5f8f0..998ddb145 100644 --- a/plugins/generic/enumeration.py +++ b/plugins/generic/enumeration.py @@ -103,7 +103,6 @@ class Enumeration: infoMsg = "fetching banner" logger.info(infoMsg) - if not kb.data.banner: if conf.unionUse or conf.unionTest: dumper.string("valid union", unionTest()) diff --git a/sqlmap.conf b/sqlmap.conf index 8e6dfb82f..610008ed5 100644 --- a/sqlmap.conf +++ b/sqlmap.conf @@ -398,6 +398,10 @@ regType = # Save and resume all data retrieved on a session file. sessionFile = + +# Flush session file for current target. +flushSession = False + # Retrieve each query output length and calculate the estimated time of # arrival in real time. # Valid: True or False