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 487<br />

HTML can be embedded in various locations within a valid image file, including<br />

<strong>the</strong> comment section of <strong>the</strong> image. Several browsers, including Firefox and<br />

Safari, happily render an image file as HTML. The binary parts of <strong>the</strong> image<br />

are displayed as junk, and any embedded HTML is displayed in <strong>the</strong> usual way.<br />

TIP Suppose a potential victim is using an HTML5-compliant browser, where<br />

cross-domain Ajax requests are possible with <strong>the</strong> permission of <strong>the</strong> requested<br />

domain. Ano<strong>the</strong>r possible attack in this situation would be to place an absolute<br />

URL after <strong>the</strong> fragment character, specifying an external HTML file that<br />

<strong>the</strong> attacker fully controls, on a server that allows Ajax interaction from <strong>the</strong><br />

domain being targeted. If <strong>the</strong> client-side script does not validate that <strong>the</strong> URL<br />

being requested is on <strong>the</strong> same domain, <strong>the</strong> client-side remote file inclusion<br />

attack succeeds.<br />

Because this validation of <strong>the</strong> URL’s domain would have been unnecessary<br />

in older versions of HTML, this is one example where <strong>the</strong> changes introduced<br />

in HTML5 may <strong>the</strong>mselves introduce exploitable conditions into existing <strong>application</strong>s<br />

that were previously secure.<br />

Finding and Exploiting DOM-Based XSS Vulnerabilities<br />

DOM-based XSS vulnerabilities cannot be identified by submitting a unique string<br />

as each parameter and monitoring responses for <strong>the</strong> appearance of that string.<br />

One basic method for identifying DOM-based XSS bugs is to manually walk<br />

through <strong>the</strong> <strong>application</strong> with your browser and modify each URL parameter to<br />

contain a standard test string, such as one of <strong>the</strong> following:<br />

“alert(1)<br />

“;alert(1)//<br />

‘-alert(1)-’<br />

By actually displaying each returned page in your browser, you cause all<br />

client-side scripts to execute, referencing your modified URL parameter where<br />

applicable. Any time a dialog box appears containing your cookies, you will<br />

have found a vulnerability (which may be due to DOM-based or o<strong>the</strong>r forms<br />

of XSS). This process could even be automated by a tool that implemented its<br />

own JavaScript interpreter.<br />

However, this basic approach does not identify all DOM-based XSS bugs.<br />

As you have seen, <strong>the</strong> precise syntax required to inject valid JavaScript into an<br />

HTML document depends on <strong>the</strong> syntax that already appears before and after<br />

<strong>the</strong> point where <strong>the</strong> user-controllable string gets inserted. It may be necessary to<br />

terminate a single- or double-quoted string or to close specific tags. Sometimes<br />

new tags may be required, but sometimes not. Client-side <strong>application</strong> code may<br />

attempt to validate data retrieved from <strong>the</strong> DOM, and yet may still be vulnerable.

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

Saved successfully!

Ooh no, something went wrong!