From 7a179889a3242ac2b71fd5e502fe56e99fa49418 Mon Sep 17 00:00:00 2001 From: Miroslav Stampar Date: Wed, 8 May 2019 17:21:40 +0200 Subject: [PATCH] Fixes #3637 --- lib/core/common.py | 4 +++- lib/core/dump.py | 5 +++-- lib/core/settings.py | 2 +- thirdparty/magic/magic.py | 2 +- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/core/common.py b/lib/core/common.py index 30e9a3394..c1491d953 100644 --- a/lib/core/common.py +++ b/lib/core/common.py @@ -1800,9 +1800,11 @@ def getFileType(filePath): """ try: - desc = getUnicode(magic.from_file(filePath) or "") + desc = magic.from_file(filePath) or magic.MAGIC_UNKNOWN_FILETYPE except: desc = magic.MAGIC_UNKNOWN_FILETYPE + finally: + desc = getText(desc) if desc == magic.MAGIC_UNKNOWN_FILETYPE: content = openFile(filePath, "rb", encoding=None).read() diff --git a/lib/core/dump.py b/lib/core/dump.py index 9b227b1c0..333b09b0b 100644 --- a/lib/core/dump.py +++ b/lib/core/dump.py @@ -18,6 +18,7 @@ from lib.core.common import checkFile from lib.core.common import dataToDumpFile from lib.core.common import dataToStdout from lib.core.common import getSafeExString +from lib.core.common import getText from lib.core.common import isListLike from lib.core.common import isMultiThreadMode from lib.core.common import normalizeUnicode @@ -613,8 +614,8 @@ class Dump(object): if len(value) > MIN_BINARY_DISK_DUMP_SIZE and r'\x' in value: try: - mimetype = magic.from_buffer(value, mime=True) - if any(mimetype.startswith(_) for _ in (b"application", b"image")): + mimetype = getText(magic.from_buffer(value, mime=True)) + if any(mimetype.startswith(_) for _ in ("application", "image")): if not os.path.isdir(dumpDbPath): os.makedirs(dumpDbPath) diff --git a/lib/core/settings.py b/lib/core/settings.py index 1d5cf5ca0..9a04e5dd6 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -18,7 +18,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.3.5.58" +VERSION = "1.3.5.59" 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) diff --git a/thirdparty/magic/magic.py b/thirdparty/magic/magic.py index 0c077f5b1..c99c17041 100644 --- a/thirdparty/magic/magic.py +++ b/thirdparty/magic/magic.py @@ -223,4 +223,4 @@ MAGIC_NO_CHECK_ASCII = 0x020000 # Don't check for ascii files MAGIC_NO_CHECK_TROFF = 0x040000 # Don't check ascii/troff MAGIC_NO_CHECK_FORTRAN = 0x080000 # Don't check ascii/fortran MAGIC_NO_CHECK_TOKENS = 0x100000 # Don't check ascii/tokens -MAGIC_UNKNOWN_FILETYPE = "unknown" \ No newline at end of file +MAGIC_UNKNOWN_FILETYPE = b"unknown" \ No newline at end of file