XPATH injection
Learn & practice AWS Hacking:
HackTricks Training AWS Red Team Expert (ARTE)
Learn & practice GCP Hacking:
HackTricks Training GCP Red Team Expert (GRTE)

Join HackenProof Discord server to communicate with experienced hackers and bug bounty hunters!
Hacking Insights Engage with content that delves into the thrill and challenges of hacking
Real-Time Hack News Keep up-to-date with fast-paced hacking world through real-time news and insights
Latest Announcements Stay informed with the newest bug bounties launching and crucial platform updates
Join us on Discord and start collaborating with top hackers today!
Basic Syntax
An attack technique known as XPath Injection is utilized to take advantage of applications that form XPath (XML Path Language) queries based on user input to query or navigate XML documents.
Nodes Described
Expressions are used to select various nodes in an XML document. These expressions and their descriptions are summarized below:
nodename: All nodes with the name "nodename" are selected.
/: Selection is made from the root node.
//: Nodes matching the selection from the current node are selected, regardless of their location in the document.
.: The current node is selected.
..: The parent of the current node is selected.
@: Attributes are selected.
XPath Examples
Examples of path expressions and their results include:
bookstore: All nodes named "bookstore" are selected.
/bookstore: The root element bookstore is selected. It's noted that an absolute path to an element is represented by a path starting with a slash (/).
bookstore/book: All book elements that are children of bookstore are selected.
//book: All book elements in the document are selected, irrespective of their location.
bookstore//book: All book elements that are descendants of the bookstore element are selected, no matter their position under the bookstore element.
//@lang: All attributes named lang are selected.
Utilization of Predicates
Predicates are used to refine selections:
/bookstore/book[1]: The first book element child of the bookstore element is selected. A workaround for IE versions 5 to 9, which index the first node as [0], is setting the SelectionLanguage to XPath through JavaScript.
/bookstore/book[last()]: The last book element child of the bookstore element is selected.
/bookstore/book[last()-1]: The penultimate book element child of the bookstore element is selected.
/bookstore/book[position()<3]: The first two book elements children of the bookstore element are selected.
//title[@lang]: All title elements with a lang attribute are selected.
//title[@lang='en']: All title elements with a "lang" attribute value of "en" are selected.
/bookstore/book[price>35.00]: All book elements of the bookstore with a price greater than 35.00 are selected.
/bookstore/book[price>35.00]/title: All title elements of the book elements of the bookstore with a price greater than 35.00 are selected.
Handling of Unknown Nodes
Wildcards are employed for matching unknown nodes:
*: Matches any element node.
@*: Matches any attribute node.
node(): Matches any node of any kind.
Further examples include:
/bookstore/*: Selects all the child element nodes of the bookstore element.
//*: Selects all elements in the document.
//title[@*]: Selects all title elements with at least one attribute of any kind.
Example
Access the information
Identify & stealing the schema
Authentication Bypass
Example of queries:
OR bypass in user and password (same value in both)
Abusing null injection
Double OR in Username or in password (is valid with only 1 vulnerable field)
IMPORTANT: Notice that the "and" is the first operation made.
String extraction
The output contains strings and the user can manipulate the values to search:
Blind Explotation
Get length of a value and extract it by comparisons:
Python Example
Read file
OOB Exploitation
Automatic tool
References

Join HackenProof Discord server to communicate with experienced hackers and bug bounty hunters!
Hacking Insights Engage with content that delves into the thrill and challenges of hacking
Real-Time Hack News Keep up-to-date with fast-paced hacking world through real-time news and insights
Latest Announcements Stay informed with the newest bug bounties launching and crucial platform updates
Join us on Discord and start collaborating with top hackers today!
Learn & practice AWS Hacking:
HackTricks Training AWS Red Team Expert (ARTE)
Learn & practice GCP Hacking:
HackTricks Training GCP Red Team Expert (GRTE)
Last updated