DescriptionXPath is a sort of query language that describes how to locate specific elements (including attributes, processing instructions, etc.) in an XML document. Since it is a query language, XPath is somewhat similar to Structured Query Language (SQL). However, XPath can be used to reference almost any part of any XML document without access control restrictions, whereas with SQL, a "user" (which is a term undefined in the XPath/XML context) may be restricted to certain tables, columns or queries.
ExamplesUsing XPATH_Injection attack the attacker is able to e.g. log in to the system without entering valid login and password. If he wants to know information about other users he must take one step further. The attacker may be successfull using two methods: Boolenization and XML Crawling. By adding to the XPath syntax, which allows to log in without entering a login and password, additional expressions (replacing what the attacker entered in the place of login to the specially crafted expression). Boolenization Using so called "Boolenization" method the attacker may find out if the given XPath expression is True or False. Let's assume that the aim of the attacker is to log in to the account. Successfull log in would be equal "True" and failed log in attempt would equals "False". Only a smart portion of the information is analyzed "character" or the number. When the attacker focuses on the string he may reveal it in its entirety by checking every single character within the class/range of characters this string belongs to.
<?xml version="1.0" encoding="UTF-8"?> <data> <user> <login>admin</login> <password>test</password> <realname>SuperUser</realname> </user> <user> <login>rezos</login> <password>rezos123</password> <realname>Simple User</realname> </user> </data> Function:
To get to know the XML document structure the attacker may use:
count(//user/child::node() Will return the number of nodes (in this case 2).
string-length(//user[position()=1]/child::node()[position()=2])=6 Using this query the attacker will find out if the second string (password) of the first node (user 'admin') consists of 6 characters.
substring((//user[position()=1]/child::node()[position()=2]),1,1)="a" This query will confirm (True) or deny (False) that the first character of the user ('admin') password is an "a" character.
C#: String FindUser;
FindUser = "//user[login/text()='" + Request("Username") + "' And
password/text()='" + Request("Password") + "']";
then the attacker should inject the following code: Username: ' or substring((//user[position()=1]/child::node()[position()=2]),1,1)="a" or ''=' The XPath syntax may remind common SQL_Injection attacks but the attacker must consider, that this language disallows commenting out the rest of expresssion. To ommit this limitation the attacker should use OR expressions to void all expressions, which may disrupt the attack. Because of Boolenization the number of queries, even within a small XML document, may be very high (thousands, houndred of thousands and more). That is why this attack is not conducted manually. Knowing few basic XPath functions the attacker is able to write an application in a short time, which will rebuild the structure of the document and will fill it with a data by itself. References:
|

