From 5770c08784cb034d052cbe360ce59fdcd1603ace Mon Sep 17 00:00:00 2001 From: Miroslav Stampar Date: Mon, 25 Jul 2011 20:17:44 +0000 Subject: [PATCH] minor optimization and refactoring --- lib/core/settings.py | 4 ++-- lib/techniques/error/use.py | 15 +++++++-------- lib/techniques/union/use.py | 15 +++++++-------- lib/utils/hash.py | 2 +- sqlmap.py | 3 ++- 5 files changed, 19 insertions(+), 20 deletions(-) diff --git a/lib/core/settings.py b/lib/core/settings.py index f01e9fc75..ee48947a7 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -384,7 +384,7 @@ IDS_WAF_CHECK_PAYLOAD = "AND 1=1 UNION ALL SELECT 1,2,3,table_name FROM informat ROTATING_CHARS = ('\\', '|', '|', '/', '-') # Chunk length (in items) used by BigArray objects (only last chunk and cached one are held in memory) -BIGARRAY_CHUNK_LENGTH = 5000 +BIGARRAY_CHUNK_LENGTH = 4096 # Only console display last n table rows -TRIM_STDOUT_DUMP_SIZE = 256 +TRIM_STDOUT_DUMP_SIZE = 1024 diff --git a/lib/techniques/error/use.py b/lib/techniques/error/use.py index 657ebb5aa..d79a2a0ef 100644 --- a/lib/techniques/error/use.py +++ b/lib/techniques/error/use.py @@ -320,8 +320,8 @@ def errorUse(expression, expected=None, resumeValue=True, dump=False): stopLimit = 1 threadData = getCurrentThreadData() - threadData.shared.limits = range(startLimit, stopLimit) - numThreads = min(conf.threads, len(threadData.shared.limits)) + threadData.shared.limits = iter(xrange(startLimit, stopLimit)) + numThreads = min(conf.threads, (stopLimit - startLimit)) threadData.shared.outputs = BigArray() if stopLimit > TURN_OFF_RESUME_INFO_LIMIT: @@ -340,13 +340,12 @@ def errorUse(expression, expected=None, resumeValue=True, dump=False): while kb.threadContinue: kb.locks.limits.acquire() - if threadData.shared.limits: - num = threadData.shared.limits[-1] - del threadData.shared.limits[-1] - kb.locks.limits.release() - else: - kb.locks.limits.release() + try: + num = threadData.shared.limits.next() + except StopIteration: break + finally: + kb.locks.limits.release() output = __errorFields(expression, expressionFields, expressionFieldsList, expected, num, resumeValue) diff --git a/lib/techniques/union/use.py b/lib/techniques/union/use.py index 8e589671c..5b75ba96e 100644 --- a/lib/techniques/union/use.py +++ b/lib/techniques/union/use.py @@ -261,8 +261,8 @@ def unionUse(expression, unpack=True, dump=False): stopLimit = 1 threadData = getCurrentThreadData() - threadData.shared.limits = range(startLimit, stopLimit) - numThreads = min(conf.threads, len(threadData.shared.limits)) + threadData.shared.limits = iter(xrange(startLimit, stopLimit)) + numThreads = min(conf.threads, (stopLimit - startLimit)) threadData.shared.value = BigArray() if stopLimit > TURN_OFF_RESUME_INFO_LIMIT: @@ -281,13 +281,12 @@ def unionUse(expression, unpack=True, dump=False): while kb.threadContinue: kb.locks.limits.acquire() - if threadData.shared.limits: - num = threadData.shared.limits[-1] - del threadData.shared.limits[-1] - kb.locks.limits.release() - else: - kb.locks.limits.release() + try: + num = threadData.shared.limits.next() + except StopIteration: break + finally: + kb.locks.limits.release() if Backend.getIdentifiedDbms() in (DBMS.MSSQL, DBMS.SYBASE): field = expressionFieldsList[0] diff --git a/lib/utils/hash.py b/lib/utils/hash.py index 28d0fe0a7..ce43d22d0 100644 --- a/lib/utils/hash.py +++ b/lib/utils/hash.py @@ -266,7 +266,7 @@ def attackDumpedTable(): colUser = column break - for i in range(count): + for i in xrange(count): for column in columns: if column == colUser or column == '__infos__': continue diff --git a/sqlmap.py b/sqlmap.py index 71943ec93..4a212bcf6 100755 --- a/sqlmap.py +++ b/sqlmap.py @@ -130,7 +130,8 @@ def main(): kb.threadException = True # Reference: http://stackoverflow.com/questions/1635080/terminate-a-multi-thread-python-program - os._exit(0) + if conf.threads > 1: + os._exit(0) if __name__ == "__main__": main()