mirror of
https://github.com/sqlmapproject/sqlmap.git
synced 2025-12-07 13:11:29 +00:00
Some code refactoring
This commit is contained in:
@@ -137,7 +137,7 @@ def checkSqlInjection(place, parameter, value):
|
||||
SUPPORTED_DBMS, True) or kb.heuristicDbms or injection.dbms):
|
||||
msg = "it looks like the back-end DBMS is '%s'. " % (Format.getErrorParsedDBMSes() or kb.heuristicDbms or injection.dbms)
|
||||
msg += "Do you want to skip test payloads specific for other DBMSes? [Y/n]"
|
||||
kb.reduceTests = (Backend.getErrorParsedDBMSes() or [kb.heuristicDbms]) if readInput(msg, default='Y').upper() == 'Y' else []
|
||||
kb.reduceTests = (Backend.getErrorParsedDBMSes() or [kb.heuristicDbms]) if readInput(msg, default='Y', boolean=True) else []
|
||||
|
||||
# If the DBMS has been fingerprinted (via DBMS-specific error
|
||||
# message, via simple heuristic check or via DBMS-specific
|
||||
@@ -152,7 +152,7 @@ def checkSqlInjection(place, parameter, value):
|
||||
msg += " and " if conf.level < 5 and conf.risk < 3 else ""
|
||||
msg += "risk (%d)" % conf.risk if conf.risk < 3 else ""
|
||||
msg += " values? [Y/n]" if conf.level < 5 and conf.risk < 3 else " value? [Y/n]"
|
||||
kb.extendTests = (Backend.getErrorParsedDBMSes() or [kb.heuristicDbms]) if readInput(msg, default='Y').upper() == 'Y' else []
|
||||
kb.extendTests = (Backend.getErrorParsedDBMSes() or [kb.heuristicDbms]) if readInput(msg, default='Y', boolean=True) else []
|
||||
|
||||
title = test.title
|
||||
kb.testType = stype = test.stype
|
||||
@@ -631,7 +631,8 @@ def checkSqlInjection(place, parameter, value):
|
||||
msg += "extended UNION tests if there is not "
|
||||
msg += "at least one other (potential) "
|
||||
msg += "technique found. Do you want to skip? [Y/n] "
|
||||
kb.futileUnion = readInput(msg, default="Y").strip().upper() == 'N'
|
||||
|
||||
kb.futileUnion = not readInput(msg, default='Y', boolean=True)
|
||||
if kb.futileUnion is False:
|
||||
continue
|
||||
|
||||
@@ -738,11 +739,9 @@ def checkSqlInjection(place, parameter, value):
|
||||
logger.warn(warnMsg)
|
||||
|
||||
msg = "how do you want to proceed? [(S)kip current test/(e)nd detection phase/(n)ext parameter/(c)hange verbosity/(q)uit]"
|
||||
choice = readInput(msg, default="S", checkBatch=False)
|
||||
choice = readInput(msg, default='S', checkBatch=False).strip().upper()
|
||||
|
||||
if choice[0] in ("s", "S"):
|
||||
pass
|
||||
elif choice[0] in ("c", "C"):
|
||||
if choice == 'C':
|
||||
choice = None
|
||||
while not ((choice or "").isdigit() and 0 <= int(choice) <= 6):
|
||||
if choice:
|
||||
@@ -752,11 +751,11 @@ def checkSqlInjection(place, parameter, value):
|
||||
conf.verbose = int(choice)
|
||||
setVerbosity()
|
||||
tests.insert(0, test)
|
||||
elif choice[0] in ("n", "N"):
|
||||
elif choice == 'N':
|
||||
return None
|
||||
elif choice[0] in ("e", "E"):
|
||||
elif choice == 'E':
|
||||
kb.endDetection = True
|
||||
elif choice[0] in ("q", "Q"):
|
||||
elif choice == 'Q':
|
||||
raise SqlmapUserQuitException
|
||||
|
||||
finally:
|
||||
@@ -1177,19 +1176,19 @@ def checkStability():
|
||||
logger.warn(warnMsg)
|
||||
|
||||
message = "how do you want to proceed? [(C)ontinue/(s)tring/(r)egex/(q)uit] "
|
||||
test = readInput(message, default="C")
|
||||
choice = readInput(message, default='C').strip().upper()
|
||||
|
||||
if test and test[0] in ("q", "Q"):
|
||||
if choice == 'Q':
|
||||
raise SqlmapUserQuitException
|
||||
|
||||
elif test and test[0] in ("s", "S"):
|
||||
elif choice == 'S':
|
||||
showStaticWords(firstPage, secondPage)
|
||||
|
||||
message = "please enter value for parameter 'string': "
|
||||
test = readInput(message)
|
||||
string = readInput(message)
|
||||
|
||||
if test:
|
||||
conf.string = test
|
||||
if string:
|
||||
conf.string = string
|
||||
|
||||
if kb.nullConnection:
|
||||
debugMsg = "turning off NULL connection "
|
||||
@@ -1201,12 +1200,12 @@ def checkStability():
|
||||
errMsg = "Empty value supplied"
|
||||
raise SqlmapNoneDataException(errMsg)
|
||||
|
||||
elif test and test[0] in ("r", "R"):
|
||||
elif choice == 'R':
|
||||
message = "please enter value for parameter 'regex': "
|
||||
test = readInput(message)
|
||||
regex = readInput(message)
|
||||
|
||||
if test:
|
||||
conf.regex = test
|
||||
if regex:
|
||||
conf.regex = regex
|
||||
|
||||
if kb.nullConnection:
|
||||
debugMsg = "turning off NULL connection "
|
||||
@@ -1372,13 +1371,13 @@ def identifyWaf():
|
||||
if retVal:
|
||||
message = "are you sure that you want to "
|
||||
message += "continue with further target testing? [y/N] "
|
||||
output = readInput(message, default="N")
|
||||
choice = readInput(message, default='N', boolean=True)
|
||||
|
||||
if not conf.tamper:
|
||||
warnMsg = "please consider usage of tamper scripts (option '--tamper')"
|
||||
singleTimeWarnMessage(warnMsg)
|
||||
|
||||
if output and output[0] not in ("Y", "y"):
|
||||
if not choice:
|
||||
raise SqlmapUserQuitException
|
||||
else:
|
||||
warnMsg = "WAF/IPS/IDS product hasn't been identified"
|
||||
@@ -1494,7 +1493,7 @@ def checkConnection(suppressOutput=False):
|
||||
return False
|
||||
|
||||
msg = "it is not recommended to continue in this kind of cases. Do you want to quit and make sure that everything is set up properly? [Y/n] "
|
||||
if readInput(msg, default="Y") not in ("n", "N"):
|
||||
if readInput(msg, default='Y', boolean=True):
|
||||
raise SqlmapSilentQuitException
|
||||
else:
|
||||
kb.ignoreNotFound = True
|
||||
|
||||
@@ -183,8 +183,8 @@ def _randomFillBlankFields(value):
|
||||
|
||||
if extractRegexResult(EMPTY_FORM_FIELDS_REGEX, value):
|
||||
message = "do you want to fill blank fields with random values? [Y/n] "
|
||||
test = readInput(message, default="Y")
|
||||
if not test or test[0] in ("y", "Y"):
|
||||
|
||||
if readInput(message, default="Y", boolean=True):
|
||||
for match in re.finditer(EMPTY_FORM_FIELDS_REGEX, retVal):
|
||||
item = match.group("result")
|
||||
if not any(_ in item for _ in IGNORE_PARAMETERS) and not re.search(ASP_NET_CONTROL_REGEX, item):
|
||||
@@ -305,7 +305,9 @@ def start():
|
||||
message = "SQL injection vulnerability has already been detected "
|
||||
message += "against '%s'. Do you want to skip " % conf.hostname
|
||||
message += "further tests involving it? [Y/n]"
|
||||
kb.skipVulnHost = readInput(message, default="Y").upper() != 'N'
|
||||
|
||||
kb.skipVulnHost = readInput(message, default="Y", boolean=True)
|
||||
|
||||
testSqlInj = not kb.skipVulnHost
|
||||
|
||||
if not testSqlInj:
|
||||
@@ -332,9 +334,8 @@ def start():
|
||||
continue
|
||||
|
||||
message += "\ndo you want to test this form? [Y/n/q] "
|
||||
test = readInput(message, default="Y")
|
||||
|
||||
if not test or test[0] in ("y", "Y"):
|
||||
if readInput(message, default='Y', boolean=True):
|
||||
if conf.method != HTTPMETHOD.GET:
|
||||
message = "Edit %s data [default: %s]%s: " % (conf.method, urlencode(conf.data) if conf.data else "None", " (Warning: blank fields detected)" if conf.data and extractRegexResult(EMPTY_FORM_FIELDS_REGEX, conf.data) else "")
|
||||
conf.data = readInput(message, default=conf.data)
|
||||
@@ -359,14 +360,12 @@ def start():
|
||||
|
||||
else:
|
||||
message += "\ndo you want to test this URL? [Y/n/q]"
|
||||
test = readInput(message, default="Y")
|
||||
choice = readInput(message, default='Y').strip().upper()
|
||||
|
||||
if not test or test[0] in ("y", "Y"):
|
||||
pass
|
||||
elif test[0] in ("n", "N"):
|
||||
if choice == 'N':
|
||||
dataToStdout(os.linesep)
|
||||
continue
|
||||
elif test[0] in ("q", "Q"):
|
||||
elif choice == 'Q':
|
||||
break
|
||||
|
||||
infoMsg = "testing URL '%s'" % targetUrl
|
||||
@@ -543,9 +542,8 @@ def start():
|
||||
|
||||
msg = "%s parameter '%s' " % (injection.place, injection.parameter)
|
||||
msg += "is vulnerable. Do you want to keep testing the others (if any)? [y/N] "
|
||||
test = readInput(msg, default="N")
|
||||
|
||||
if test[0] not in ("y", "Y"):
|
||||
if not readInput(msg, default='N', boolean=True):
|
||||
proceed = False
|
||||
paramKey = (conf.hostname, conf.path, None, None)
|
||||
kb.testedParams.add(paramKey)
|
||||
@@ -629,9 +627,7 @@ def start():
|
||||
if kb.injection.place is not None and kb.injection.parameter is not None:
|
||||
if conf.multipleTargets:
|
||||
message = "do you want to exploit this SQL injection? [Y/n] "
|
||||
exploit = readInput(message, default="Y")
|
||||
|
||||
condition = not exploit or exploit[0] in ("y", "Y")
|
||||
condition = readInput(message, default='Y', boolean=True)
|
||||
else:
|
||||
condition = True
|
||||
|
||||
@@ -644,13 +640,11 @@ def start():
|
||||
logger.warn(warnMsg)
|
||||
|
||||
message = "do you want to skip to the next target in list? [Y/n/q]"
|
||||
test = readInput(message, default="Y")
|
||||
choice = readInput(message, default='Y').strip().upper()
|
||||
|
||||
if not test or test[0] in ("y", "Y"):
|
||||
pass
|
||||
elif test[0] in ("n", "N"):
|
||||
if choice == 'N':
|
||||
return False
|
||||
elif test[0] in ("q", "Q"):
|
||||
elif choice == 'Q':
|
||||
raise SqlmapUserQuitException
|
||||
else:
|
||||
raise
|
||||
|
||||
Reference in New Issue
Block a user