Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1d6d2c1

Browse files
committed
Some refactoring (isMultiThreadMode fuzz)
1 parent e6532f3 commit 1d6d2c1

6 files changed

Lines changed: 32 additions & 48 deletions

File tree

lib/core/common.py

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,7 +1016,7 @@ def dataToStdout(data, forceOutput=False, bold=False, contentType=None, status=C
10161016

10171017
if not kb.get("threadException"):
10181018
if forceOutput or not (getCurrentThreadData().disableStdOut or kb.get("wizardMode")):
1019-
multiThreadMode = isMultiThreadMode()
1019+
multiThreadMode = kb.get("multiThreadMode")
10201020
if multiThreadMode:
10211021
logging._acquireLock()
10221022

@@ -2266,25 +2266,6 @@ def isHexEncodedString(subject):
22662266

22672267
return re.match(r"\A[0-9a-fA-Fx]+\Z", subject) is not None
22682268

2269-
def isMultiThreadMode():
2270-
"""
2271-
Checks if running in multi-thread(ing) mode
2272-
2273-
>>> import time
2274-
>>> threading.activeCount()
2275-
1
2276-
>>> isMultiThreadMode()
2277-
False
2278-
>>> _ = lambda: time.sleep(0.1)
2279-
>>> thread = threading.Thread(target=_)
2280-
>>> thread.daemon = True
2281-
>>> thread.start()
2282-
>>> isMultiThreadMode()
2283-
True
2284-
"""
2285-
2286-
return threading.activeCount() > 1
2287-
22882269
@cachedmethod
22892270
def getConsoleWidth(default=80):
22902271
"""

lib/core/dump.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
from lib.core.common import filterNone
2020
from lib.core.common import getSafeExString
2121
from lib.core.common import isListLike
22-
from lib.core.common import isMultiThreadMode
2322
from lib.core.common import isNoneValue
2423
from lib.core.common import normalizeUnicode
2524
from lib.core.common import openFile
@@ -80,7 +79,7 @@ def _write(self, data, newline=True, console=True, content_type=None):
8079
elif console:
8180
dataToStdout(text)
8281

83-
multiThreadMode = isMultiThreadMode()
82+
multiThreadMode = kb.multiThreadMode
8483
if multiThreadMode:
8584
self._lock.acquire()
8685

lib/core/option.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2090,6 +2090,7 @@ def _setKnowledgeBaseAttributes(flushAll=True):
20902090
kb.matchRatio = None
20912091
kb.maxConnectionsFlag = False
20922092
kb.mergeCookies = None
2093+
kb.multiThreadMode = False
20932094
kb.multipleCtrlC = False
20942095
kb.negativeLogic = False
20952096
kb.nchar = True

lib/core/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from thirdparty.six import unichr as _unichr
2121

2222
# sqlmap version (<major>.<minor>.<month>.<monthly commit>)
23-
VERSION = "1.5.9.11"
23+
VERSION = "1.5.9.12"
2424
TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable"
2525
TYPE_COLORS = {"dev": 33, "stable": 90, "pip": 34}
2626
VERSION_STRING = "sqlmap/%s#%s" % ('.'.join(VERSION.split('.')[:-1]) if VERSION.count('.') > 2 and VERSION.split('.')[-1] == '0' else VERSION, TYPE)

lib/core/threads.py

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -123,31 +123,32 @@ def runThreads(numThreads, threadFunction, cleanupFunction=None, forwardExceptio
123123
kb.threadContinue = True
124124
kb.threadException = False
125125
kb.technique = ThreadData.technique
126-
127-
if threadChoice and conf.threads == numThreads == 1 and not (kb.injection.data and not any(_ not in (PAYLOAD.TECHNIQUE.TIME, PAYLOAD.TECHNIQUE.STACKED) for _ in kb.injection.data)):
128-
while True:
129-
message = "please enter number of threads? [Enter for %d (current)] " % numThreads
130-
choice = readInput(message, default=str(numThreads))
131-
if choice:
132-
skipThreadCheck = False
133-
134-
if choice.endswith('!'):
135-
choice = choice[:-1]
136-
skipThreadCheck = True
137-
138-
if isDigit(choice):
139-
if int(choice) > MAX_NUMBER_OF_THREADS and not skipThreadCheck:
140-
errMsg = "maximum number of used threads is %d avoiding potential connection issues" % MAX_NUMBER_OF_THREADS
141-
logger.critical(errMsg)
142-
else:
143-
conf.threads = numThreads = int(choice)
144-
break
145-
146-
if numThreads == 1:
147-
warnMsg = "running in a single-thread mode. This could take a while"
148-
logger.warn(warnMsg)
126+
kb.multiThreadMode = False
149127

150128
try:
129+
if threadChoice and conf.threads == numThreads == 1 and not (kb.injection.data and not any(_ not in (PAYLOAD.TECHNIQUE.TIME, PAYLOAD.TECHNIQUE.STACKED) for _ in kb.injection.data)):
130+
while True:
131+
message = "please enter number of threads? [Enter for %d (current)] " % numThreads
132+
choice = readInput(message, default=str(numThreads))
133+
if choice:
134+
skipThreadCheck = False
135+
136+
if choice.endswith('!'):
137+
choice = choice[:-1]
138+
skipThreadCheck = True
139+
140+
if isDigit(choice):
141+
if int(choice) > MAX_NUMBER_OF_THREADS and not skipThreadCheck:
142+
errMsg = "maximum number of used threads is %d avoiding potential connection issues" % MAX_NUMBER_OF_THREADS
143+
logger.critical(errMsg)
144+
else:
145+
conf.threads = numThreads = int(choice)
146+
break
147+
148+
if numThreads == 1:
149+
warnMsg = "running in a single-thread mode. This could take a while"
150+
logger.warn(warnMsg)
151+
151152
if numThreads > 1:
152153
if startThreadMsg:
153154
infoMsg = "starting %d threads" % numThreads
@@ -156,6 +157,8 @@ def runThreads(numThreads, threadFunction, cleanupFunction=None, forwardExceptio
156157
threadFunction()
157158
return
158159

160+
kb.multiThreadMode = True
161+
159162
# Start the threads
160163
for numThread in xrange(numThreads):
161164
thread = threading.Thread(target=exceptionHandledFunction, name=str(numThread), args=[threadFunction])
@@ -225,6 +228,7 @@ def runThreads(numThreads, threadFunction, cleanupFunction=None, forwardExceptio
225228
traceback.print_exc()
226229

227230
finally:
231+
kb.multiThreadMode = False
228232
kb.threadContinue = True
229233
kb.threadException = False
230234
kb.technique = None

lib/request/connect.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ class WebSocketException(Exception):
4343
from lib.core.common import getHostHeader
4444
from lib.core.common import getRequestHeader
4545
from lib.core.common import getSafeExString
46-
from lib.core.common import isMultiThreadMode
4746
from lib.core.common import logHTTPTraffic
4847
from lib.core.common import openFile
4948
from lib.core.common import popValue
@@ -884,7 +883,7 @@ class _(dict):
884883
else:
885884
logger.debug(warnMsg)
886885
return Connect._retryProxy(**kwargs)
887-
elif kb.testMode or isMultiThreadMode():
886+
elif kb.testMode or kb.multiThreadMode:
888887
logger.critical(warnMsg)
889888
return None, None, None
890889
else:

0 commit comments

Comments
 (0)