mirror of
https://github.com/sqlmapproject/sqlmap.git
synced 2024-11-26 03:23:48 +03:00
code refactoring regarding standard output suppression and some threading issues
This commit is contained in:
parent
0e68248f60
commit
385e208f38
|
@ -427,7 +427,9 @@ def filePathToString(filePath):
|
||||||
return strRepl
|
return strRepl
|
||||||
|
|
||||||
def dataToStdout(data, forceOutput=False):
|
def dataToStdout(data, forceOutput=False):
|
||||||
if forceOutput or conf.verbose > 0:
|
if (forceOutput or conf.verbose > 0)\
|
||||||
|
and not ('threadException' in kb and kb.threadException)\
|
||||||
|
and not ('disableStdOut' in kb and kb.disableStdOut):
|
||||||
try:
|
try:
|
||||||
sys.stdout.write(data)
|
sys.stdout.write(data)
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
|
|
@ -1119,7 +1119,6 @@ def __setConfAttributes():
|
||||||
conf.sessionFP = None
|
conf.sessionFP = None
|
||||||
conf.start = True
|
conf.start = True
|
||||||
conf.tests = []
|
conf.tests = []
|
||||||
conf.threadException = False
|
|
||||||
conf.trafficFP = None
|
conf.trafficFP = None
|
||||||
conf.wFileType = None
|
conf.wFileType = None
|
||||||
|
|
||||||
|
@ -1144,6 +1143,7 @@ def __setKnowledgeBaseAttributes(flushAll=True):
|
||||||
kb.commonOutputs = None
|
kb.commonOutputs = None
|
||||||
|
|
||||||
kb.data = advancedDict()
|
kb.data = advancedDict()
|
||||||
|
kb.disableStdOut = False
|
||||||
|
|
||||||
# Old style injection flag
|
# Old style injection flag
|
||||||
kb.unionTest = None
|
kb.unionTest = None
|
||||||
|
@ -1196,6 +1196,7 @@ def __setKnowledgeBaseAttributes(flushAll=True):
|
||||||
kb.testMode = False
|
kb.testMode = False
|
||||||
kb.testQueryCount = 0
|
kb.testQueryCount = 0
|
||||||
kb.threadContinue = True
|
kb.threadContinue = True
|
||||||
|
kb.threadException = False
|
||||||
kb.threadData = {}
|
kb.threadData = {}
|
||||||
kb.unionComment = ""
|
kb.unionComment = ""
|
||||||
kb.unionCount = None
|
kb.unionCount = None
|
||||||
|
|
|
@ -288,7 +288,7 @@ class Connect:
|
||||||
|
|
||||||
if silent or (ignoreTimeout and "timeout" in tbMsg):
|
if silent or (ignoreTimeout and "timeout" in tbMsg):
|
||||||
return None, None
|
return None, None
|
||||||
elif kb.retriesCount < conf.retries and not conf.threadException and not conf.scriptKiddie:
|
elif kb.retriesCount < conf.retries and not kb.threadException and not conf.scriptKiddie:
|
||||||
kb.retriesCount += 1
|
kb.retriesCount += 1
|
||||||
|
|
||||||
warnMsg += ", sqlmap is going to retry the request"
|
warnMsg += ", sqlmap is going to retry the request"
|
||||||
|
|
|
@ -390,8 +390,7 @@ def getValue(expression, blind=True, inband=True, error=True, time=True, fromUse
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if suppressOutput:
|
if suppressOutput:
|
||||||
pushValue(conf.verbose)
|
kb.disableStdOut = True
|
||||||
conf.verbose = 0
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if conf.direct:
|
if conf.direct:
|
||||||
|
@ -467,7 +466,7 @@ def getValue(expression, blind=True, inband=True, error=True, time=True, fromUse
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
if suppressOutput:
|
if suppressOutput:
|
||||||
conf.verbose = popValue()
|
kb.disableStdOut = False
|
||||||
|
|
||||||
if value and expected == EXPECTED.BOOL:
|
if value and expected == EXPECTED.BOOL:
|
||||||
if isinstance(value, basestring):
|
if isinstance(value, basestring):
|
||||||
|
|
|
@ -341,11 +341,11 @@ def bisection(payload, expression, length=None, charsetType=None, firstChar=None
|
||||||
|
|
||||||
except (sqlmapConnectionException, sqlmapValueException), errMsg:
|
except (sqlmapConnectionException, sqlmapValueException), errMsg:
|
||||||
print
|
print
|
||||||
conf.threadException = True
|
kb.threadException = True
|
||||||
logger.error("thread %d: %s" % (numThread + 1, errMsg))
|
logger.error("thread %d: %s" % (numThread + 1, errMsg))
|
||||||
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
conf.threadException = True
|
kb.threadException = True
|
||||||
|
|
||||||
print
|
print
|
||||||
logger.debug("waiting for threads to finish")
|
logger.debug("waiting for threads to finish")
|
||||||
|
@ -359,7 +359,7 @@ def bisection(payload, expression, length=None, charsetType=None, firstChar=None
|
||||||
|
|
||||||
except:
|
except:
|
||||||
print
|
print
|
||||||
conf.threadException = True
|
kb.threadException = True
|
||||||
errMsg = unhandledException()
|
errMsg = unhandledException()
|
||||||
logger.error("thread %d: %s" % (numThread + 1, errMsg))
|
logger.error("thread %d: %s" % (numThread + 1, errMsg))
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
@ -505,7 +505,7 @@ def bisection(payload, expression, length=None, charsetType=None, firstChar=None
|
||||||
if not partialValue:
|
if not partialValue:
|
||||||
dataToSessionFile("]\n")
|
dataToSessionFile("]\n")
|
||||||
|
|
||||||
if conf.threadException:
|
if kb.threadException:
|
||||||
raise sqlmapThreadException, "something unexpected happened inside the threads"
|
raise sqlmapThreadException, "something unexpected happened inside the threads"
|
||||||
|
|
||||||
return queriesCount[0], finalValue
|
return queriesCount[0], finalValue
|
||||||
|
|
|
@ -80,7 +80,17 @@ def tableExists(tableFile):
|
||||||
thread.join(5)
|
thread.join(5)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
kb.threadContinue = False
|
kb.threadContinue = False
|
||||||
raise
|
kb.threadException = True
|
||||||
|
|
||||||
|
print
|
||||||
|
logger.debug("waiting for threads to finish")
|
||||||
|
|
||||||
|
try:
|
||||||
|
while (threading.activeCount() > 1):
|
||||||
|
pass
|
||||||
|
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
raise sqlmapThreadException, "user aborted"
|
||||||
finally:
|
finally:
|
||||||
kb.locks.seqLock = None
|
kb.locks.seqLock = None
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@ import re
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from lib.core.agent import agent
|
from lib.core.agent import agent
|
||||||
|
from lib.core.common import dataToStdout
|
||||||
from lib.core.common import extractRegexResult
|
from lib.core.common import extractRegexResult
|
||||||
from lib.core.common import getUnicode
|
from lib.core.common import getUnicode
|
||||||
from lib.core.common import initTechnique
|
from lib.core.common import initTechnique
|
||||||
|
@ -60,9 +61,6 @@ def errorUse(expression):
|
||||||
|
|
||||||
if output:
|
if output:
|
||||||
output = output.replace(kb.misc.space, " ")
|
output = output.replace(kb.misc.space, " ")
|
||||||
|
dataToStdout("\r[%s] [INFO] retrieved: %s" % (time.strftime("%X"), replaceNewlineTabs(output, stdout=True)))
|
||||||
if conf.verbose > 0:
|
|
||||||
infoMsg = "retrieved: %s" % replaceNewlineTabs(output, stdout=True)
|
|
||||||
logger.info(infoMsg)
|
|
||||||
|
|
||||||
return output
|
return output
|
||||||
|
|
|
@ -299,8 +299,7 @@ class Enumeration:
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
query = rootQuery.blind.query % user
|
query = rootQuery.blind.query % user
|
||||||
pushValue(conf.verbose)
|
kb.disableStdOut = True
|
||||||
conf.verbose = 0
|
|
||||||
elif kb.dbms == DBMS.MSSQL:
|
elif kb.dbms == DBMS.MSSQL:
|
||||||
if kb.dbmsVersion[0] in ( "2005", "2008" ):
|
if kb.dbmsVersion[0] in ( "2005", "2008" ):
|
||||||
query = rootQuery.blind.query2 % (user, index, user)
|
query = rootQuery.blind.query2 % (user, index, user)
|
||||||
|
@ -310,7 +309,7 @@ class Enumeration:
|
||||||
query = rootQuery.blind.query % (user, index)
|
query = rootQuery.blind.query % (user, index)
|
||||||
password = inject.getValue(query, inband=False)
|
password = inject.getValue(query, inband=False)
|
||||||
if kb.dbms == DBMS.SYBASE:
|
if kb.dbms == DBMS.SYBASE:
|
||||||
conf.verbose = popValue()
|
kb.disableStdOut = False
|
||||||
password = "0x%s" % strToHex(password)
|
password = "0x%s" % strToHex(password)
|
||||||
infoMsg = "retrieved: %s" % password
|
infoMsg = "retrieved: %s" % password
|
||||||
logger.info(infoMsg)
|
logger.info(infoMsg)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user