19.09.2017 Views

the-web-application-hackers-handbook

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

384 Chapter 10 n Attacking Back-End Components<br />

Injecting XML External Entities<br />

In today’s <strong>web</strong> <strong>application</strong>s, XML is often used to submit data from <strong>the</strong> client<br />

to <strong>the</strong> server. The server-side <strong>application</strong> <strong>the</strong>n acts on this data and may return<br />

a response containing XML or data in any o<strong>the</strong>r format. This behavior is most<br />

commonly found in Ajax-based <strong>application</strong>s where asynchronous requests are<br />

used to communicate in <strong>the</strong> background. It can also appear in <strong>the</strong> context of<br />

browser extension components and o<strong>the</strong>r client-side technologies.<br />

For example, consider a search function that, to provide a seamless user<br />

experience, is implemented using Ajax. When a user enters a search term, a<br />

client-side script issues <strong>the</strong> following request to <strong>the</strong> server:<br />

POST /search/128/AjaxSearch.ashx HTTP/1.1<br />

Host: mdsec.net<br />

Content-Type: text/xml; charset=UTF-8<br />

Content-Length: 44<br />

nothing will change<br />

The server’s response is as follows (although vulnerabilities may exist regardless<br />

of <strong>the</strong> format used in responses):<br />

HTTP/1.1 200 OK<br />

Content-Type: text/xml; charset=utf-8<br />

Content-Length: 81<br />

No results found for expression: nothing will<br />

change<br />

The client-side script processes this response and updates part of <strong>the</strong> user<br />

interface with <strong>the</strong> results of <strong>the</strong> search.<br />

When you encounter this type of functionality, you should always check for<br />

XML external entity (XXE) injection. This vulnerability arises because standard<br />

XML parsing libraries support <strong>the</strong> use of entity references. These are simply a<br />

method of referencing data ei<strong>the</strong>r inside or outside <strong>the</strong> XML document. Entity<br />

references should be familiar from o<strong>the</strong>r contexts. For example, <strong>the</strong> entities<br />

corresponding to <strong>the</strong> < and > characters are as follows:<br />

&lt;<br />

&gt;<br />

The XML format allows custom entities to be defined within <strong>the</strong> XML document<br />

itself. This is done within <strong>the</strong> optional DOCTYPE element at <strong>the</strong> start of <strong>the</strong><br />

document. For example:<br />

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!