This commit is contained in:
Miroslav Stampar 2019-06-09 01:11:29 +02:00
parent e30155b657
commit ce3abdaa4d
2 changed files with 53 additions and 24 deletions

View File

@ -12,7 +12,6 @@ import codecs
import collections import collections
import contextlib import contextlib
import copy import copy
import distutils
import functools import functools
import getpass import getpass
import hashlib import hashlib
@ -176,6 +175,7 @@ from lib.core.settings import URI_QUESTION_MARKER
from lib.core.settings import URLENCODE_CHAR_LIMIT from lib.core.settings import URLENCODE_CHAR_LIMIT
from lib.core.settings import URLENCODE_FAILSAFE_CHARS from lib.core.settings import URLENCODE_FAILSAFE_CHARS
from lib.core.settings import USER_AGENT_ALIASES from lib.core.settings import USER_AGENT_ALIASES
from lib.core.settings import VERSION_COMPARISON_CORRECTION
from lib.core.settings import VERSION_STRING from lib.core.settings import VERSION_STRING
from lib.core.settings import ZIP_HEADER from lib.core.settings import ZIP_HEADER
from lib.core.settings import WEBSCARAB_SPLITTER from lib.core.settings import WEBSCARAB_SPLITTER
@ -517,7 +517,7 @@ class Backend(object):
@staticmethod @staticmethod
def getVersion(): def getVersion():
versions = filterNone(flattenValue(kb.dbmsVersion)) versions = filterNone(flattenValue(kb.dbmsVersion)) if not isinstance(kb.dbmsVersion, six.string_types) else [kb.dbmsVersion]
if not isNoneValue(versions): if not isNoneValue(versions):
return versions[0] return versions[0]
else: else:
@ -525,7 +525,7 @@ class Backend(object):
@staticmethod @staticmethod
def getVersionList(): def getVersionList():
versions = filterNone(flattenValue(kb.dbmsVersion)) versions = filterNone(flattenValue(kb.dbmsVersion)) if not isinstance(kb.dbmsVersion, six.string_types) else [kb.dbmsVersion]
if not isNoneValue(versions): if not isNoneValue(versions):
return versions return versions
else: else:
@ -3110,37 +3110,63 @@ def filterNone(values):
return retVal return retVal
def isDBMSVersionAtLeast(version): def isDBMSVersionAtLeast(minimum):
""" """
Checks if the recognized DBMS version is at least the version specified Checks if the recognized DBMS version is at least the version specified
>>> pushValue(kb.dbmsVersion)
>>> kb.dbmsVersion = "2"
>>> isDBMSVersionAtLeast("1.3.4.1.4")
True
>>> isDBMSVersionAtLeast(2.1)
False
>>> isDBMSVersionAtLeast(">2")
False
>>> isDBMSVersionAtLeast(">=2.0")
True
>>> kb.dbmsVersion = "<2"
>>> isDBMSVersionAtLeast("2")
False
>>> isDBMSVersionAtLeast("1.5")
True
>>> kb.dbmsVersion = popValue()
""" """
retVal = None retVal = None
if Backend.getVersion() and Backend.getVersion() != UNKNOWN_DBMS_VERSION: if not any(isNoneValue(_) for _ in (Backend.getVersion(), minimum)) and Backend.getVersion() != UNKNOWN_DBMS_VERSION:
value = Backend.getVersion().replace(" ", "").rstrip('.') version = Backend.getVersion().replace(" ", "").rstrip('.')
while True: if '.' in version:
index = value.find('.', value.find('.') + 1) parts = version.split('.', 1)
parts[1] = filterStringValue(parts[1], '[0-9]')
version = '.'.join(parts)
if index > -1: correction = 0.0
value = value[0:index] + value[index + 1:] if ">=" in version:
else: pass
break elif '>' in version:
correction = VERSION_COMPARISON_CORRECTION
elif '<' in version:
correction = -VERSION_COMPARISON_CORRECTION
value = filterStringValue(value, '[0-9.><=]') version = float(filterStringValue(version, '[0-9.]')) + correction
if value and isinstance(value, six.string_types): if isinstance(minimum, six.string_types):
if value.startswith(">="): if '.' in minimum:
value = float(value.replace(">=", "")) parts = minimum.split('.', 1)
elif value.startswith(">"): parts[1] = filterStringValue(parts[1], '[0-9]')
value = float(value.replace(">", "")) + 0.01 minimum = '.'.join(parts)
elif value.startswith("<="):
value = float(value.replace("<=", ""))
elif value.startswith(">"):
value = float(value.replace("<", "")) - 0.01
retVal = distutils.version.LooseVersion(getUnicode(value)) >= distutils.version.LooseVersion(getUnicode(version)) correction = 0.0
if minimum.startswith(">="):
pass
elif minimum.startswith(">"):
correction = VERSION_COMPARISON_CORRECTION
minimum = float(filterStringValue(minimum, '[0-9.]')) + correction
retVal = version >= minimum
return retVal return retVal

View File

@ -18,7 +18,7 @@ from lib.core.enums import OS
from thirdparty.six import unichr as _unichr from thirdparty.six import unichr as _unichr
# sqlmap version (<major>.<minor>.<month>.<monthly commit>) # sqlmap version (<major>.<minor>.<month>.<monthly commit>)
VERSION = "1.3.6.34" VERSION = "1.3.6.35"
TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable" TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable"
TYPE_COLORS = {"dev": 33, "stable": 90, "pip": 34} 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) VERSION_STRING = "sqlmap/%s#%s" % ('.'.join(VERSION.split('.')[:-1]) if VERSION.count('.') > 2 and VERSION.split('.')[-1] == '0' else VERSION, TYPE)
@ -500,6 +500,9 @@ DEFAULT_TOR_HTTP_PORTS = (8123, 8118)
# Percentage below which comparison engine could have problems # Percentage below which comparison engine could have problems
LOW_TEXT_PERCENT = 20 LOW_TEXT_PERCENT = 20
# Auxiliary value used in isDBMSVersionAtLeast() version comparison correction cases
VERSION_COMPARISON_CORRECTION = 0.0001
# These MySQL keywords can't go (alone) into versioned comment form (/*!...*/) # These MySQL keywords can't go (alone) into versioned comment form (/*!...*/)
# Reference: http://dev.mysql.com/doc/refman/5.1/en/function-resolution.html # Reference: http://dev.mysql.com/doc/refman/5.1/en/function-resolution.html
IGNORE_SPACE_AFFECTED_KEYWORDS = ("CAST", "COUNT", "EXTRACT", "GROUP_CONCAT", "MAX", "MID", "MIN", "SESSION_USER", "SUBSTR", "SUBSTRING", "SUM", "SYSTEM_USER", "TRIM") IGNORE_SPACE_AFFECTED_KEYWORDS = ("CAST", "COUNT", "EXTRACT", "GROUP_CONCAT", "MAX", "MID", "MIN", "SESSION_USER", "SUBSTR", "SUBSTRING", "SUM", "SYSTEM_USER", "TRIM")