From 003393442626864cc3896bad1ab2a818238fcca1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Wed, 8 Jul 2026 12:43:10 +0200 Subject: [PATCH] Minor optimization --- lib/core/settings.py | 2 +- lib/core/threads.py | 2 ++ lib/request/comparison.py | 9 +++++++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/core/settings.py b/lib/core/settings.py index e46d16d13..be28c87c6 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -20,7 +20,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.7.42" +VERSION = "1.10.7.43" 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/threads.py b/lib/core/threads.py index 96d646859..47e8e10ab 100644 --- a/lib/core/threads.py +++ b/lib/core/threads.py @@ -52,6 +52,8 @@ class _ThreadData(threading.local): self.lastComparisonCode = None self.lastComparisonRatio = None self.lastPageTemplateCleaned = None + self.lastPageTemplateJsonMinimized = None + self.lastPageTemplateStructural = None self.lastPageTemplate = None self.lastErrorPage = tuple() self.lastHTTPError = None diff --git a/lib/request/comparison.py b/lib/request/comparison.py index d2e8bac07..b800f4795 100644 --- a/lib/request/comparison.py +++ b/lib/request/comparison.py @@ -132,6 +132,11 @@ def _comparison(page, headers, code, getRatioValue, pageLength): page = removeDynamicContent(page) if threadData.lastPageTemplate != kb.pageTemplate: threadData.lastPageTemplateCleaned = removeDynamicContent(kb.pageTemplate) + # Same template-identity memoization for the structure-aware projections (§below): the + # template is constant across an extraction, so it must not be re-parsed/re-tokenized on + # every inference request - only seq2 (from the live page) is recomputed per response + threadData.lastPageTemplateJsonMinimized = jsonMinimize(kb.pageTemplate) + threadData.lastPageTemplateStructural = "\n".join(sorted(extractStructuralTokens(kb.pageTemplate))) threadData.lastPageTemplate = kb.pageTemplate seqMatcher.set_seq1(threadData.lastPageTemplateCleaned) @@ -178,14 +183,14 @@ def _comparison(page, headers, code, getRatioValue, pageLength): # only on a JSON Content-Type with both bodies parseable; any doubt (or an explicit # --text-only/--titles) falls back to the exact text path below. if _isJsonResponse(headers) and not (conf.titles or conf.textOnly or kb.nullConnection): - seq1 = jsonMinimize(kb.pageTemplate) + seq1 = threadData.lastPageTemplateJsonMinimized # memoized per template (see above) seq2 = jsonMinimize(rawPage) # Structure-aware comparison for a structurally-stable (but byte-unstable) HTML page: # compare the value-free tag/class/id skeleton so dynamic text does not perturb the ratio # while a structural change (e.g. a results table appearing/disappearing) still does if seq1 is None and kb.pageStructurallyStable and not (conf.titles or conf.textOnly or kb.nullConnection): - _ = "\n".join(sorted(extractStructuralTokens(kb.pageTemplate))) + _ = threadData.lastPageTemplateStructural # memoized per template (see above) if _: # only engage when the page actually exposes structure (HTML tags); tagless content falls back to text seq1 = _ seq2 = "\n".join(sorted(extractStructuralTokens(rawPage)))