From b77e2042f245eb62f61e84c6fe3fafa279c02ddd Mon Sep 17 00:00:00 2001 From: Miroslav Stampar Date: Wed, 21 Dec 2011 23:23:00 +0000 Subject: [PATCH] some optimization --- _sqlmap.py | 9 ++++++--- lib/core/common.py | 12 ++++++++---- lib/techniques/union/use.py | 4 ++-- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/_sqlmap.py b/_sqlmap.py index 7eb241d88..e709b9a67 100755 --- a/_sqlmap.py +++ b/_sqlmap.py @@ -95,13 +95,13 @@ def main(): logger.critical(e) closeDumper(False, e) - except KeyboardInterrupt, _: + except KeyboardInterrupt: print errMsg = "user aborted" logger.error(errMsg) closeDumper(False, errMsg) - except EOFError, _: + except EOFError: print errMsg = "exit" logger.error(errMsg) @@ -127,7 +127,10 @@ def main(): kb.threadException = True if conf.get('hashDB', None): - conf.hashDB.flush(True) + try: + conf.hashDB.flush(True) + except KeyboardInterrupt: + pass # Reference: http://stackoverflow.com/questions/1635080/terminate-a-multi-thread-python-program if hasattr(conf, "threads") and conf.threads > 1: diff --git a/lib/core/common.py b/lib/core/common.py index 8c3db4a12..9c68aee9e 100644 --- a/lib/core/common.py +++ b/lib/core/common.py @@ -1340,10 +1340,14 @@ def parseUnionPage(output, expression, partial=False, sort=True): output = re.findall(regExpr, output, re.DOTALL | re.IGNORECASE) if sort: - dict_ = {} + _ = [] + unique = set() for entry in output: - dict_[entry.lower()] = entry - output = dict_.values() + key = entry.lower() + if key not in unique: + unique.add(key) + _.append(entry) + output = _ for entry in output: entry = safecharencode(entry) if kb.safeCharEncode else entry @@ -1356,7 +1360,7 @@ def parseUnionPage(output, expression, partial=False, sort=True): if len(entry) == 1: data.append(entry[0]) else: - data.append(list(entry)) + data.append(entry) else: data = output diff --git a/lib/techniques/union/use.py b/lib/techniques/union/use.py index 86c68fbd6..126433d36 100644 --- a/lib/techniques/union/use.py +++ b/lib/techniques/union/use.py @@ -72,10 +72,10 @@ def __oneShotUnionUse(expression, unpack=True, limited=False): # Parse the returned page to get the exact union-based # sql injection output - retVal = reduce(lambda x, y: x if x is not None else y, [ \ + retVal = reduce(lambda x, y: x if x is not None else y, ( \ extractRegexResult(check, removeReflectiveValues(page, payload), re.DOTALL | re.IGNORECASE), \ extractRegexResult(check, removeReflectiveValues(listToStrValue(headers.headers \ - if headers else None), payload, True), re.DOTALL | re.IGNORECASE)], \ + if headers else None), payload, True), re.DOTALL | re.IGNORECASE)), \ None) if retVal is not None: