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

Skip to content

Commit c8a4e63

Browse files
committed
Minor improvement for --forms
1 parent 08d3228 commit c8a4e63

3 files changed

Lines changed: 59 additions & 50 deletions

File tree

lib/controller/controller.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ def start():
374374
message += "\nCookie: %s" % conf.cookie
375375

376376
if conf.data is not None:
377-
message += "\n%s data: %s" % ((conf.method if conf.method != HTTPMETHOD.GET else conf.method) or HTTPMETHOD.POST, urlencode(conf.data) if conf.data else "")
377+
message += "\n%s data: %s" % ((conf.method if conf.method != HTTPMETHOD.GET else conf.method) or HTTPMETHOD.POST, urlencode(conf.data or "") if re.search(r"\A\s*[<{]", conf.data or "") is None else conf.data)
378378

379379
if conf.forms and conf.method:
380380
if conf.method == HTTPMETHOD.GET and targetUrl.find("?") == -1:
@@ -389,7 +389,7 @@ def start():
389389
break
390390
else:
391391
if conf.method != HTTPMETHOD.GET:
392-
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 "")
392+
message = "Edit %s data [default: %s]%s: " % (conf.method, urlencode(conf.data or "") if re.search(r"\A\s*[<{]", conf.data or "None") is None else conf.data, " (Warning: blank fields detected)" if conf.data and extractRegexResult(EMPTY_FORM_FIELDS_REGEX, conf.data) else "")
393393
conf.data = readInput(message, default=conf.data)
394394
conf.data = _randomFillBlankFields(conf.data)
395395
conf.data = urldecode(conf.data) if conf.data and urlencode(DEFAULT_GET_POST_DELIMITER, None) not in conf.data else conf.data

lib/core/common.py

Lines changed: 56 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -4417,59 +4417,52 @@ def geturl(self):
44174417
except:
44184418
pass
44194419

4420-
if forms:
4421-
for form in forms:
4422-
try:
4423-
for control in form.controls:
4424-
if hasattr(control, "items") and not any((control.disabled, control.readonly)):
4425-
# if control has selectable items select first non-disabled
4426-
for item in control.items:
4427-
if not item.disabled:
4428-
if not item.selected:
4429-
item.selected = True
4430-
break
4431-
4432-
if conf.crawlExclude and re.search(conf.crawlExclude, form.action or ""):
4433-
dbgMsg = "skipping '%s'" % form.action
4434-
logger.debug(dbgMsg)
4435-
continue
4420+
for form in forms or []:
4421+
try:
4422+
for control in form.controls:
4423+
if hasattr(control, "items") and not any((control.disabled, control.readonly)):
4424+
# if control has selectable items select first non-disabled
4425+
for item in control.items:
4426+
if not item.disabled:
4427+
if not item.selected:
4428+
item.selected = True
4429+
break
44364430

4437-
request = form.click()
4438-
except (ValueError, TypeError) as ex:
4439-
errMsg = "there has been a problem while "
4440-
errMsg += "processing page forms ('%s')" % getSafeExString(ex)
4441-
if raise_:
4442-
raise SqlmapGenericException(errMsg)
4443-
else:
4444-
logger.debug(errMsg)
4431+
if conf.crawlExclude and re.search(conf.crawlExclude, form.action or ""):
4432+
dbgMsg = "skipping '%s'" % form.action
4433+
logger.debug(dbgMsg)
4434+
continue
4435+
4436+
request = form.click()
4437+
except (ValueError, TypeError) as ex:
4438+
errMsg = "there has been a problem while "
4439+
errMsg += "processing page forms ('%s')" % getSafeExString(ex)
4440+
if raise_:
4441+
raise SqlmapGenericException(errMsg)
44454442
else:
4446-
url = urldecode(request.get_full_url(), kb.pageEncoding)
4447-
method = request.get_method()
4448-
data = request.data
4449-
data = urldecode(data, kb.pageEncoding, spaceplus=False)
4443+
logger.debug(errMsg)
4444+
else:
4445+
url = urldecode(request.get_full_url(), kb.pageEncoding)
4446+
method = request.get_method()
4447+
data = request.data
4448+
data = urldecode(data, kb.pageEncoding, spaceplus=False)
44504449

4451-
if not data and method and method.upper() == HTTPMETHOD.POST:
4452-
debugMsg = "invalid POST form with blank data detected"
4453-
logger.debug(debugMsg)
4454-
continue
4450+
if not data and method and method.upper() == HTTPMETHOD.POST:
4451+
debugMsg = "invalid POST form with blank data detected"
4452+
logger.debug(debugMsg)
4453+
continue
44554454

4456-
# flag to know if we are dealing with the same target host
4457-
_ = checkSameHost(response.geturl(), url)
4455+
# flag to know if we are dealing with the same target host
4456+
_ = checkSameHost(response.geturl(), url)
44584457

4459-
if conf.scope:
4460-
if not re.search(conf.scope, url, re.I):
4461-
continue
4462-
elif not _:
4458+
if conf.scope:
4459+
if not re.search(conf.scope, url, re.I):
44634460
continue
4464-
else:
4465-
target = (url, method, data, conf.cookie, None)
4466-
retVal.add(target)
4467-
else:
4468-
errMsg = "there were no forms found at the given target URL"
4469-
if raise_:
4470-
raise SqlmapGenericException(errMsg)
4471-
else:
4472-
logger.debug(errMsg)
4461+
elif not _:
4462+
continue
4463+
else:
4464+
target = (url, method, data, conf.cookie, None)
4465+
retVal.add(target)
44734466

44744467
for match in re.finditer(r"\.post\(['\"]([^'\"]*)['\"],\s*\{([^}]*)\}", content):
44754468
url = _urllib.parse.urljoin(url, htmlUnescape(match.group(1)))
@@ -4481,6 +4474,22 @@ def geturl(self):
44814474
data = data.rstrip(DEFAULT_GET_POST_DELIMITER)
44824475
retVal.add((url, HTTPMETHOD.POST, data, conf.cookie, None))
44834476

4477+
for match in re.finditer(r"(?s)(\w+)\.open\(['\"]POST['\"],\s*['\"]([^'\"]+)['\"]\).*?\1\.send\(([^)]+)\)", content):
4478+
url = _urllib.parse.urljoin(url, htmlUnescape(match.group(2)))
4479+
data = match.group(3)
4480+
4481+
data = re.sub(r"\s*\+\s*[^\s'\"]+|[^\s'\"]+\s*\+\s*", "", data)
4482+
4483+
data = data.strip("['\"]")
4484+
retVal.add((url, HTTPMETHOD.POST, data, conf.cookie, None))
4485+
4486+
if not retVal:
4487+
errMsg = "there were no forms found at the given target URL"
4488+
if raise_:
4489+
raise SqlmapGenericException(errMsg)
4490+
else:
4491+
logger.debug(errMsg)
4492+
44844493
if addToTargets and retVal:
44854494
for target in retVal:
44864495
kb.targets.add(target)

lib/core/settings.py

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

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

0 commit comments

Comments
 (0)