Bug fix (reconnecting in case of timeouted direct connection)

This commit is contained in:
Miroslav Stampar 2016-10-17 22:55:07 +02:00
parent 24eaf55dc8
commit 5b14eecd25
5 changed files with 24 additions and 10 deletions

View File

@ -366,3 +366,8 @@ class MKSTEMP_PREFIX:
RESULTS = "sqlmapresults-" RESULTS = "sqlmapresults-"
COOKIE_JAR = "sqlmapcookiejar-" COOKIE_JAR = "sqlmapcookiejar-"
BIG_ARRAY = "sqlmapbigarray-" BIG_ARRAY = "sqlmapbigarray-"
class TIMEOUT_STATE:
NORMAL = 0
EXCEPTION = 1
TIMEOUT = 2

View File

@ -19,7 +19,7 @@ from lib.core.enums import DBMS_DIRECTORY_NAME
from lib.core.enums import OS from lib.core.enums import OS
# sqlmap version (<major>.<minor>.<month>.<monthly commit>) # sqlmap version (<major>.<minor>.<month>.<monthly commit>)
VERSION = "1.0.10.41" VERSION = "1.0.10.42"
TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable" TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable"
TYPE_COLORS = {"dev": 33, "stable": 90, "pip": 34} 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) VERSION_STRING = "sqlmap/%s#%s" % ('.'.join(VERSION.split('.')[:-1]) if VERSION.count('.') > 2 and VERSION.split('.')[-1] == '0' else VERSION, TYPE)

View File

@ -24,6 +24,7 @@ from lib.core.dicts import SQL_STATEMENTS
from lib.core.enums import CUSTOM_LOGGING from lib.core.enums import CUSTOM_LOGGING
from lib.core.enums import DBMS from lib.core.enums import DBMS
from lib.core.enums import EXPECTED from lib.core.enums import EXPECTED
from lib.core.enums import TIMEOUT_STATE
from lib.core.settings import UNICODE_ENCODING from lib.core.settings import UNICODE_ENCODING
from lib.utils.timeout import timeout from lib.utils.timeout import timeout
@ -51,10 +52,14 @@ def direct(query, content=True):
start = time.time() start = time.time()
if not select and "EXEC " not in query.upper(): 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): 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) output, state = timeout(func=conf.dbmsConnector.select, args=(query,), duration=conf.timeout, default=None)
hashDBWrite(query, output, True) if state == TIMEOUT_STATE.NORMAL:
hashDBWrite(query, output, True)
elif state == TIMEOUT_STATE.TIMEOUT:
conf.dbmsConnector.close()
conf.dbmsConnector.connect()
elif output: elif output:
infoMsg = "resumed: %s..." % getUnicode(output, UNICODE_ENCODING)[:20] infoMsg = "resumed: %s..." % getUnicode(output, UNICODE_ENCODING)[:20]
logger.info(infoMsg) logger.info(infoMsg)

View File

@ -9,25 +9,29 @@ import threading
from lib.core.data import logger from lib.core.data import logger
from lib.core.enums import CUSTOM_LOGGING from lib.core.enums import CUSTOM_LOGGING
from lib.core.enums import TIMEOUT_STATE
def timeout(func, args=(), kwargs={}, duration=1, default=None): def timeout(func, args=(), kwargs={}, duration=1, default=None):
class InterruptableThread(threading.Thread): class InterruptableThread(threading.Thread):
def __init__(self): def __init__(self):
threading.Thread.__init__(self) threading.Thread.__init__(self)
self.result = None self.result = None
self.timeout_state = None
def run(self): def run(self):
try: try:
self.result = func(*args, **kwargs) self.result = func(*args, **kwargs)
self.timeout_state = TIMEOUT_STATE.NORMAL
except Exception, msg: except Exception, msg:
logger.log(CUSTOM_LOGGING.TRAFFIC_IN, msg) logger.log(CUSTOM_LOGGING.TRAFFIC_IN, msg)
self.result = default self.result = default
self.timeout_state = TIMEOUT_STATE.EXCEPTION
thread = InterruptableThread() thread = InterruptableThread()
thread.start() thread.start()
thread.join(duration) thread.join(duration)
if thread.isAlive(): if thread.isAlive():
return default return default, TIMEOUT_STATE.TIMEOUT
else: else:
return thread.result return thread.result, thread.timeout_state

View File

@ -34,7 +34,7 @@ e4ca0fd47f20cf7ba6a5f5cbf980073c lib/core/decorators.py
67f206cf2658145992cc1d7020138325 lib/core/defaults.py 67f206cf2658145992cc1d7020138325 lib/core/defaults.py
3b2c013b610c5ae3193ced4f19bf1931 lib/core/dicts.py 3b2c013b610c5ae3193ced4f19bf1931 lib/core/dicts.py
1f98d3f57ce21d625fd67adb26cfd13c lib/core/dump.py 1f98d3f57ce21d625fd67adb26cfd13c lib/core/dump.py
1128705f593013359497b3959078b650 lib/core/enums.py b218e03ef7426fb0414881b05add1092 lib/core/enums.py
e4aec2b11c1ad6039d0c3dbbfbc5eb1a lib/core/exception.py e4aec2b11c1ad6039d0c3dbbfbc5eb1a lib/core/exception.py
cc9c82cfffd8ee9b25ba3af6284f057e lib/core/__init__.py cc9c82cfffd8ee9b25ba3af6284f057e lib/core/__init__.py
91c514013daa796e2cdd940389354eac lib/core/log.py 91c514013daa796e2cdd940389354eac lib/core/log.py
@ -45,7 +45,7 @@ e60456db5380840a586654344003d4e6 lib/core/readlineng.py
5ef56abb8671c2ca6ceecb208258e360 lib/core/replication.py 5ef56abb8671c2ca6ceecb208258e360 lib/core/replication.py
99a2b496b9d5b546b335653ca801153f lib/core/revision.py 99a2b496b9d5b546b335653ca801153f lib/core/revision.py
7c15dd2777af4dac2c89cab6df17462e lib/core/session.py 7c15dd2777af4dac2c89cab6df17462e lib/core/session.py
3f7524efc2c224678608ae14f372b009 lib/core/settings.py 49b872986ac8a016a5ec7e378eaac419 lib/core/settings.py
7af83e4f18cab6dff5e67840eb65be80 lib/core/shell.py 7af83e4f18cab6dff5e67840eb65be80 lib/core/shell.py
23657cd7d924e3c6d225719865855827 lib/core/subprocessng.py 23657cd7d924e3c6d225719865855827 lib/core/subprocessng.py
c3ace7874a536d801f308cf1fd03df99 lib/core/target.py c3ace7874a536d801f308cf1fd03df99 lib/core/target.py
@ -68,7 +68,7 @@ b40a4c5d91770d347df36d3065b63798 lib/parse/sitemap.py
083e7f446909b12009e72ae8e5e5737c lib/request/basic.py 083e7f446909b12009e72ae8e5e5737c lib/request/basic.py
c48285682a61d49982cb508351013cb4 lib/request/comparison.py c48285682a61d49982cb508351013cb4 lib/request/comparison.py
fa20d4d117875f9769ef49256d4da61f lib/request/connect.py fa20d4d117875f9769ef49256d4da61f lib/request/connect.py
49b4c583af68689de5f9acb162de2939 lib/request/direct.py d4d52c1073c75a6eecd2ebb98b670b96 lib/request/direct.py
1a46f7bb26b23ec0c0d9d9c95828241b lib/request/dns.py 1a46f7bb26b23ec0c0d9d9c95828241b lib/request/dns.py
70ceefe39980611494d4f99afb96f652 lib/request/httpshandler.py 70ceefe39980611494d4f99afb96f652 lib/request/httpshandler.py
cc9c82cfffd8ee9b25ba3af6284f057e lib/request/__init__.py cc9c82cfffd8ee9b25ba3af6284f057e lib/request/__init__.py
@ -112,7 +112,7 @@ da08a0b58c08ff452c7d1da4857d6680 lib/utils/progress.py
4c8895fb543aa5ae81f2d066422613f0 lib/utils/purge.py 4c8895fb543aa5ae81f2d066422613f0 lib/utils/purge.py
cc9b0f68dd58a2576a5a454b7f5f6b9c lib/utils/search.py cc9b0f68dd58a2576a5a454b7f5f6b9c lib/utils/search.py
4a0374ac0bc9d726446f04c77fbb5697 lib/utils/sqlalchemy.py 4a0374ac0bc9d726446f04c77fbb5697 lib/utils/sqlalchemy.py
8013e4a4c62ad916452434ea3c352a7a lib/utils/timeout.py 93dc08ba9f732d378f02cf85eae89df2 lib/utils/timeout.py
e6fa0e76367a77015da113811dfd9712 lib/utils/versioncheck.py e6fa0e76367a77015da113811dfd9712 lib/utils/versioncheck.py
adafdb28095ba2d03322fee2aae4548f lib/utils/xrange.py adafdb28095ba2d03322fee2aae4548f lib/utils/xrange.py
988100b4a1cd3b07acfd8b6ec692aed5 plugins/dbms/access/connector.py 988100b4a1cd3b07acfd8b6ec692aed5 plugins/dbms/access/connector.py