Skip to content

Commit 63073a1

Browse files
committed
15% speedup in some cases (avoiding heuristic char detection)
1 parent 295cd15 commit 63073a1

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

lib/core/settings.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@
1616
from lib.core.enums import DBMS
1717
from lib.core.enums import DBMS_DIRECTORY_NAME
1818
from lib.core.enums import OS
19+
from thirdparty import six
1920
from thirdparty.six import unichr as _unichr
2021

2122
# sqlmap version (<major>.<minor>.<month>.<monthly commit>)
22-
VERSION = "1.5.6.0"
23+
VERSION = "1.5.6.1"
2324
TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable"
2425
TYPE_COLORS = {"dev": 33, "stable": 90, "pip": 34}
2526
VERSION_STRING = "sqlmap/%s#%s" % ('.'.join(VERSION.split('.')[:-1]) if VERSION.count('.') > 2 and VERSION.split('.')[-1] == '0' else VERSION, TYPE)
@@ -906,6 +907,9 @@
906907
# Letters of lower frequency used in kb.chars
907908
KB_CHARS_LOW_FREQUENCY_ALPHABET = "zqxjkvbp"
908909

910+
# Printable bytes
911+
PRINTABLE_BYTES = set(bytes(string.printable, "ascii") if six.PY3 else string.printable)
912+
909913
# SQL keywords used for splitting in HTTP chunked transfer encoded requests (switch --chunk)
910914
HTTP_CHUNKED_SPLIT_KEYWORDS = ("SELECT", "UPDATE", "INSERT", "FROM", "LOAD_FILE", "UNION", "information_schema", "sysdatabases", "msysaccessobjects", "msysqueries", "sysmodules")
911915

lib/request/basic.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
from lib.core.settings import MAX_CONNECTION_TOTAL_SIZE
4949
from lib.core.settings import META_CHARSET_REGEX
5050
from lib.core.settings import PARSE_HEADERS_LIMIT
51+
from lib.core.settings import PRINTABLE_BYTES
5152
from lib.core.settings import SELECT_FROM_TABLE_REGEX
5253
from lib.core.settings import UNICODE_ENCODING
5354
from lib.core.settings import VIEWSTATE_REGEX
@@ -324,7 +325,7 @@ def decodePage(page, contentEncoding, contentType, percentDecode=True):
324325

325326
metaCharset = checkCharEncoding(extractRegexResult(META_CHARSET_REGEX, page))
326327

327-
if (any((httpCharset, metaCharset)) and not all((httpCharset, metaCharset))) or (httpCharset == metaCharset and all((httpCharset, metaCharset))):
328+
if (any((httpCharset, metaCharset)) and (not all((httpCharset, metaCharset)) or isinstance(page, six.binary_type) and all(_ in PRINTABLE_BYTES for _ in page))) or (httpCharset == metaCharset and all((httpCharset, metaCharset))):
328329
kb.pageEncoding = httpCharset or metaCharset # Reference: http://bytes.com/topic/html-css/answers/154758-http-equiv-vs-true-header-has-precedence
329330
debugMsg = "declared web page charset '%s'" % kb.pageEncoding
330331
singleTimeLogMessage(debugMsg, logging.DEBUG, debugMsg)

0 commit comments

Comments
 (0)