From c2c4601d6e47204423e42b5d5f5c3ac564e1f8c2 Mon Sep 17 00:00:00 2001 From: Miroslav Stampar Date: Thu, 20 Dec 2012 11:06:52 +0100 Subject: [PATCH] Minor restyling --- lib/core/option.py | 2 +- lib/techniques/brute/use.py | 18 +++++++++--------- lib/techniques/error/use.py | 38 ++++++++++++++++++------------------- lib/techniques/union/use.py | 2 +- lib/utils/crawler.py | 12 ++++++------ 5 files changed, 36 insertions(+), 36 deletions(-) diff --git a/lib/core/option.py b/lib/core/option.py index 1f70bedb4..678fdea37 100644 --- a/lib/core/option.py +++ b/lib/core/option.py @@ -1538,7 +1538,7 @@ def _setKnowledgeBaseAttributes(flushAll=True): kb.lastParserStatus = None kb.locks = AttribDict() - for _ in ("cache", "count", "index", "io", "limits", "log", "outputs", "value"): + for _ in ("cache", "count", "index", "io", "limit", "log", "value"): kb.locks[_] = threading.Lock() kb.matchRatio = None diff --git a/lib/techniques/brute/use.py b/lib/techniques/brute/use.py index c605200d6..8375eb143 100644 --- a/lib/techniques/brute/use.py +++ b/lib/techniques/brute/use.py @@ -66,7 +66,7 @@ def tableExists(tableFile, regex=None): threadData = getCurrentThreadData() threadData.shared.count = 0 threadData.shared.limit = len(tables) - threadData.shared.outputs = [] + threadData.shared.values = [] threadData.shared.unique = set() def tableExistsThread(): @@ -92,7 +92,7 @@ def tableExists(tableFile, regex=None): kb.locks.io.acquire() if result and table.lower() not in threadData.shared.unique: - threadData.shared.outputs.append(table) + threadData.shared.values.append(table) threadData.shared.unique.add(table.lower()) if conf.verbose in (1, 2): @@ -117,17 +117,17 @@ def tableExists(tableFile, regex=None): clearConsoleLine(True) dataToStdout("\n") - if not threadData.shared.outputs: + if not threadData.shared.values: warnMsg = "no table(s) found" logger.warn(warnMsg) else: - for item in threadData.shared.outputs: + for item in threadData.shared.values: if conf.db not in kb.data.cachedTables: kb.data.cachedTables[conf.db] = [item] else: kb.data.cachedTables[conf.db].append(item) - for _ in map(lambda x: (conf.db, x), threadData.shared.outputs): + for _ in map(lambda x: (conf.db, x), threadData.shared.values): if _ not in kb.brute.tables: kb.brute.tables.append(_) @@ -164,7 +164,7 @@ def columnExists(columnFile, regex=None): threadData = getCurrentThreadData() threadData.shared.count = 0 threadData.shared.limit = len(columns) - threadData.shared.outputs = [] + threadData.shared.values = [] def columnExistsThread(): threadData = getCurrentThreadData() @@ -184,7 +184,7 @@ def columnExists(columnFile, regex=None): kb.locks.io.acquire() if result: - threadData.shared.outputs.append(column) + threadData.shared.values.append(column) if conf.verbose in (1, 2): clearConsoleLine(True) @@ -208,13 +208,13 @@ def columnExists(columnFile, regex=None): clearConsoleLine(True) dataToStdout("\n") - if not threadData.shared.outputs: + if not threadData.shared.values: warnMsg = "no column(s) found" logger.warn(warnMsg) else: columns = {} - for column in threadData.shared.outputs: + for column in threadData.shared.values: result = inject.checkBooleanExpression("%s" % safeStringFormat("EXISTS(SELECT %s FROM %s WHERE ROUND(%s)=ROUND(%s))", (column, table, column, column))) if result: diff --git a/lib/techniques/error/use.py b/lib/techniques/error/use.py index 4d2e9e4d8..337a700b9 100644 --- a/lib/techniques/error/use.py +++ b/lib/techniques/error/use.py @@ -158,7 +158,7 @@ def _oneShotErrorUse(expression, field=None): return safecharencode(retVal) if kb.safeCharEncode else retVal def _errorFields(expression, expressionFields, expressionFieldsList, num=None, emptyFields=None): - outputs = [] + values = [] origExpr = None threadData = getCurrentThreadData() @@ -191,9 +191,9 @@ def _errorFields(expression, expressionFields, expressionFieldsList, num=None, e if isinstance(num, int): expression = origExpr - outputs.append(output) + values.append(output) - return outputs + return values def _errorReplaceChars(value): """ @@ -237,7 +237,7 @@ def errorUse(expression, dump=False): startLimit = 0 stopLimit = None output = None - outputs = None + value = None _, _, _, _, _, expressionFieldsList, expressionFields, _ = agent.getFields(expression) @@ -290,21 +290,21 @@ def errorUse(expression, dump=False): warnMsg += "return any output" logger.warn(warnMsg) else: - outputs = [] # for empty tables - return outputs + value = [] # for empty tables + return value if " ORDER BY " in expression and (stopLimit - startLimit) > SLOW_ORDER_COUNT_THRESHOLD: message = "due to huge table size do you want to remove " message += "ORDER BY clause gaining speed over consistency? [y/N] " - output = readInput(message, default="N") + _ = readInput(message, default="N") - if output and output[0] in ("y", "Y"): + if _ and _[0] in ("y", "Y"): expression = expression[:expression.index(" ORDER BY ")] threadData = getCurrentThreadData() threadData.shared.limits = iter(xrange(startLimit, stopLimit)) numThreads = min(conf.threads, (stopLimit - startLimit)) - threadData.shared.outputs = BigArray() + threadData.shared.value = BigArray() threadData.shared.buffered = [] threadData.shared.lastFlushed = startLimit - 1 @@ -327,7 +327,7 @@ def errorUse(expression, dump=False): threadData = getCurrentThreadData() while kb.threadContinue: - with kb.locks.limits: + with kb.locks.limit: try: num = threadData.shared.limits.next() except StopIteration: @@ -341,7 +341,7 @@ def errorUse(expression, dump=False): if output and isListLike(output) and len(output) == 1: output = output[0] - with kb.locks.outputs: + with kb.locks.value: index = None for index in xrange(len(threadData.shared.buffered)): if threadData.shared.buffered[index][0] >= num: @@ -349,7 +349,7 @@ def errorUse(expression, dump=False): threadData.shared.buffered.insert(index or 0, (num, output)) while threadData.shared.buffered and threadData.shared.lastFlushed + 1 == threadData.shared.buffered[0][0]: threadData.shared.lastFlushed += 1 - threadData.shared.outputs.append(threadData.shared.buffered[0][1]) + threadData.shared.value.append(threadData.shared.buffered[0][1]) del threadData.shared.buffered[0] runThreads(numThreads, errorThread) @@ -361,15 +361,15 @@ def errorUse(expression, dump=False): logger.warn(warnMsg) finally: - threadData.shared.outputs.extend(_[1] for _ in sorted(threadData.shared.buffered)) - outputs = threadData.shared.outputs + threadData.shared.value.extend(_[1] for _ in sorted(threadData.shared.buffered)) + value = threadData.shared.value kb.suppressResumeInfo = False - if not outputs and not abortedFlag: - outputs = _errorFields(expression, expressionFields, expressionFieldsList) + if not value and not abortedFlag: + value = _errorFields(expression, expressionFields, expressionFieldsList) - if outputs and isListLike(outputs) and len(outputs) == 1 and isinstance(outputs[0], basestring): - outputs = outputs[0] + if value and isListLike(value) and len(value) == 1 and isinstance(value[0], basestring): + value = value[0] duration = calculateDeltaSeconds(start) @@ -377,4 +377,4 @@ def errorUse(expression, dump=False): debugMsg = "performed %d queries in %d seconds" % (kb.counters[kb.technique], duration) logger.debug(debugMsg) - return outputs + return value diff --git a/lib/techniques/union/use.py b/lib/techniques/union/use.py index 85e810fd1..1706b291c 100644 --- a/lib/techniques/union/use.py +++ b/lib/techniques/union/use.py @@ -237,7 +237,7 @@ def unionUse(expression, unpack=True, dump=False): threadData = getCurrentThreadData() while kb.threadContinue: - with kb.locks.limits: + with kb.locks.limit: try: num = threadData.shared.limits.next() except StopIteration: diff --git a/lib/utils/crawler.py b/lib/utils/crawler.py index a31fdaf3c..d94b3209a 100644 --- a/lib/utils/crawler.py +++ b/lib/utils/crawler.py @@ -34,13 +34,13 @@ class Crawler(object): def getTargetUrls(self): try: threadData = getCurrentThreadData() - threadData.shared.outputs = oset() + threadData.shared.values = oset() def crawlThread(): threadData = getCurrentThreadData() while kb.threadContinue: - with kb.locks.limits: + with kb.locks.limit: if threadData.shared.unprocessed: current = threadData.shared.unprocessed.pop() else: @@ -79,10 +79,10 @@ class Crawler(object): continue if url.split('.')[-1].lower() not in CRAWL_EXCLUDE_EXTENSIONS: - with kb.locks.outputs: + with kb.locks.value: threadData.shared.deeper.add(url) if re.search(r"(.*?)\?(.+)", url): - threadData.shared.outputs.add(url) + threadData.shared.values.add(url) except UnicodeEncodeError: # for non-HTML files pass finally: @@ -121,9 +121,9 @@ class Crawler(object): finally: clearConsoleLine(True) - if not threadData.shared.outputs: + if not threadData.shared.values: warnMsg = "no usable links found (with GET parameters)" logger.warn(warnMsg) else: - for url in threadData.shared.outputs: + for url in threadData.shared.values: kb.targets.add(( url, None, None, None ))