19.09.2017 Views

the-web-application-hackers-handbook

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

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

In some situations, <strong>the</strong> XSS vulnerability is triggered only if <strong>the</strong> Referer header<br />

contains a URL on <strong>the</strong> same domain as <strong>the</strong> vulnerable <strong>application</strong>. Here, you<br />

may be able to leverage any on-site redirector functions within <strong>the</strong> <strong>application</strong><br />

to deliver your attack. To do this, you need to construct a URL to <strong>the</strong> redirector<br />

function that both contains a valid XSS exploit and causes a redirection to <strong>the</strong><br />

vulnerable URL. The success of this attack depends on <strong>the</strong> redirection method<br />

<strong>the</strong> function uses and on whe<strong>the</strong>r current browsers update <strong>the</strong> Referer header<br />

when following redirections of that type.<br />

Exploiting XSS in Nonstandard Request and Response Content<br />

Today’s complex <strong>application</strong>s increasingly employ Ajax requests that do not<br />

contain traditional request parameters. Instead, requests often contain data in<br />

formats such as XML and JSON, or employing various serialization schemes.<br />

Correspondingly, <strong>the</strong> responses to <strong>the</strong>se requests frequently contain data in <strong>the</strong><br />

same or ano<strong>the</strong>r format, ra<strong>the</strong>r than HTML.<br />

The server-side functionality involved in <strong>the</strong>se requests and responses often<br />

exhibits XSS-like behavior. Request payloads that normally would indicate <strong>the</strong><br />

presence of a vulnerability are returned unmodified by <strong>the</strong> <strong>application</strong>.<br />

In this situation, it is still possible that <strong>the</strong> behavior can be exploited to deliver<br />

an XSS attack. To do so, you need to meet two distinct challenges:<br />

n You need to find a means of causing a victim user to make <strong>the</strong> necessary<br />

request cross-domain.<br />

n You need to find a way of manipulating <strong>the</strong> response so that it executes<br />

your script when consumed by <strong>the</strong> browser.<br />

Nei<strong>the</strong>r of <strong>the</strong>se challenges is trivial. First, <strong>the</strong> requests in question typically<br />

are made from JavaScript using XMLHttpRequest (see Chapter 3). By default,<br />

this cannot be used to make cross-domain requests. Although XMLHttpRequest<br />

is being modified in HTML5 to allow sites to specify o<strong>the</strong>r domains that may<br />

interact with <strong>the</strong>m, if you find a target that allows third-party interaction, <strong>the</strong>re<br />

are probably simpler ways for you to compromise it (see Chapter 13).<br />

Second, in any attack, <strong>the</strong> response returned by <strong>the</strong> <strong>application</strong> would be consumed<br />

directly by <strong>the</strong> victim’s browser, not by <strong>the</strong> custom script that processes<br />

it in its original context. The response will contain data in whatever non-HTML<br />

format is being used, usually with <strong>the</strong> corresponding Content-Type header. In<br />

this situation, <strong>the</strong> browser processes <strong>the</strong> response in <strong>the</strong> normal way for this<br />

data type (if recognized), and normal methods for introducing script code via<br />

HTML may be irrelevant.<br />

Although nontrivial, in some situations both of <strong>the</strong>se challenges can be<br />

met, allowing <strong>the</strong> XSS-like behavior to be exploited to deliver a working<br />

attack. We will examine how this can be done using <strong>the</strong> XML data format<br />

as an example.

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

Saved successfully!

Ooh no, something went wrong!