From 744636a8c1f7c7c2ac4acd6a509bf8a2da2f4f06 Mon Sep 17 00:00:00 2001 From: Miroslav Stampar Date: Sun, 25 Sep 2011 20:36:32 +0000 Subject: [PATCH] switching to SQLite resume support (on error and union techniques this moment) --- lib/core/option.py | 2 + lib/core/target.py | 10 +++ lib/techniques/error/use.py | 135 ++++++++++++++++++------------------ lib/techniques/union/use.py | 101 ++++++++++++++------------- lib/utils/hashdb.py | 63 +++++++++++++++++ 5 files changed, 197 insertions(+), 114 deletions(-) create mode 100644 lib/utils/hashdb.py diff --git a/lib/core/option.py b/lib/core/option.py index 207fee01eee..493cddc4517 100644 --- a/lib/core/option.py +++ b/lib/core/option.py @@ -1360,6 +1360,8 @@ def __setConfAttributes(): conf.dbmsConnector = None conf.dbmsHandler = None conf.dumpPath = None + conf.hashDB = None + conf.hashDBFile = None conf.httpHeaders = [] conf.hostname = None conf.multipleTargets = False diff --git a/lib/core/target.py b/lib/core/target.py index c09dab81e43..4a454c7b2e5 100644 --- a/lib/core/target.py +++ b/lib/core/target.py @@ -40,6 +40,7 @@ from lib.core.settings import URI_INJECTABLE_REGEX from lib.core.settings import URI_INJECTION_MARK_CHAR from lib.core.settings import USER_AGENT_ALIASES +from lib.utils.hashdb import HashDB from lib.core.xmldump import dumper as xmldumper from lib.request.connect import Connect as Request @@ -174,6 +175,9 @@ def __setOutputResume(): if not conf.sessionFile: conf.sessionFile = "%s%ssession" % (conf.outputPath, os.sep) + if not conf.hashDBFile: + conf.hashDBFile = "%s%shashdb" % (conf.outputPath, os.sep) + logger.info("using '%s' as session file" % conf.sessionFile) if os.path.exists(conf.sessionFile): @@ -223,6 +227,7 @@ def __setOutputResume(): else: try: os.remove(conf.sessionFile) + os.remove(conf.hashDBFile) logger.info("flushing session file") except OSError, msg: errMsg = "unable to flush the session file (%s)" % msg @@ -230,6 +235,7 @@ def __setOutputResume(): try: conf.sessionFP = codecs.open(conf.sessionFile, "a", UNICODE_ENCODING) + conf.hashDB = HashDB(conf.hashDBFile) dataToSessionFile("\n[%s]\n" % time.strftime("%X %x")) except IOError: errMsg = "unable to write on the session file specified" @@ -338,12 +344,16 @@ def initTargetEnv(): if conf.sessionFP: conf.sessionFP.close() + if conf.hashDB: + conf.hashDB.close() + if conf.cj: conf.cj.clear() conf.paramDict = {} conf.parameters = {} conf.sessionFile = None + conf.hashDBFile = None __setKnowledgeBaseAttributes(False) __restoreCmdLineOptions() diff --git a/lib/techniques/error/use.py b/lib/techniques/error/use.py index f43dbbc2150..0e03465736b 100644 --- a/lib/techniques/error/use.py +++ b/lib/techniques/error/use.py @@ -53,83 +53,86 @@ def __oneShotErrorUse(expression, field): threadData = getCurrentThreadData() - retVal = None + retVal = conf.hashDB.retrieve(expression) if not conf.freshQueries else None + offset = 1 chunk_length = None - while True: - check = "%s(?P.*?)%s" % (kb.misc.start, kb.misc.stop) - trimcheck = "%s(?P.*?).*?)%s" % (kb.misc.start, kb.misc.stop) + trimcheck = "%s(?P.*?)= chunk_length: - offset += chunk_length + if output and len(output) >= chunk_length: + offset += chunk_length + else: + break else: + retVal = output break - else: - retVal = output - break - if isinstance(retVal, basestring): - retVal = htmlunescape(retVal).replace("
", "\n") + if isinstance(retVal, basestring): + retVal = htmlunescape(retVal).replace("
", "\n") - retVal = __errorReplaceChars(retVal) + retVal = __errorReplaceChars(retVal) - dataToSessionFile("[%s][%s][%s][%s][%s]\n" % (conf.url, kb.injection.place, conf.parameters[kb.injection.place], expression, replaceNewlineTabs(retVal))) + #dataToSessionFile("[%s][%s][%s][%s][%s]\n" % (conf.url, kb.injection.place, conf.parameters[kb.injection.place], expression, replaceNewlineTabs(retVal))) + conf.hashDB.write(expression, retVal) return safecharencode(retVal) if kb.safeCharEncode else retVal diff --git a/lib/techniques/union/use.py b/lib/techniques/union/use.py index 1eb3fba8f9d..6dd72afe0b1 100644 --- a/lib/techniques/union/use.py +++ b/lib/techniques/union/use.py @@ -50,54 +50,59 @@ def __oneShotUnionUse(expression, unpack=True, limited=False): global reqCount - check = "(?P%s.*%s)" % (kb.misc.start, kb.misc.stop) - trimcheck = "%s(?P.*?)%s.*%s)" % (kb.misc.start, kb.misc.stop) + trimcheck = "%s(?P.*?)