mirror of
https://github.com/sqlmapproject/sqlmap.git
synced 2024-11-22 17:46:37 +03:00
Some refactoring (isMultiThreadMode fuzz)
This commit is contained in:
parent
e6532f3faf
commit
1d6d2c1892
|
@ -1016,7 +1016,7 @@ def dataToStdout(data, forceOutput=False, bold=False, contentType=None, status=C
|
||||||
|
|
||||||
if not kb.get("threadException"):
|
if not kb.get("threadException"):
|
||||||
if forceOutput or not (getCurrentThreadData().disableStdOut or kb.get("wizardMode")):
|
if forceOutput or not (getCurrentThreadData().disableStdOut or kb.get("wizardMode")):
|
||||||
multiThreadMode = isMultiThreadMode()
|
multiThreadMode = kb.get("multiThreadMode")
|
||||||
if multiThreadMode:
|
if multiThreadMode:
|
||||||
logging._acquireLock()
|
logging._acquireLock()
|
||||||
|
|
||||||
|
@ -2266,25 +2266,6 @@ def isHexEncodedString(subject):
|
||||||
|
|
||||||
return re.match(r"\A[0-9a-fA-Fx]+\Z", subject) is not None
|
return re.match(r"\A[0-9a-fA-Fx]+\Z", subject) is not None
|
||||||
|
|
||||||
def isMultiThreadMode():
|
|
||||||
"""
|
|
||||||
Checks if running in multi-thread(ing) mode
|
|
||||||
|
|
||||||
>>> import time
|
|
||||||
>>> threading.activeCount()
|
|
||||||
1
|
|
||||||
>>> isMultiThreadMode()
|
|
||||||
False
|
|
||||||
>>> _ = lambda: time.sleep(0.1)
|
|
||||||
>>> thread = threading.Thread(target=_)
|
|
||||||
>>> thread.daemon = True
|
|
||||||
>>> thread.start()
|
|
||||||
>>> isMultiThreadMode()
|
|
||||||
True
|
|
||||||
"""
|
|
||||||
|
|
||||||
return threading.activeCount() > 1
|
|
||||||
|
|
||||||
@cachedmethod
|
@cachedmethod
|
||||||
def getConsoleWidth(default=80):
|
def getConsoleWidth(default=80):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -19,7 +19,6 @@ from lib.core.common import dataToStdout
|
||||||
from lib.core.common import filterNone
|
from lib.core.common import filterNone
|
||||||
from lib.core.common import getSafeExString
|
from lib.core.common import getSafeExString
|
||||||
from lib.core.common import isListLike
|
from lib.core.common import isListLike
|
||||||
from lib.core.common import isMultiThreadMode
|
|
||||||
from lib.core.common import isNoneValue
|
from lib.core.common import isNoneValue
|
||||||
from lib.core.common import normalizeUnicode
|
from lib.core.common import normalizeUnicode
|
||||||
from lib.core.common import openFile
|
from lib.core.common import openFile
|
||||||
|
@ -80,7 +79,7 @@ class Dump(object):
|
||||||
elif console:
|
elif console:
|
||||||
dataToStdout(text)
|
dataToStdout(text)
|
||||||
|
|
||||||
multiThreadMode = isMultiThreadMode()
|
multiThreadMode = kb.multiThreadMode
|
||||||
if multiThreadMode:
|
if multiThreadMode:
|
||||||
self._lock.acquire()
|
self._lock.acquire()
|
||||||
|
|
||||||
|
|
|
@ -2090,6 +2090,7 @@ def _setKnowledgeBaseAttributes(flushAll=True):
|
||||||
kb.matchRatio = None
|
kb.matchRatio = None
|
||||||
kb.maxConnectionsFlag = False
|
kb.maxConnectionsFlag = False
|
||||||
kb.mergeCookies = None
|
kb.mergeCookies = None
|
||||||
|
kb.multiThreadMode = False
|
||||||
kb.multipleCtrlC = False
|
kb.multipleCtrlC = False
|
||||||
kb.negativeLogic = False
|
kb.negativeLogic = False
|
||||||
kb.nchar = True
|
kb.nchar = True
|
||||||
|
|
|
@ -20,7 +20,7 @@ from thirdparty import six
|
||||||
from thirdparty.six import unichr as _unichr
|
from thirdparty.six import unichr as _unichr
|
||||||
|
|
||||||
# sqlmap version (<major>.<minor>.<month>.<monthly commit>)
|
# sqlmap version (<major>.<minor>.<month>.<monthly commit>)
|
||||||
VERSION = "1.5.9.11"
|
VERSION = "1.5.9.12"
|
||||||
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)
|
||||||
|
|
|
@ -123,31 +123,32 @@ def runThreads(numThreads, threadFunction, cleanupFunction=None, forwardExceptio
|
||||||
kb.threadContinue = True
|
kb.threadContinue = True
|
||||||
kb.threadException = False
|
kb.threadException = False
|
||||||
kb.technique = ThreadData.technique
|
kb.technique = ThreadData.technique
|
||||||
|
kb.multiThreadMode = False
|
||||||
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)):
|
|
||||||
while True:
|
|
||||||
message = "please enter number of threads? [Enter for %d (current)] " % numThreads
|
|
||||||
choice = readInput(message, default=str(numThreads))
|
|
||||||
if choice:
|
|
||||||
skipThreadCheck = False
|
|
||||||
|
|
||||||
if choice.endswith('!'):
|
|
||||||
choice = choice[:-1]
|
|
||||||
skipThreadCheck = True
|
|
||||||
|
|
||||||
if isDigit(choice):
|
|
||||||
if int(choice) > MAX_NUMBER_OF_THREADS and not skipThreadCheck:
|
|
||||||
errMsg = "maximum number of used threads is %d avoiding potential connection issues" % MAX_NUMBER_OF_THREADS
|
|
||||||
logger.critical(errMsg)
|
|
||||||
else:
|
|
||||||
conf.threads = numThreads = int(choice)
|
|
||||||
break
|
|
||||||
|
|
||||||
if numThreads == 1:
|
|
||||||
warnMsg = "running in a single-thread mode. This could take a while"
|
|
||||||
logger.warn(warnMsg)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
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)):
|
||||||
|
while True:
|
||||||
|
message = "please enter number of threads? [Enter for %d (current)] " % numThreads
|
||||||
|
choice = readInput(message, default=str(numThreads))
|
||||||
|
if choice:
|
||||||
|
skipThreadCheck = False
|
||||||
|
|
||||||
|
if choice.endswith('!'):
|
||||||
|
choice = choice[:-1]
|
||||||
|
skipThreadCheck = True
|
||||||
|
|
||||||
|
if isDigit(choice):
|
||||||
|
if int(choice) > MAX_NUMBER_OF_THREADS and not skipThreadCheck:
|
||||||
|
errMsg = "maximum number of used threads is %d avoiding potential connection issues" % MAX_NUMBER_OF_THREADS
|
||||||
|
logger.critical(errMsg)
|
||||||
|
else:
|
||||||
|
conf.threads = numThreads = int(choice)
|
||||||
|
break
|
||||||
|
|
||||||
|
if numThreads == 1:
|
||||||
|
warnMsg = "running in a single-thread mode. This could take a while"
|
||||||
|
logger.warn(warnMsg)
|
||||||
|
|
||||||
if numThreads > 1:
|
if numThreads > 1:
|
||||||
if startThreadMsg:
|
if startThreadMsg:
|
||||||
infoMsg = "starting %d threads" % numThreads
|
infoMsg = "starting %d threads" % numThreads
|
||||||
|
@ -156,6 +157,8 @@ def runThreads(numThreads, threadFunction, cleanupFunction=None, forwardExceptio
|
||||||
threadFunction()
|
threadFunction()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
kb.multiThreadMode = True
|
||||||
|
|
||||||
# Start the threads
|
# Start the threads
|
||||||
for numThread in xrange(numThreads):
|
for numThread in xrange(numThreads):
|
||||||
thread = threading.Thread(target=exceptionHandledFunction, name=str(numThread), args=[threadFunction])
|
thread = threading.Thread(target=exceptionHandledFunction, name=str(numThread), args=[threadFunction])
|
||||||
|
@ -225,6 +228,7 @@ def runThreads(numThreads, threadFunction, cleanupFunction=None, forwardExceptio
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
|
kb.multiThreadMode = False
|
||||||
kb.threadContinue = True
|
kb.threadContinue = True
|
||||||
kb.threadException = False
|
kb.threadException = False
|
||||||
kb.technique = None
|
kb.technique = None
|
||||||
|
|
|
@ -43,7 +43,6 @@ from lib.core.common import getHeader
|
||||||
from lib.core.common import getHostHeader
|
from lib.core.common import getHostHeader
|
||||||
from lib.core.common import getRequestHeader
|
from lib.core.common import getRequestHeader
|
||||||
from lib.core.common import getSafeExString
|
from lib.core.common import getSafeExString
|
||||||
from lib.core.common import isMultiThreadMode
|
|
||||||
from lib.core.common import logHTTPTraffic
|
from lib.core.common import logHTTPTraffic
|
||||||
from lib.core.common import openFile
|
from lib.core.common import openFile
|
||||||
from lib.core.common import popValue
|
from lib.core.common import popValue
|
||||||
|
@ -884,7 +883,7 @@ class Connect(object):
|
||||||
else:
|
else:
|
||||||
logger.debug(warnMsg)
|
logger.debug(warnMsg)
|
||||||
return Connect._retryProxy(**kwargs)
|
return Connect._retryProxy(**kwargs)
|
||||||
elif kb.testMode or isMultiThreadMode():
|
elif kb.testMode or kb.multiThreadMode:
|
||||||
logger.critical(warnMsg)
|
logger.critical(warnMsg)
|
||||||
return None, None, None
|
return None, None, None
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user