From 63d7cd607edb62ba69cb403c6a7752754fec73d9 Mon Sep 17 00:00:00 2001 From: Miroslav Stampar Date: Tue, 17 May 2016 13:54:42 +0200 Subject: [PATCH] Minor patch (for late threading issues) --- lib/core/settings.py | 5 ++++- sqlmap.py | 16 +++++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/lib/core/settings.py b/lib/core/settings.py index 88c1c83be..194f2bc0d 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from lib.core.revision import getRevisionNumber # sqlmap version (...) -VERSION = "1.0.5.34" +VERSION = "1.0.5.35" REVISION = getRevisionNumber() STABLE = VERSION.count('.') <= 2 VERSION_STRING = "sqlmap/%s#%s" % (VERSION, "stable" if STABLE else "dev") @@ -130,6 +130,9 @@ HTTP_ACCEPT_ENCODING_HEADER_VALUE = "gzip,deflate" # Default timeout for running commands over backdoor BACKDOOR_RUN_CMD_TIMEOUT = 5 +# Number of seconds to wait for thread finalization at program end +THREAD_FINALIZATION_TIMEOUT = 1 + # Maximum number of techniques used in inject.py/getValue() per one value MAX_TECHNIQUES_PER_VALUE = 2 diff --git a/sqlmap.py b/sqlmap.py index 66ba35706..e6a34ea54 100755 --- a/sqlmap.py +++ b/sqlmap.py @@ -54,6 +54,7 @@ try: from lib.core.profiling import profile from lib.core.settings import IS_WIN from lib.core.settings import LEGAL_DISCLAIMER + from lib.core.settings import THREAD_FINALIZATION_TIMEOUT from lib.core.settings import VERSION from lib.core.testing import smokeTest from lib.core.testing import liveTest @@ -276,15 +277,16 @@ def main(): if conf.get("dumper"): conf.dumper.flush() - if threading.activeCount() > 1: - logger.debug("short delay for thread finalization") - try: - time.sleep(0.5) - except KeyboardInterrupt: - pass + # short delay for thread finalization + try: + _ = time.time() + while threading.activeCount() > 1 and (time.time() - _) > THREAD_FINALIZATION_TIMEOUT: + time.sleep(0.01) + except KeyboardInterrupt: + pass # Reference: http://stackoverflow.com/questions/1635080/terminate-a-multi-thread-python-program - if conf.get("threads", 0) > 1 or conf.get("dnsServer"): + if threading.activeCount() > 1: os._exit(0) if __name__ == "__main__":