From 5b14eecd2568a6d0ad08afe59cd55e896b6a0e72 Mon Sep 17 00:00:00 2001 From: Miroslav Stampar Date: Mon, 17 Oct 2016 22:55:07 +0200 Subject: [PATCH] Bug fix (reconnecting in case of timeouted direct connection) --- lib/core/enums.py | 5 +++++ lib/core/settings.py | 2 +- lib/request/direct.py | 11 ++++++++--- lib/utils/timeout.py | 8 ++++++-- txt/checksum.md5 | 8 ++++---- 5 files changed, 24 insertions(+), 10 deletions(-) diff --git a/lib/core/enums.py b/lib/core/enums.py index 88f7d8695..9c285e774 100644 --- a/lib/core/enums.py +++ b/lib/core/enums.py @@ -366,3 +366,8 @@ class MKSTEMP_PREFIX: RESULTS = "sqlmapresults-" COOKIE_JAR = "sqlmapcookiejar-" BIG_ARRAY = "sqlmapbigarray-" + +class TIMEOUT_STATE: + NORMAL = 0 + EXCEPTION = 1 + TIMEOUT = 2 diff --git a/lib/core/settings.py b/lib/core/settings.py index 56fbda960..68921db82 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import DBMS_DIRECTORY_NAME from lib.core.enums import OS # sqlmap version (...) -VERSION = "1.0.10.41" +VERSION = "1.0.10.42" TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable" TYPE_COLORS = {"dev": 33, "stable": 90, "pip": 34} VERSION_STRING = "sqlmap/%s#%s" % ('.'.join(VERSION.split('.')[:-1]) if VERSION.count('.') > 2 and VERSION.split('.')[-1] == '0' else VERSION, TYPE) diff --git a/lib/request/direct.py b/lib/request/direct.py index 8e2889f81..a907a0d2a 100644 --- a/lib/request/direct.py +++ b/lib/request/direct.py @@ -24,6 +24,7 @@ from lib.core.dicts import SQL_STATEMENTS from lib.core.enums import CUSTOM_LOGGING from lib.core.enums import DBMS from lib.core.enums import EXPECTED +from lib.core.enums import TIMEOUT_STATE from lib.core.settings import UNICODE_ENCODING from lib.utils.timeout import timeout @@ -51,10 +52,14 @@ def direct(query, content=True): start = time.time() if not select and "EXEC " not in query.upper(): - _ = timeout(func=conf.dbmsConnector.execute, args=(query,), duration=conf.timeout, default=None) + timeout(func=conf.dbmsConnector.execute, args=(query,), duration=conf.timeout, default=None) elif not (output and "sqlmapoutput" not in query and "sqlmapfile" not in query): - output = timeout(func=conf.dbmsConnector.select, args=(query,), duration=conf.timeout, default=None) - hashDBWrite(query, output, True) + output, state = timeout(func=conf.dbmsConnector.select, args=(query,), duration=conf.timeout, default=None) + if state == TIMEOUT_STATE.NORMAL: + hashDBWrite(query, output, True) + elif state == TIMEOUT_STATE.TIMEOUT: + conf.dbmsConnector.close() + conf.dbmsConnector.connect() elif output: infoMsg = "resumed: %s..." % getUnicode(output, UNICODE_ENCODING)[:20] logger.info(infoMsg) diff --git a/lib/utils/timeout.py b/lib/utils/timeout.py index 0e0a4f03b..10fc3fac7 100644 --- a/lib/utils/timeout.py +++ b/lib/utils/timeout.py @@ -9,25 +9,29 @@ import threading from lib.core.data import logger from lib.core.enums import CUSTOM_LOGGING +from lib.core.enums import TIMEOUT_STATE def timeout(func, args=(), kwargs={}, duration=1, default=None): class InterruptableThread(threading.Thread): def __init__(self): threading.Thread.__init__(self) self.result = None + self.timeout_state = None def run(self): try: self.result = func(*args, **kwargs) + self.timeout_state = TIMEOUT_STATE.NORMAL except Exception, msg: logger.log(CUSTOM_LOGGING.TRAFFIC_IN, msg) self.result = default + self.timeout_state = TIMEOUT_STATE.EXCEPTION thread = InterruptableThread() thread.start() thread.join(duration) if thread.isAlive(): - return default + return default, TIMEOUT_STATE.TIMEOUT else: - return thread.result + return thread.result, thread.timeout_state diff --git a/txt/checksum.md5 b/txt/checksum.md5 index 281f065de..d2b1cc113 100644 --- a/txt/checksum.md5 +++ b/txt/checksum.md5 @@ -34,7 +34,7 @@ e4ca0fd47f20cf7ba6a5f5cbf980073c lib/core/decorators.py 67f206cf2658145992cc1d7020138325 lib/core/defaults.py 3b2c013b610c5ae3193ced4f19bf1931 lib/core/dicts.py 1f98d3f57ce21d625fd67adb26cfd13c lib/core/dump.py -1128705f593013359497b3959078b650 lib/core/enums.py +b218e03ef7426fb0414881b05add1092 lib/core/enums.py e4aec2b11c1ad6039d0c3dbbfbc5eb1a lib/core/exception.py cc9c82cfffd8ee9b25ba3af6284f057e lib/core/__init__.py 91c514013daa796e2cdd940389354eac lib/core/log.py @@ -45,7 +45,7 @@ e60456db5380840a586654344003d4e6 lib/core/readlineng.py 5ef56abb8671c2ca6ceecb208258e360 lib/core/replication.py 99a2b496b9d5b546b335653ca801153f lib/core/revision.py 7c15dd2777af4dac2c89cab6df17462e lib/core/session.py -3f7524efc2c224678608ae14f372b009 lib/core/settings.py +49b872986ac8a016a5ec7e378eaac419 lib/core/settings.py 7af83e4f18cab6dff5e67840eb65be80 lib/core/shell.py 23657cd7d924e3c6d225719865855827 lib/core/subprocessng.py c3ace7874a536d801f308cf1fd03df99 lib/core/target.py @@ -68,7 +68,7 @@ b40a4c5d91770d347df36d3065b63798 lib/parse/sitemap.py 083e7f446909b12009e72ae8e5e5737c lib/request/basic.py c48285682a61d49982cb508351013cb4 lib/request/comparison.py fa20d4d117875f9769ef49256d4da61f lib/request/connect.py -49b4c583af68689de5f9acb162de2939 lib/request/direct.py +d4d52c1073c75a6eecd2ebb98b670b96 lib/request/direct.py 1a46f7bb26b23ec0c0d9d9c95828241b lib/request/dns.py 70ceefe39980611494d4f99afb96f652 lib/request/httpshandler.py cc9c82cfffd8ee9b25ba3af6284f057e lib/request/__init__.py @@ -112,7 +112,7 @@ da08a0b58c08ff452c7d1da4857d6680 lib/utils/progress.py 4c8895fb543aa5ae81f2d066422613f0 lib/utils/purge.py cc9b0f68dd58a2576a5a454b7f5f6b9c lib/utils/search.py 4a0374ac0bc9d726446f04c77fbb5697 lib/utils/sqlalchemy.py -8013e4a4c62ad916452434ea3c352a7a lib/utils/timeout.py +93dc08ba9f732d378f02cf85eae89df2 lib/utils/timeout.py e6fa0e76367a77015da113811dfd9712 lib/utils/versioncheck.py adafdb28095ba2d03322fee2aae4548f lib/utils/xrange.py 988100b4a1cd3b07acfd8b6ec692aed5 plugins/dbms/access/connector.py