HAAS - Kiwicon7-Automating Advanced XPath Injection Attacks PDF
HAAS - Kiwicon7-Automating Advanced XPath Injection Attacks PDF
Paul Haas
Kiwicon 7
Agenda
Experience
10 years in computer security, hailing from California, living in NZ
Expertise across entire pentest spectrum: App, Net, WIFI, DB, etc.
Talks: OWASP Day NZ 2013, sec. training classes, Defcon 2010
Bash-Fu Master, XPath Ninja, CTF Winner, Psychic Beach bum
Passions
Solving complex problems (the hack)
Alternately: making them more complex
Mario Kart duals at sunset on the beach
What
What is XPath?
<book>
<title>Necronomicon</title>
<description language="latin">!Q@#$%^*()_+{}:"?</description>
<price><?cat /dev/random; ?></price>
<author>"Mad Arab" Abdul Alhazred</author>
</book>
<book>
<title>Les Fleurs du mal</title>
<description>Spleen et Ide'al</description>
<price>5</price>
<author>Charles Baudelaire</author>
</book>
</lib>
What
Examples
count(/lib/book)
/lib/book[1]/price
//book[last()]/description
/lib/book[title='Learning XPath']
Elements
Node, @attribute, ‘//’ anywhere, ‘.’ Current, ‘..’ Parent, ‘*’ wildcard
Functions
name, count, string-length, translate, concat, contains, substring
Operators
+-/*, div, =, !=, <, <=, >, >=, [ ], or, and, mod, | as a union operator
Wut
Why XPath?
XPath allows queries to read from a ‘sensitive’ backend database
Used in variety of web frameworks as a replacement for SQL
Commonly used to provide dynamic user interaction/search
Certain characters can modify purpose and function of query
Modified query can access other part of database
Including arbitrary XPath functions
Risk
XPath 1: Retrieve the entire database
XPath 2: Access remote files on the server
Penetration Testing
Need to be aware of emerging technologies and vulnerabilities
XML technologies on the rise, more ‘enterprise’
Increased number of applications using XPath
Lack of techniques, tools and cheat sheets
Existing Work
Various presentations and whitepapers about injection techniques
XPath-blind-explorer: Windows binary to perform blind injection
xcat.py: Blind XPath injection with focus on XPath 2 techniques
Both tools designed by same author for Blackhat
Why
xcat Advantages
Reconstruct a remote XML database using blind XPi
Replaces Windows binary with open source Python implementation
Includes both XPath 1 and 2 techniques
Uses threading and other optimization techniques
xcat Disadvantages
Best optimizations only work in XPath 2
Version 1 falls back to slow linear methods
Threading makes improvements impossible
Cannot customize retrieval content
Can do better
y?
Blind Injection
Does not rely on XPath data being returned,
errors or speed of response
Ask yes/no question about the database
Distinguish if true/false using response
Repeat until no questions remain
How
Injection Comparisons
' OR '1'='1 – Supported in both SQLi and XPi
' OR user() AND '1'='1 – Works in SQLi only
' OR count(//*) AND '1'='1 – Works in XPi only
' OR lower-case('A') AND '1'='1 – Works in XPath 2
' OR kart() AND '1'='1 – Doesn’t work anywhere
How
Demo
How
Search Techniques
xcat uses a linear search method for blind retrieval
There are faster search algorithms, implement these
Determine if XPath 1 has necessary functionality
Binary Search
Keeps dividing problem in half until single answer is found
IE: Is character in the first or second half of the alphabet?
Requests = ln(size of alphabet), 8 requests for entire ASCII set
Binary Search
Use contains function while dividing set in half until match
contains([A..Z], character), contains([A..M], character),
contains([A..G], character), contains([A..D], character),
contains([A..B], character), character = ‘A’
Improvement: Threading
xcat uses threading across a linear search
Cannot easily thread advanced searches as they use conditional
statements based on old results for future ones
Largest amount of time is spent reconstructing strings
Assign a thread to each character in string reconstruction
Allows use of all speedup techniques without additional complexity
How
Future Improvements:
HTTP Keep Alive
Keep connections open to prevent round trip TCP setup time
Retrieval Resume
Keep information about current reconstruction, allowing restart
Compare/Update SQLmap
Compare features/Push XPath techniques back to SQLi
Namespace checks
Additional Unicode checks
Additional Flags
IE: --ssl
How
Umbraco
Described as ‘The open source ASP.NET CMS’
Mention of several XPath injection attacks on Google
Vulnerable at /umbraco/dashboard.aspx?app=$INJECTION
No sensitive information in XML database, POC only
As long as they don’t update to XPath 2 they will be safe
Payload provided in xxxpwn
+ =
Where?
Demo
When