Implements option --retry-on (#4876)

This commit is contained in:
Miroslav Stampar 2021-11-01 21:50:16 +01:00
parent fc9875fc12
commit 9e17babe7b
6 changed files with 26 additions and 1 deletions

View File

@ -2648,6 +2648,13 @@ def _basicOptionValidation():
errMsg = "invalid regular expression '%s' ('%s')" % (conf.paramExclude, getSafeExString(ex)) errMsg = "invalid regular expression '%s' ('%s')" % (conf.paramExclude, getSafeExString(ex))
raise SqlmapSyntaxException(errMsg) raise SqlmapSyntaxException(errMsg)
if conf.retryOn:
try:
re.compile(conf.retryOn)
except Exception as ex:
errMsg = "invalid regular expression '%s' ('%s')" % (conf.retryOn, getSafeExString(ex))
raise SqlmapSyntaxException(errMsg)
if conf.cookieDel and len(conf.cookieDel): if conf.cookieDel and len(conf.cookieDel):
errMsg = "option '--cookie-del' should contain a single character (e.g. ';')" errMsg = "option '--cookie-del' should contain a single character (e.g. ';')"
raise SqlmapSyntaxException(errMsg) raise SqlmapSyntaxException(errMsg)

View File

@ -54,6 +54,7 @@ optDict = {
"delay": "float", "delay": "float",
"timeout": "float", "timeout": "float",
"retries": "integer", "retries": "integer",
"retryOn": "string",
"rParam": "string", "rParam": "string",
"safeUrl": "string", "safeUrl": "string",
"safePost": "string", "safePost": "string",

View File

@ -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.10.21" VERSION = "1.5.11.0"
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)

View File

@ -246,6 +246,9 @@ def cmdLineParser(argv=None):
request.add_argument("--retries", dest="retries", type=int, request.add_argument("--retries", dest="retries", type=int,
help="Retries when the connection timeouts (default %d)" % defaults.retries) help="Retries when the connection timeouts (default %d)" % defaults.retries)
request.add_argument("--retry-on", dest="retryOn",
help="Retry request on regexp matching content (e.g. \"drop\")")
request.add_argument("--randomize", dest="rParam", request.add_argument("--randomize", dest="rParam",
help="Randomly change value for given parameter(s)") help="Randomly change value for given parameter(s)")

View File

@ -909,6 +909,17 @@ class Connect(object):
socket.setdefaulttimeout(conf.timeout) socket.setdefaulttimeout(conf.timeout)
if conf.retryOn and re.search(conf.retryOn, page, re.I):
if threadData.retriesCount < conf.retries:
warnMsg = "forced retry of the request because of undesired page content"
logger.warn(warnMsg)
return Connect._retryProxy(**kwargs)
else:
errMsg = "unable to get the page content not matching "
errMsg += "the given regular expression '%s'. Please use as high " % conf.retryOn
errMsg += "value for option '--retries' as possible (e.g. 20 or more)"
raise SqlmapConnectionException(errMsg)
processResponse(page, responseHeaders, code, status) processResponse(page, responseHeaders, code, status)
if not skipLogTraffic: if not skipLogTraffic:

View File

@ -160,6 +160,9 @@ timeout = 30
# Default: 3 # Default: 3
retries = 3 retries = 3
# Retry request on regexp matching content.
retries = 3
# Randomly change value for the given parameter. # Randomly change value for the given parameter.
rParam = rParam =