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

Skip to content

Commit 0977f6d

Browse files
committed
Bug fix (disable HTML decoding in XSS checks)
1 parent f550a22 commit 0977f6d

4 files changed

Lines changed: 42 additions & 36 deletions

File tree

lib/controller/checks.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,6 +1104,7 @@ def _(page):
11041104
logger.warn(infoMsg)
11051105

11061106
kb.heuristicMode = True
1107+
kb.disableHtmlDecoding = True
11071108

11081109
randStr1, randStr2 = randomStr(NON_SQLI_CHECK_PREFIX_SUFFIX_LENGTH), randomStr(NON_SQLI_CHECK_PREFIX_SUFFIX_LENGTH)
11091110
value = "%s%s%s" % (randStr1, DUMMY_NON_SQLI_CHECK_APPENDIX, randStr2)
@@ -1123,6 +1124,7 @@ def _(page):
11231124
logger.info(infoMsg)
11241125
break
11251126

1127+
kb.disableHtmlDecoding = False
11261128
kb.heuristicMode = False
11271129

11281130
return kb.heuristicTest

lib/core/option.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1872,6 +1872,7 @@ def _setKnowledgeBaseAttributes(flushAll=True):
18721872

18731873
kb.delayCandidates = TIME_DELAY_CANDIDATES * [0]
18741874
kb.dep = None
1875+
kb.disableHtmlDecoding = False
18751876
kb.dnsMode = False
18761877
kb.dnsTest = None
18771878
kb.docRoot = None

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.11.75"
21+
VERSION = "1.3.11.76"
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)

lib/request/basic.py

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -334,41 +334,44 @@ def decodePage(page, contentEncoding, contentType, percentDecode=True):
334334

335335
# can't do for all responses because we need to support binary files too
336336
if isinstance(page, six.binary_type) and "text/" in contentType:
337-
# e.g. &#x9;&#195;&#235;&#224;&#226;&#224;
338-
if b"&#" in page:
339-
page = re.sub(b"&#x([0-9a-f]{1,2});", lambda _: decodeHex(_.group(1) if len(_.group(1)) == 2 else "0%s" % _.group(1)), page)
340-
page = re.sub(b"&#(\\d{1,3});", lambda _: six.int2byte(int(_.group(1))) if int(_.group(1)) < 256 else _.group(0), page)
341-
342-
# e.g. %20%28%29
343-
if percentDecode:
344-
if b"%" in page:
345-
page = re.sub(b"%([0-9a-fA-F]{2})", lambda _: decodeHex(_.group(1)), page)
346-
347-
# e.g. &amp;
348-
page = re.sub(b"&([^;]+);", lambda _: six.int2byte(HTML_ENTITIES[getText(_.group(1))]) if HTML_ENTITIES.get(getText(_.group(1)), 256) < 256 else _.group(0), page)
349-
350-
kb.pageEncoding = kb.pageEncoding or checkCharEncoding(getHeuristicCharEncoding(page))
351-
352-
if (kb.pageEncoding or "").lower() == "utf-8-sig":
353-
kb.pageEncoding = "utf-8"
354-
if page and page.startswith("\xef\xbb\xbf"): # Reference: https://docs.python.org/2/library/codecs.html (Note: noticed problems when "utf-8-sig" is left to Python for handling)
355-
page = page[3:]
356-
357-
page = getUnicode(page, kb.pageEncoding)
358-
359-
# e.g. &#8217;&#8230;&#8482;
360-
if "&#" in page:
361-
def _(match):
362-
retVal = match.group(0)
363-
try:
364-
retVal = _unichr(int(match.group(1)))
365-
except (ValueError, OverflowError):
366-
pass
367-
return retVal
368-
page = re.sub(r"&#(\d+);", _, page)
369-
370-
# e.g. &zeta;
371-
page = re.sub(r"&([^;]+);", lambda _: _unichr(HTML_ENTITIES[_.group(1)]) if HTML_ENTITIES.get(_.group(1), 0) > 255 else _.group(0), page)
337+
if not kb.disableHtmlDecoding:
338+
# e.g. &#x9;&#195;&#235;&#224;&#226;&#224;
339+
if b"&#" in page:
340+
page = re.sub(b"&#x([0-9a-f]{1,2});", lambda _: decodeHex(_.group(1) if len(_.group(1)) == 2 else "0%s" % _.group(1)), page)
341+
page = re.sub(b"&#(\\d{1,3});", lambda _: six.int2byte(int(_.group(1))) if int(_.group(1)) < 256 else _.group(0), page)
342+
343+
# e.g. %20%28%29
344+
if percentDecode:
345+
if b"%" in page:
346+
page = re.sub(b"%([0-9a-fA-F]{2})", lambda _: decodeHex(_.group(1)), page)
347+
348+
# e.g. &amp;
349+
page = re.sub(b"&([^;]+);", lambda _: six.int2byte(HTML_ENTITIES[getText(_.group(1))]) if HTML_ENTITIES.get(getText(_.group(1)), 256) < 256 else _.group(0), page)
350+
351+
kb.pageEncoding = kb.pageEncoding or checkCharEncoding(getHeuristicCharEncoding(page))
352+
353+
if (kb.pageEncoding or "").lower() == "utf-8-sig":
354+
kb.pageEncoding = "utf-8"
355+
if page and page.startswith("\xef\xbb\xbf"): # Reference: https://docs.python.org/2/library/codecs.html (Note: noticed problems when "utf-8-sig" is left to Python for handling)
356+
page = page[3:]
357+
358+
page = getUnicode(page, kb.pageEncoding)
359+
360+
# e.g. &#8217;&#8230;&#8482;
361+
if "&#" in page:
362+
def _(match):
363+
retVal = match.group(0)
364+
try:
365+
retVal = _unichr(int(match.group(1)))
366+
except (ValueError, OverflowError):
367+
pass
368+
return retVal
369+
page = re.sub(r"&#(\d+);", _, page)
370+
371+
# e.g. &zeta;
372+
page = re.sub(r"&([^;]+);", lambda _: _unichr(HTML_ENTITIES[_.group(1)]) if HTML_ENTITIES.get(_.group(1), 0) > 255 else _.group(0), page)
373+
else:
374+
page = getUnicode(page, kb.pageEncoding)
372375

373376
return page
374377

0 commit comments

Comments
 (0)