Minor stability patch for multi-threading console output (#3284)

This commit is contained in:
Miroslav Stampar 2019-01-22 13:45:16 +01:00
parent ae6235ce20
commit ba356baab0
7 changed files with 23 additions and 15 deletions

View File

@ -913,7 +913,8 @@ def dataToStdout(data, forceOutput=False, bold=False, content_type=None, status=
if not kb.get("threadException"):
if forceOutput or not (getCurrentThreadData().disableStdOut or kb.get("wizardMode")):
if kb.get("multiThreadMode"):
multiThreadMode = isMultiThreadMode()
if multiThreadMode:
logging._acquireLock()
if isinstance(data, unicode):
@ -931,7 +932,7 @@ def dataToStdout(data, forceOutput=False, bold=False, content_type=None, status=
except IOError:
pass
if kb.get("multiThreadMode"):
if multiThreadMode:
logging._releaseLock()
kb.prependFlag = isinstance(data, basestring) and (len(data) == 1 and data not in ('\n', '\r') or len(data) > 2 and data[0] == '\r' and data[-1] != '\n')
@ -1982,6 +1983,13 @@ def isHexEncodedString(subject):
return re.match(r"\A[0-9a-fA-Fx]+\Z", subject) is not None
def isMultiThreadMode():
"""
Checks if running in multi-thread(ing) mode
"""
return threading.activeCount() > 1
@cachedmethod
def getConsoleWidth(default=80):
"""

View File

@ -20,6 +20,7 @@ from lib.core.common import dataToStdout
from lib.core.common import getSafeExString
from lib.core.common import getUnicode
from lib.core.common import isListLike
from lib.core.common import isMultiThreadMode
from lib.core.common import normalizeUnicode
from lib.core.common import openFile
from lib.core.common import prioritySortColumns
@ -74,7 +75,8 @@ class Dump(object):
if console:
dataToStdout(text)
if kb.get("multiThreadMode"):
multiThreadMode = isMultiThreadMode()
if multiThreadMode:
self._lock.acquire()
try:
@ -83,7 +85,7 @@ class Dump(object):
errMsg = "error occurred while writing to log file ('%s')" % getSafeExString(ex)
raise SqlmapGenericException(errMsg)
if kb.get("multiThreadMode"):
if multiThreadMode:
self._lock.release()
kb.dataOutputFlag = True

View File

@ -1829,7 +1829,6 @@ def _setKnowledgeBaseAttributes(flushAll=True):
kb.matchRatio = None
kb.maxConnectionsFlag = False
kb.mergeCookies = None
kb.multiThreadMode = False
kb.negativeLogic = False
kb.nullConnection = None
kb.oldMsf = None

View File

@ -19,7 +19,7 @@ from lib.core.enums import DBMS_DIRECTORY_NAME
from lib.core.enums import OS
# sqlmap version (<major>.<minor>.<month>.<monthly commit>)
VERSION = "1.3.1.70"
VERSION = "1.3.1.71"
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)

View File

@ -110,7 +110,6 @@ def setDaemon(thread):
def runThreads(numThreads, threadFunction, cleanupFunction=None, forwardException=True, threadChoice=False, startThreadMsg=True):
threads = []
kb.multiThreadMode = True
kb.threadContinue = True
kb.threadException = False
@ -204,7 +203,6 @@ def runThreads(numThreads, threadFunction, cleanupFunction=None, forwardExceptio
traceback.print_exc()
finally:
kb.multiThreadMode = False
kb.bruteMode = False
kb.threadContinue = True
kb.threadException = False

View File

@ -44,6 +44,7 @@ from lib.core.common import getHostHeader
from lib.core.common import getRequestHeader
from lib.core.common import getSafeExString
from lib.core.common import getUnicode
from lib.core.common import isMultiThreadMode
from lib.core.common import logHTTPTraffic
from lib.core.common import pushValue
from lib.core.common import popValue
@ -731,7 +732,7 @@ class Connect(object):
else:
logger.debug(warnMsg)
return Connect._retryProxy(**kwargs)
elif kb.testMode or kb.multiThreadMode:
elif kb.testMode or isMultiThreadMode():
logger.critical(warnMsg)
return None, None, None
else:

View File

@ -29,32 +29,32 @@ c1da277517c7ec4c23e953a51b51e203 lib/controller/handler.py
fb6be55d21a70765e35549af2484f762 lib/controller/__init__.py
ed7874be0d2d3802f3d20184f2b280d5 lib/core/agent.py
a932126e7d80e545c5d44af178d0bc0c lib/core/bigarray.py
2cb5d057cbb1f333dfd42b8c7262d404 lib/core/common.py
d6961903f261635b2eb3fe7e9c35e8ce lib/core/common.py
de8d27ae6241163ff9e97aa9e7c51a18 lib/core/convert.py
abcb1121eb56d3401839d14e8ed06b6e lib/core/data.py
db60c6ebb63b72ed119e304b359fc1a6 lib/core/datatype.py
b7c912e2af7a3354f6d7c04f556a80b2 lib/core/decorators.py
5f4680b769ae07f22157bd832c97cf8f lib/core/defaults.py
9dfc69ba47209a4ceca494dde9ee8183 lib/core/dicts.py
fd5403505f76eee6829c06b9342e269c lib/core/dump.py
4782353a3072e4d17c4e314daf918d8a lib/core/dump.py
5c91145204092b995ed1ac641e9e291d lib/core/enums.py
84ef8f32e4582fcc294dc14e1997131d lib/core/exception.py
fb6be55d21a70765e35549af2484f762 lib/core/__init__.py
18c896b157b03af716542e5fe9233ef9 lib/core/log.py
fa9f24e88c81a6cef52da3dd5e637010 lib/core/optiondict.py
bdb5a0e1f40d9c4d43593e25c8c58ec6 lib/core/option.py
b56df9d9426027f3450432c2b6428485 lib/core/option.py
fe370021c6bc99daf44b2bfc0d1effb3 lib/core/patch.py
4cfda3735871cd59b213470a0bbc8c3a lib/core/profiling.py
5e2c16a8e2daee22dd545df13386e7a3 lib/core/readlineng.py
7d8a22c582ad201f65b73225e4456170 lib/core/replication.py
3179d34f371e0295dd4604568fb30bcd lib/core/revision.py
d6269c55789f78cf707e09a0f5b45443 lib/core/session.py
6e47f6340889c0241c3055581fd9dd5c lib/core/settings.py
77e8b3de0d19deb37e87cf34bdf18a1a lib/core/settings.py
4483b4a5b601d8f1c4281071dff21ecc lib/core/shell.py
10fd19b0716ed261e6d04f311f6f527c lib/core/subprocessng.py
9c7b5c6397fb3da33e7a4d7876d159c6 lib/core/target.py
7857b24b7865ccb4a05283faa596974d lib/core/testing.py
203d2082929b4ac5454605c8c7c800a9 lib/core/threads.py
e9788d2992f842cf91ab67389bf4372a lib/core/threads.py
2c263c8610667fdc593c50a35ab20f57 lib/core/unescaper.py
ff45c74515fecc95277f7b9ad945f17c lib/core/update.py
5b3f08208be0579356f78ce5805d37b2 lib/core/wordlist.py
@ -71,7 +71,7 @@ adcecd2d6a8667b22872a563eb83eac0 lib/parse/payloads.py
e4ea70bcd461f5176867dcd89d372386 lib/request/basicauthhandler.py
97b7577fdfe3d8537fe9ea3a070d0507 lib/request/basic.py
fc25d951217077fe655ed2a3a81552ae lib/request/comparison.py
5a1226fc294dd7507be089b5622564d1 lib/request/connect.py
27927a37edfa9c2dfb6e5de9e859d10f lib/request/connect.py
7cba86090b02558f04c6692cef66e772 lib/request/direct.py
2b7509ba38a667c61cefff036ec4ca6f lib/request/dns.py
ceac6b3bf1f726f8ff43c6814e9d7281 lib/request/httpshandler.py