From 5269cb8c08d90607ac92c59d641dcd24ba52b888 Mon Sep 17 00:00:00 2001 From: Miroslav Stampar Date: Tue, 2 Nov 2010 09:06:38 +0000 Subject: [PATCH] some code refactoring and beautification --- lib/core/common.py | 4 ++-- lib/core/option.py | 7 +++++-- lib/request/comparison.py | 8 ++++---- lib/techniques/blind/inference.py | 4 ++-- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/lib/core/common.py b/lib/core/common.py index 48a7fc338..104c9fbaf 100644 --- a/lib/core/common.py +++ b/lib/core/common.py @@ -1245,7 +1245,7 @@ def parseXmlFile(xmlFile, handler): def readCachedFileContent(filename, mode='rb'): if filename not in kb.cache.content: - kb.data.cacheLock.acquire() + kb.locks.cacheLock.acquire() if filename not in kb.cache.content: checkFile(filename) @@ -1254,7 +1254,7 @@ def readCachedFileContent(filename, mode='rb'): kb.cache.content[filename] = content xfile.close() - kb.data.cacheLock.release() + kb.locks.cacheLock.release() return kb.cache.content[filename] diff --git a/lib/core/option.py b/lib/core/option.py index 8c0e9a656..108c4d85a 100644 --- a/lib/core/option.py +++ b/lib/core/option.py @@ -1028,8 +1028,6 @@ def __setKnowledgeBaseAttributes(): kb.commonOutputs = None kb.data = advancedDict() - kb.data.cacheLock = threading.Lock() - kb.data.seqLock = None # Basic back-end DBMS fingerprint kb.dbms = None @@ -1053,6 +1051,11 @@ def __setKnowledgeBaseAttributes(): kb.keywords = set(getFileItems(paths.SQL_KEYWORDS)) kb.lastErrorPage = None kb.lastRequestUID = 0 + + kb.locks = advancedDict() + kb.locks.cacheLock = threading.Lock() + kb.locks.seqLock = None + kb.nullConnection = None # Back-end DBMS underlying operating system fingerprint via banner (-b) diff --git a/lib/request/comparison.py b/lib/request/comparison.py index 61e294ec2..5a4e311bd 100644 --- a/lib/request/comparison.py +++ b/lib/request/comparison.py @@ -58,8 +58,8 @@ def comparison(page, headers=None, getSeqMatcher=False, pageLength=None): else: page = re.sub('(?s)%s.+%s' % (prefix, postfix), '%s%s' % (prefix, postfix), page) - if kb.data.seqLock: - kb.data.seqLock.acquire() + if kb.locks.seqLock: + kb.locks.seqLock.acquire() if not conf.eRegexp and not conf.eString and kb.nullConnection: ratio = 1. * pageLength / len(conf.seqMatcher.a) @@ -69,8 +69,8 @@ def comparison(page, headers=None, getSeqMatcher=False, pageLength=None): conf.seqMatcher.set_seq2(page if not conf.textOnly else getFilteredPageContent(page)) ratio = round(conf.seqMatcher.ratio(), 3) - if kb.data.seqLock: - kb.data.seqLock.release() + if kb.locks.seqLock: + kb.locks.seqLock.release() # If the url is stable and we did not set yet the match ratio and the # current injected value changes the url page content diff --git a/lib/techniques/blind/inference.py b/lib/techniques/blind/inference.py index 7e7a54a82..baf2b68ec 100644 --- a/lib/techniques/blind/inference.py +++ b/lib/techniques/blind/inference.py @@ -251,7 +251,7 @@ def bisection(payload, expression, length=None, charsetType=None, firstChar=None idxlock = threading.Lock() iolock = threading.Lock() valuelock = threading.Lock() - kb.data.seqLock = threading.Lock() + kb.locks.seqLock = threading.Lock() conf.threadContinue = True def downloadThread(): @@ -415,7 +415,7 @@ def bisection(payload, expression, length=None, charsetType=None, firstChar=None if conf.verbose >= 1 and not showEta and infoMsg: dataToStdout(infoMsg) - kb.data.seqLock = None + kb.locks.seqLock = None # No multi-threading (--threads = 1) else: