From e64cc86fc4c9a28893733f4cfb6cee0e865055db Mon Sep 17 00:00:00 2001 From: Miroslav Stampar Date: Mon, 25 Mar 2019 11:42:16 +0100 Subject: [PATCH] Patch related to the #3524 --- lib/controller/checks.py | 59 ++++++++++++++++++++++++---------------- lib/core/enums.py | 1 + lib/core/settings.py | 2 +- 3 files changed, 37 insertions(+), 25 deletions(-) diff --git a/lib/controller/checks.py b/lib/controller/checks.py index 3f299bfdb..2ba006e19 100644 --- a/lib/controller/checks.py +++ b/lib/controller/checks.py @@ -1507,44 +1507,55 @@ def checkNullConnection(): if conf.data: return False - infoMsg = "testing NULL connection to the target URL" - logger.info(infoMsg) + _ = hashDBRetrieve(HASHDB_KEYS.CHECK_NULL_CONNECTION_RESULT, True) + if _ is not None: + kb.nullConnection = _ - pushValue(kb.pageCompress) - kb.pageCompress = False + if _: + dbgMsg = "resuming NULL connection method '%s'" % _ + logger.debug(dbgMsg) - try: - page, headers, _ = Request.getPage(method=HTTPMETHOD.HEAD, raise404=False) + else: + infoMsg = "testing NULL connection to the target URL" + logger.info(infoMsg) - if not page and HTTP_HEADER.CONTENT_LENGTH in (headers or {}): - kb.nullConnection = NULLCONNECTION.HEAD + pushValue(kb.pageCompress) + kb.pageCompress = False - infoMsg = "NULL connection is supported with HEAD method ('Content-Length')" - logger.info(infoMsg) - else: - page, headers, _ = Request.getPage(auxHeaders={HTTP_HEADER.RANGE: "bytes=-1"}) + try: + page, headers, _ = Request.getPage(method=HTTPMETHOD.HEAD, raise404=False) - if page and len(page) == 1 and HTTP_HEADER.CONTENT_RANGE in (headers or {}): - kb.nullConnection = NULLCONNECTION.RANGE + if not page and HTTP_HEADER.CONTENT_LENGTH in (headers or {}): + kb.nullConnection = NULLCONNECTION.HEAD - infoMsg = "NULL connection is supported with GET method ('Range')" + infoMsg = "NULL connection is supported with HEAD method ('Content-Length')" logger.info(infoMsg) else: - _, headers, _ = Request.getPage(skipRead=True) + page, headers, _ = Request.getPage(auxHeaders={HTTP_HEADER.RANGE: "bytes=-1"}) - if HTTP_HEADER.CONTENT_LENGTH in (headers or {}): - kb.nullConnection = NULLCONNECTION.SKIP_READ + if page and len(page) == 1 and HTTP_HEADER.CONTENT_RANGE in (headers or {}): + kb.nullConnection = NULLCONNECTION.RANGE - infoMsg = "NULL connection is supported with 'skip-read' method" + infoMsg = "NULL connection is supported with GET method ('Range')" logger.info(infoMsg) + else: + _, headers, _ = Request.getPage(skipRead=True) - except SqlmapConnectionException: - pass + if HTTP_HEADER.CONTENT_LENGTH in (headers or {}): + kb.nullConnection = NULLCONNECTION.SKIP_READ - finally: - kb.pageCompress = popValue() + infoMsg = "NULL connection is supported with 'skip-read' method" + logger.info(infoMsg) - return kb.nullConnection is not None + except SqlmapConnectionException: + pass + + finally: + kb.pageCompress = popValue() + kb.nullConnection = False if kb.nullConnection is None else kb.nullConnection + hashDBWrite(HASHDB_KEYS.CHECK_NULL_CONNECTION_RESULT, kb.nullConnection, True) + + return kb.nullConnection in getPublicTypeMembers(NULLCONNECTION, True) def checkConnection(suppressOutput=False): threadData = getCurrentThreadData() diff --git a/lib/core/enums.py b/lib/core/enums.py index a050e8b01..18510404c 100644 --- a/lib/core/enums.py +++ b/lib/core/enums.py @@ -231,6 +231,7 @@ class HASHDB_KEYS: DBMS = "DBMS" DBMS_FORK = "DBMS_FORK" CHECK_WAF_RESULT = "CHECK_WAF_RESULT" + CHECK_NULL_CONNECTION_RESULT = "CHECK_NULL_CONNECTION_RESULT" CONF_TMP_PATH = "CONF_TMP_PATH" KB_ABS_FILE_PATHS = "KB_ABS_FILE_PATHS" KB_BRUTE_COLUMNS = "KB_BRUTE_COLUMNS" diff --git a/lib/core/settings.py b/lib/core/settings.py index be5ccca1a..0b0d990ee 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import DBMS_DIRECTORY_NAME from lib.core.enums import OS # sqlmap version (...) -VERSION = "1.3.3.46" +VERSION = "1.3.3.47" 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)