From f1fd080ba5caf9ec7f9cdbb2951a5d5d6cfb91ae Mon Sep 17 00:00:00 2001 From: Miroslav Stampar Date: Mon, 10 Aug 2020 21:54:58 +0200 Subject: [PATCH] Minor improvement --- lib/core/convert.py | 26 +++++++++++++++++++++++--- lib/core/settings.py | 2 +- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/lib/core/convert.py b/lib/core/convert.py index 740ef7c02..1feae196e 100644 --- a/lib/core/convert.py +++ b/lib/core/convert.py @@ -198,6 +198,8 @@ def decodeBase64(value, binary=True, encoding=None): True >>> decodeBase64("MTIz", binary=False) '123' + >>> decodeBase64("A-B_CD") == decodeBase64("A+B/CD") + True >>> decodeBase64(b"MTIzNA") == b"1234" True >>> decodeBase64("MTIzNA") == b"1234" @@ -206,12 +208,22 @@ def decodeBase64(value, binary=True, encoding=None): True """ + if value is None: + return None + padding = b'=' if isinstance(value, bytes) else '=' # Reference: https://stackoverflow.com/a/49459036 if not value.endswith(padding): value += 3 * padding + # Reference: https://en.wikipedia.org/wiki/Base64#URL_applications + # Reference: https://perldoc.perl.org/MIME/Base64.html + if isinstance(value, bytes): + value = value.replace(b'-', b'+').replace(b'_', b'/') + else: + value = value.replace('-', '+').replace('_', '/') + retVal = base64.b64decode(value) if not binary: @@ -219,16 +231,21 @@ def decodeBase64(value, binary=True, encoding=None): return retVal -def encodeBase64(value, binary=True, encoding=None): +def encodeBase64(value, binary=True, encoding=None, padding=True): """ Returns a decoded representation of provided Base64 value >>> encodeBase64(b"123") == b"MTIz" True - >>> encodeBase64(u"123", binary=False) - 'MTIz' + >>> encodeBase64(u"1234", binary=False) + 'MTIzNA==' + >>> encodeBase64(u"1234", binary=False, padding=False) + 'MTIzNA' """ + if value is None: + return None + if isinstance(value, six.text_type): value = value.encode(encoding or UNICODE_ENCODING) @@ -237,6 +254,9 @@ def encodeBase64(value, binary=True, encoding=None): if not binary: retVal = getText(retVal, encoding) + if not padding: + retVal = retVal.rstrip(b'=' if isinstance(retVal, bytes) else '=') + return retVal def getBytes(value, encoding=None, errors="strict", unsafe=True): diff --git a/lib/core/settings.py b/lib/core/settings.py index f1ba0bfb7..9e789fe64 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.4.8.5" +VERSION = "1.4.8.6" 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)