#!/usr/bin/env python """ Copyright (c) 2006-2026 sqlmap developers (https://sqlmap.org) See the file 'LICENSE' for copying permission Coverage for the XSLT injection engine (lib/techniques/xslt/inject.py) and the XQuery tier the XPath engine gained (lib/techniques/xpath/inject.py). Network-free: the payload builders, engine fingerprinting and charset construction are pure functions, so they are asserted directly. The parts that decide a VERDICT get the most attention - a detection tier that rests on "the page changed" is exactly the kind that invents findings, so its guards are pinned here. stdlib unittest only (no pytest / no pip); works on Python 2.7 and 3.x. """ import os import re import sys import unittest sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) from _testutils import bootstrap bootstrap() from lib.core.settings import XSLT_ERROR_REGEX from lib.core.settings import XSLT_BRIDGES from lib.core.settings import XSLT_BRIDGE_PHP from lib.core.settings import XSLT_BRIDGE_JAVA from lib.core.settings import XSLT_ADVISORY_PROBES from lib.core.settings import XSLT_VENDOR_PROPERTIES from lib.core.settings import XQUERY_CAPABILITY_PROBES from lib.core.settings import XQUERY_FILE_READ from lib.techniques.xslt import inject as _xslt from lib.techniques.xpath import inject as _xpath def _source(*parts): with open(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", *parts)) as f: return f.read() class XsltPayloadTest(unittest.TestCase): def test_element_payload_is_a_whole_instruction(self): payload = _xslt._elementPayload("'a'") self.assertTrue(payload.startswith(" _quote uses "..." "grep -r 'x' /etc", "/tmp/o'brien.xml", "/tmp/a&b.xml", # bare '&' ends the attribute value "cat /etc/passwd && id", "/tmp/