diff --git a/lib/core/convert.py b/lib/core/convert.py index 6f4320579..7ea5baf02 100644 --- a/lib/core/convert.py +++ b/lib/core/convert.py @@ -101,11 +101,29 @@ def filterNone(values): # Cross-referenced function def isListLike(value): # Cross-referenced function raise NotImplementedError +def shellExec(cmd): # Cross-referenced function + raise NotImplementedError + def stdoutEncode(value): value = value or "" + if IS_WIN and kb.get("codePage", -1) is None: + output = shellExec("chcp") + match = re.search(r": (\d{3,})", output or "") + + if match: + try: + candidate = "cp%s" % match.group(1) + codecs.lookup(candidate) + except LookupError: + pass + else: + kb.codePage = candidate + + kb.codePage = kb.codePage or "" + if isinstance(value, six.text_type) and PYVERSION < "3.6": - encoding = sys.stdout.encoding or UNICODE_ENCODING + encoding = kb.get("codePage") or sys.stdout.encoding or UNICODE_ENCODING while True: try: diff --git a/lib/core/option.py b/lib/core/option.py index 7228ba0bf..78cd96e29 100644 --- a/lib/core/option.py +++ b/lib/core/option.py @@ -1872,6 +1872,7 @@ def _setKnowledgeBaseAttributes(flushAll=True): kb.chars.stop = "%s%s%s" % (KB_CHARS_BOUNDARY_CHAR, randomStr(length=3, alphabet=KB_CHARS_LOW_FREQUENCY_ALPHABET), KB_CHARS_BOUNDARY_CHAR) kb.chars.at, kb.chars.space, kb.chars.dollar, kb.chars.hash_ = ("%s%s%s" % (KB_CHARS_BOUNDARY_CHAR, _, KB_CHARS_BOUNDARY_CHAR) for _ in randomStr(length=4, lowercase=True)) + kb.codePage = None kb.columnExistsChoice = None kb.commonOutputs = None kb.connErrorChoice = None diff --git a/lib/core/patch.py b/lib/core/patch.py index 18a68a6c7..ac7384332 100644 --- a/lib/core/patch.py +++ b/lib/core/patch.py @@ -24,6 +24,7 @@ from lib.core.common import getSafeExString from lib.core.common import isListLike from lib.core.common import singleTimeWarnMessage from lib.core.common import readInput +from lib.core.common import shellExec from lib.core.convert import stdoutEncode from lib.core.option import _setHTTPHandlers from lib.core.option import setVerbosity @@ -63,6 +64,7 @@ def resolveCrossReferences(): lib.core.common.getPageTemplate = getPageTemplate lib.core.convert.filterNone = filterNone lib.core.convert.isListLike = isListLike + lib.core.convert.shellExec = shellExec lib.core.convert.singleTimeWarnMessage = singleTimeWarnMessage lib.core.option._pympTempLeakPatch = pympTempLeakPatch lib.request.connect.setHTTPHandlers = _setHTTPHandlers diff --git a/lib/core/settings.py b/lib/core/settings.py index b5c8802a6..e80e6bfa7 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -18,7 +18,7 @@ from lib.core.enums import OS from thirdparty.six import unichr as _unichr # sqlmap version (...) -VERSION = "1.3.5.123" +VERSION = "1.3.5.124" TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable" 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)