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

Skip to content

Commit 1248fe5

Browse files
committed
Bug fix (CFM tends to HTML encode non-alphanumeric chars in error reports - paths weren't recognized)
1 parent daeb281 commit 1248fe5

3 files changed

Lines changed: 38 additions & 41 deletions

File tree

lib/core/settings.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from lib.core.enums import OS
2020

2121
# sqlmap version (<major>.<minor>.<month>.<monthly commit>)
22-
VERSION = "1.3.2.26"
22+
VERSION = "1.3.2.27"
2323
TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable"
2424
TYPE_COLORS = {"dev": 33, "stable": 90, "pip": 34}
2525
VERSION_STRING = "sqlmap/%s#%s" % ('.'.join(VERSION.split('.')[:-1]) if VERSION.count('.') > 2 and VERSION.split('.')[-1] == '0' else VERSION, TYPE)
@@ -330,7 +330,7 @@
330330
SESSION_SQLITE_FILE = "session.sqlite"
331331

332332
# Regular expressions used for finding file paths in error messages
333-
FILE_PATH_REGEXES = (r"<b>(?P<result>[^<>]+?)</b> on line \d+", r"in (?P<result>[^<>'\"]+?)['\"]? on line \d+", r"(?:[>(\[\s])(?P<result>[A-Za-z]:[\\/][\w. \\/-]*)", r"(?:[>(\[\s])(?P<result>/\w[/\w.~-]+)", r"href=['\"]file://(?P<result>/[^'\"]+)")
333+
FILE_PATH_REGEXES = (r"<b>(?P<result>[^<>]+?)</b> on line \d+", r"\bin (?P<result>[^<>'\"]+?)['\"]? on line \d+", r"(?:[>(\[\s])(?P<result>[A-Za-z]:[\\/][\w. \\/-]*)", r"(?:[>(\[\s])(?P<result>/\w[/\w.~-]+)", r"\bhref=['\"]file://(?P<result>/[^'\"]+)", r"\bin <b>(?P<result>[^<]+): line \d+")
334334

335335
# Regular expressions used for parsing error messages (--parse-errors)
336336
ERROR_PARSING_REGEXES = (

lib/request/basic.py

Lines changed: 34 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -313,43 +313,40 @@ def decodePage(page, contentEncoding, contentType):
313313

314314
# can't do for all responses because we need to support binary files too
315315
if not isinstance(page, unicode) and "text/" in contentType:
316-
if kb.heuristicMode:
317-
kb.pageEncoding = kb.pageEncoding or checkCharEncoding(getHeuristicCharEncoding(page))
318-
page = getUnicode(page, kb.pageEncoding)
319-
else:
320-
# e.g. &#195;&#235;&#224;&#226;&#224;
321-
if "&#" in page:
322-
page = re.sub(r"&#(\d{1,3});", lambda _: chr(int(_.group(1))) if int(_.group(1)) < 256 else _.group(0), page)
323-
324-
# e.g. %20%28%29
325-
if "%" in page:
326-
page = re.sub(r"%([0-9a-fA-F]{2})", lambda _: _.group(1).decode("hex"), page)
327-
328-
# e.g. &amp;
329-
page = re.sub(r"&([^;]+);", lambda _: chr(htmlEntities[_.group(1)]) if htmlEntities.get(_.group(1), 256) < 256 else _.group(0), page)
330-
331-
kb.pageEncoding = kb.pageEncoding or checkCharEncoding(getHeuristicCharEncoding(page))
332-
333-
if (kb.pageEncoding or "").lower() == "utf-8-sig":
334-
kb.pageEncoding = "utf-8"
335-
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)
336-
page = page[3:]
337-
338-
page = getUnicode(page, kb.pageEncoding)
339-
340-
# e.g. &#8217;&#8230;&#8482;
341-
if "&#" in page:
342-
def _(match):
343-
retVal = match.group(0)
344-
try:
345-
retVal = unichr(int(match.group(1)))
346-
except (ValueError, OverflowError):
347-
pass
348-
return retVal
349-
page = re.sub(r"&#(\d+);", _, page)
350-
351-
# e.g. &zeta;
352-
page = re.sub(r"&([^;]+);", lambda _: unichr(htmlEntities[_.group(1)]) if htmlEntities.get(_.group(1), 0) > 255 else _.group(0), page)
316+
# e.g. &#x9;&#195;&#235;&#224;&#226;&#224;
317+
if "&#" in page:
318+
page = re.sub(r"&#x([0-9a-f]{1,2});", lambda _: (_.group(1) if len(_.group(1)) == 2 else "0%s" % _.group(1)).decode("hex"), page)
319+
page = re.sub(r"&#(\d{1,3});", lambda _: chr(int(_.group(1))) if int(_.group(1)) < 256 else _.group(0), page)
320+
321+
# e.g. %20%28%29
322+
if "%" in page:
323+
page = re.sub(r"%([0-9a-fA-F]{2})", lambda _: _.group(1).decode("hex"), page)
324+
325+
# e.g. &amp;
326+
page = re.sub(r"&([^;]+);", lambda _: chr(htmlEntities[_.group(1)]) if htmlEntities.get(_.group(1), 256) < 256 else _.group(0), page)
327+
328+
kb.pageEncoding = kb.pageEncoding or checkCharEncoding(getHeuristicCharEncoding(page))
329+
330+
if (kb.pageEncoding or "").lower() == "utf-8-sig":
331+
kb.pageEncoding = "utf-8"
332+
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)
333+
page = page[3:]
334+
335+
page = getUnicode(page, kb.pageEncoding)
336+
337+
# e.g. &#8217;&#8230;&#8482;
338+
if "&#" in page:
339+
def _(match):
340+
retVal = match.group(0)
341+
try:
342+
retVal = unichr(int(match.group(1)))
343+
except (ValueError, OverflowError):
344+
pass
345+
return retVal
346+
page = re.sub(r"&#(\d+);", _, page)
347+
348+
# e.g. &zeta;
349+
page = re.sub(r"&([^;]+);", lambda _: unichr(htmlEntities[_.group(1)]) if htmlEntities.get(_.group(1), 0) > 255 else _.group(0), page)
353350

354351
return page
355352

txt/checksum.md5

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ d5ef43fe3cdd6c2602d7db45651f9ceb lib/core/readlineng.py
5050
7d8a22c582ad201f65b73225e4456170 lib/core/replication.py
5151
3179d34f371e0295dd4604568fb30bcd lib/core/revision.py
5252
d6269c55789f78cf707e09a0f5b45443 lib/core/session.py
53-
bb7fceee8b646ac156273ecdc2d1d783 lib/core/settings.py
53+
1ab84830277bc8690adc2e2db916bb8f lib/core/settings.py
5454
4483b4a5b601d8f1c4281071dff21ecc lib/core/shell.py
5555
10fd19b0716ed261e6d04f311f6f527c lib/core/subprocessng.py
5656
43772ea73e9e3d446f782af591cb4eda lib/core/target.py
@@ -70,7 +70,7 @@ fb6be55d21a70765e35549af2484f762 lib/parse/__init__.py
7070
adcecd2d6a8667b22872a563eb83eac0 lib/parse/payloads.py
7171
993104046c7d97120613409ef7780c76 lib/parse/sitemap.py
7272
e4ea70bcd461f5176867dcd89d372386 lib/request/basicauthhandler.py
73-
97b7577fdfe3d8537fe9ea3a070d0507 lib/request/basic.py
73+
b23163d485e0dbc038cbf1ba80be11da lib/request/basic.py
7474
fc25d951217077fe655ed2a3a81552ae lib/request/comparison.py
7575
2fde12a95133b26699e26a5c56311c38 lib/request/connect.py
7676
43005bd6a78e9cf0f3ed2283a1cb122e lib/request/direct.py

0 commit comments

Comments
 (0)