Authentication Bypass

Now that we have a basic idea of XPath query syntax, let's look at how XPath injection can be weaponized to bypass web authentication.

Foundation

Example XML user store:

<users>
	<user>
		<name first="Kaylie" last="Grenvile"/>
		<id>1</id>
		<username>kgrenvile</username>
		<password>P@ssw0rd!</password>
	</user>
	<user>
		<name first="Admin" last="Admin"/>
		<id>2</id>
		<username>admin</username>
		<password>admin</password>
	</user>
	<user>
		<name first="Academy" last="Student"/>
		<id>3</id>
		<username>htb-stdnt</username>
		<password>Academy_student!</password>
	</user>
</users>

Typical query used for auth:

Vulnerable PHP (unsanitized concatenation):

Basic Bypass (boolean true)

Inject values so the predicate always evaluates to true:

Resulting query example:

This returns all user nodes; apps often take the first match (logs in as the first user).

To target a specific username (e.g., admin) without a valid password:

Hashed Password Scenario

If passwords are hashed server-side before interpolation:

A naive ' or '1'='1 will fail because the password literal becomes a fixed hash.

Technique A: Universal true via double OR

Result:

Technique B: Select by position

Result:

Increment the index to iterate users.

Technique C: contains() to match partial usernames

Result:

Matches users whose node string-value contains "admin" (e.g., username descendants).

Notes & Tips

  • Try both username and password fields; either can influence the predicate.

  • Use application behavior (messages, returned content) to confirm success.

  • Do not store or publish sensitive flags. Omit secret values in write-ups.

Last updated