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.

Chapter 12 n Attacking Users: Cross-Site Scripting 477<br />

Sending XML Requests Cross-Domain<br />

It is possible to send near-arbitrary data cross-domain within <strong>the</strong> HTTP request<br />

body by using an HTML form with <strong>the</strong> enctype attribute set to text/plain. This<br />

tells <strong>the</strong> browser to handle <strong>the</strong> form parameters in <strong>the</strong> following way:<br />

n Send each parameter on a separate line within <strong>the</strong> request.<br />

n Use an equals sign to separate <strong>the</strong> name and value of each parameter (as<br />

normal).<br />

n Do not perform any URL encoding of parameter names or values.<br />

Although some browsers do not honor this specification, it is properly honored<br />

by current versions of Internet Explorer, Firefox, and Opera.<br />

The behavior described means that you can send arbitrary data in <strong>the</strong> message<br />

body, provided that <strong>the</strong>re is at least one equals sign anywhere within <strong>the</strong> data. To<br />

do this, you split <strong>the</strong> data into two chunks, before and after <strong>the</strong> equals sign. You<br />

place <strong>the</strong> first chunk into a parameter name and <strong>the</strong> second chunk into a parameter<br />

value. When <strong>the</strong> browser constructs <strong>the</strong> request, it sends <strong>the</strong> two chunks separated<br />

by an equals sign, <strong>the</strong>reby exactly constructing <strong>the</strong> required data.<br />

Since XML always contains at least one equals sign, in <strong>the</strong> version attribute of<br />

<strong>the</strong> opening XML tag, we can use this technique to send arbitrary XML data crossdomain<br />

in <strong>the</strong> message body. For example, if <strong>the</strong> required XML were as follows:<br />

foo<br />

we could send this using <strong>the</strong> following form:<br />

<br />

<br />

document.forms[0].submit();<br />

To include common attack characters within <strong>the</strong> value of <strong>the</strong> param parameter,<br />

such as tag angle brackets, <strong>the</strong>se would need to be HTML-encoded within <strong>the</strong><br />

XML request. Therefore, <strong>the</strong>y would need to be double HTML-encoded within<br />

<strong>the</strong> HTML form that generates that request.<br />

TIP You can use this technique to submit cross-domain requests containing<br />

virtually any type of content, such as JSON-encoded data and serialized binary<br />

objects, provided you can incorporate <strong>the</strong> equals character somewhere within<br />

<strong>the</strong> request. This is normally possible by modifying a free-form text field within<br />

<strong>the</strong> request that can contain an equals character. For example in <strong>the</strong> following<br />

JSON data, <strong>the</strong> comment field is used to introduce <strong>the</strong> required equals character:<br />

{ “name”: “John”, “email”: “gomad@diet.com”, “comment”: “=” }

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

Saved successfully!

Ooh no, something went wrong!