• We just launched and are currently in beta. Join us as we build and grow the community.

XPATH Injection โ€“ Attacks and Mitigation

zanogiy

Mobile App Auditor
Z Rep
0
0
0
Rep
0
Z Vouches
0
0
0
Vouches
0
Posts
55
Likes
187
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 500 XP
Orange-and-Black-Corporate-Startup-Business-Animated-Presentation.png


Hey Folks, In this tutorial we are going to discuss about XPATH Injection. As we know that that injection vulnerability is one of the top 10 most prominent vulnerabilities of the 2020 OWASP. This vulnerability can be dangerous for web applications, because this vulnerability allows an attackers to obtain details of users and customers from the database by executing the SQL query via input. Is XPATH injection the same as SQL injection ๐Ÿ’‰? ๐Ÿ˜จ Calm down ! In this tutorial we will try to cover topics related to it.

Lets do it ๐Ÿ™‚ !!

What is XPATH Injection ?

XPATH language is based on a tree representation of the XML document use for selecting nodes from an XML document. XPath can be used to compute values (e.g., strings, numbers, or Boolean values) from the content of an XML document. Lets talk about injection. XPath Injection attacks occur when a web site uses user-supplied information to create an XPath query for XML data. The XML document contains sensitive information such as user profile, password etc, Which is located at the specific ID. If the attacker finds out that the web application is vulnerable to the XPATH vulnerability then they can get the details by injecting a malicious query on the input such as : or id = 1, This query contains has ID that will take the user profile from the XML document and display it on the web application. This is the whole process but we will take a small example. In the given image you can see how the user profile is maintained in the XML document.

Orange-and-White-Funny-Dating-Animated-Presentation-5-1024x482.png


As you can see in the given image that the normal user is not able to login to the web application due to incorrect credentials. But when the attacker enters a malicious SQL query it gives a description of the user concerned because the web application uses a user-supply to create an XPATH query for the XML-document, so the query entered by the attacker first goes to the XML document and after searching the results are displayed.

Orange-and-White-Funny-Dating-Animated-Presentation-8-1024x401.png

Practical

I think we have got deep knowledge about XPATH injection now we will exploiting this vulnerability through the bWAAP vulnerable web application. Lets open the web application and set the security level to low.

1-13.png

XPATH Injection โ€“ Login Form

First we analyze the response of the web application by entering common credentials and you can see that we are not able to login. Lets try to think like a hacker and inject some malicious query.

2-13.png


Great ๐Ÿ™‚ !! We did it ! It has given us a description of the user who is located at id โ€˜1โ€™ after injecting the โ€˜orโ€™ query.

3-15.png


Just like that we get more user information but how is it possible. Lets check the source code.

4-14.png


The first thing is that there is no restriction of any kind in low security. ๐Ÿ™‚ !!

5-12.png


You can see that did the input is used for create an XPATH query which means if the query is executed they will locate data from XML documents.

6-12.png


Here you can see that after entering the query it gives us the details of the user located at that entered ID.

7-11.png

XPATH Injection โ€“ Search

Now we will try to get the user profile by injecting a malicious query to the URL. After clicking on the search, the location of the input appears on the URL.

9-8.png


We analyze the response the web application by adding single quote to the URL and after trying hard we could not find, now lets check the source code.

11-7.png


We analyze the source code and get some idea about how we can exploit it.

12-7.png


Nice ๐Ÿ™‚ !! child::node() is to select all the node and it will prints all the data as you can see below.

13-6.png

Mitigation

Similar to the SQL injection, in order to protect yourself you must escape single quotes (or double quotes) if we want to protect yourself against this kind of attacks.

Source : https://owasp.org

About the AuthorShubham Goyal Certified Ethical Hacker, information security analyst, penetration tester and researcher. Can be Contact on Linkedin.
 

428,602

311,185

311,194

Top