From 69900a6c6efac5c8b43fcee5d8d03dc2afb063b5 Mon Sep 17 00:00:00 2001 From: Miroslav Stampar Date: Thu, 7 Oct 2021 00:29:31 +0200 Subject: [PATCH] Fixes #4849 --- lib/core/common.py | 4 ++-- lib/core/compat.py | 5 +++++ lib/core/settings.py | 2 +- lib/core/testing.py | 1 - lib/request/httpshandler.py | 4 ++-- plugins/dbms/mysql/takeover.py | 6 +++--- plugins/dbms/postgresql/takeover.py | 6 +++--- sqlmap.py | 4 ++-- 8 files changed, 18 insertions(+), 14 deletions(-) diff --git a/lib/core/common.py b/lib/core/common.py index 2e4a69ce4..a6d9acaad 100644 --- a/lib/core/common.py +++ b/lib/core/common.py @@ -11,7 +11,6 @@ import binascii import codecs import contextlib import copy -import distutils.version import functools import getpass import hashlib @@ -47,6 +46,7 @@ from extra.beep.beep import beep from extra.cloak.cloak import decloak from lib.core.bigarray import BigArray from lib.core.compat import cmp +from lib.core.compat import LooseVersion from lib.core.compat import round from lib.core.compat import xrange from lib.core.convert import base64pickle @@ -591,7 +591,7 @@ class Backend(object): if Backend.getVersion() is not None and version is not None: try: - retVal = distutils.version.LooseVersion(Backend.getVersion()) >= distutils.version.LooseVersion(version) + retVal = LooseVersion(Backend.getVersion()) >= LooseVersion(version) except: retVal = str(Backend.getVersion()) >= str(version) diff --git a/lib/core/compat.py b/lib/core/compat.py index 3e8c168fe..50d18695d 100644 --- a/lib/core/compat.py +++ b/lib/core/compat.py @@ -257,3 +257,8 @@ if sys.version_info >= (3, 0): else: xrange = xrange buffer = buffer + +try: + from pkg_resources import parse_version as LooseVersion +except ImportError: + from distutils.version import LooseVersion diff --git a/lib/core/settings.py b/lib/core/settings.py index c208bfc7e..ab12e789b 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -20,7 +20,7 @@ from thirdparty import six from thirdparty.six import unichr as _unichr # sqlmap version (...) -VERSION = "1.5.10.5" +VERSION = "1.5.10.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) diff --git a/lib/core/testing.py b/lib/core/testing.py index f950820e6..3c5014c1d 100644 --- a/lib/core/testing.py +++ b/lib/core/testing.py @@ -24,7 +24,6 @@ from lib.core.common import randomInt from lib.core.common import randomStr from lib.core.common import shellExec from lib.core.compat import round -from lib.core.compat import xrange from lib.core.convert import encodeBase64 from lib.core.data import kb from lib.core.data import logger diff --git a/lib/request/httpshandler.py b/lib/request/httpshandler.py index dcd429afc..26f359d3f 100644 --- a/lib/request/httpshandler.py +++ b/lib/request/httpshandler.py @@ -5,12 +5,12 @@ Copyright (c) 2006-2021 sqlmap developers (https://sqlmap.org/) See the file 'LICENSE' for copying permission """ -import distutils.version import re import socket from lib.core.common import filterNone from lib.core.common import getSafeExString +from lib.core.compat import LooseVersion from lib.core.compat import xrange from lib.core.data import conf from lib.core.data import kb @@ -109,7 +109,7 @@ class HTTPSConnection(_http_client.HTTPSConnection): if not success: errMsg = "can't establish SSL connection" # Reference: https://docs.python.org/2/library/ssl.html - if distutils.version.LooseVersion(PYVERSION) < distutils.version.LooseVersion("2.7.9"): + if LooseVersion(PYVERSION) < LooseVersion("2.7.9"): errMsg += " (please retry with Python >= 2.7.9)" if kb.sslSuccess and not self.retrying: diff --git a/plugins/dbms/mysql/takeover.py b/plugins/dbms/mysql/takeover.py index 1444436dc..b59598443 100644 --- a/plugins/dbms/mysql/takeover.py +++ b/plugins/dbms/mysql/takeover.py @@ -5,7 +5,6 @@ Copyright (c) 2006-2021 sqlmap developers (https://sqlmap.org/) See the file 'LICENSE' for copying permission """ -import distutils.version import os from lib.core.agent import agent @@ -17,6 +16,7 @@ from lib.core.common import normalizePath from lib.core.common import ntToPosixSlashes from lib.core.common import randomStr from lib.core.common import unArrayizeValue +from lib.core.compat import LooseVersion from lib.core.data import kb from lib.core.data import logger from lib.core.data import paths @@ -38,13 +38,13 @@ class Takeover(GenericTakeover): banVer = kb.bannerFp["dbmsVersion"] - if banVer and distutils.version.LooseVersion(banVer) >= distutils.version.LooseVersion("5.0.67"): + if banVer and LooseVersion(banVer) >= LooseVersion("5.0.67"): if self.__plugindir is None: logger.info("retrieving MySQL plugin directory absolute path") self.__plugindir = unArrayizeValue(inject.getValue("SELECT @@plugin_dir")) # On MySQL 5.1 >= 5.1.19 and on any version of MySQL 6.0 - if self.__plugindir is None and distutils.version.LooseVersion(banVer) >= distutils.version.LooseVersion("5.1.19"): + if self.__plugindir is None and LooseVersion(banVer) >= LooseVersion("5.1.19"): logger.info("retrieving MySQL base directory absolute path") # Reference: http://dev.mysql.com/doc/refman/5.1/en/server-options.html#option_mysqld_basedir diff --git a/plugins/dbms/postgresql/takeover.py b/plugins/dbms/postgresql/takeover.py index 187a0686f..cfa142d2d 100644 --- a/plugins/dbms/postgresql/takeover.py +++ b/plugins/dbms/postgresql/takeover.py @@ -5,7 +5,6 @@ Copyright (c) 2006-2021 sqlmap developers (https://sqlmap.org/) See the file 'LICENSE' for copying permission """ -import distutils.version import os from lib.core.common import Backend @@ -17,6 +16,7 @@ from lib.core.common import isListLike from lib.core.common import isNoneValue from lib.core.common import isStackingAvailable from lib.core.common import randomStr +from lib.core.compat import LooseVersion from lib.core.data import kb from lib.core.data import logger from lib.core.data import paths @@ -54,9 +54,9 @@ class Takeover(GenericTakeover): if not banVer or not banVer[0].isdigit(): errMsg = "unsupported feature on unknown version of PostgreSQL" raise SqlmapUnsupportedFeatureException(errMsg) - elif distutils.version.LooseVersion(banVer) >= distutils.version.LooseVersion("10"): + elif LooseVersion(banVer) >= LooseVersion("10"): majorVer = banVer.split('.')[0] - elif distutils.version.LooseVersion(banVer) >= distutils.version.LooseVersion("8.2") and '.' in banVer: + elif LooseVersion(banVer) >= LooseVersion("8.2") and '.' in banVer: majorVer = '.'.join(banVer.split('.')[:2]) else: errMsg = "unsupported feature on versions of PostgreSQL before 8.2" diff --git a/sqlmap.py b/sqlmap.py index da9cdfd26..4999a344d 100755 --- a/sqlmap.py +++ b/sqlmap.py @@ -18,7 +18,6 @@ try: sys.exit("[!] wrong installation detected (missing modules). Visit 'https://github.com/sqlmapproject/sqlmap/#installation' for further details") import bdb - import distutils import glob import inspect import json @@ -64,6 +63,7 @@ try: from lib.core.common import MKSTEMP_PREFIX from lib.core.common import setColor from lib.core.common import unhandledExceptionMessage + from lib.core.compat import LooseVersion from lib.core.compat import xrange from lib.core.exception import SqlmapBaseException from lib.core.exception import SqlmapShellQuitException @@ -114,7 +114,7 @@ def checkEnvironment(): logger.critical(errMsg) raise SystemExit - if distutils.version.LooseVersion(VERSION) < distutils.version.LooseVersion("1.0"): + if LooseVersion(VERSION) < LooseVersion("1.0"): errMsg = "your runtime environment (e.g. PYTHONPATH) is " errMsg += "broken. Please make sure that you are not running " errMsg += "newer versions of sqlmap with runtime scripts for older "