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.

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

Reflected XSS Vulnerabilities<br />

A very common example of XSS occurs when an <strong>application</strong> employs a dynamic<br />

page to display error messages to users. Typically, <strong>the</strong> page takes a parameter<br />

containing <strong>the</strong> message’s text and simply renders this text back to <strong>the</strong> user within<br />

its response. This type of mechanism is convenient for developers, because it<br />

allows <strong>the</strong>m to invoke a customized error page from anywhere in <strong>the</strong> <strong>application</strong><br />

without needing to hard-code individual messages within <strong>the</strong> error page itself.<br />

For example, consider <strong>the</strong> following URL, which returns <strong>the</strong> error message<br />

shown in Figure 12-1:<br />

http://mdsec.net/error/5/Error.ashx?message=Sorry%2c+an+error+occurred<br />

Figure 12-1: A dynamically generated error message<br />

Looking at <strong>the</strong> HTML source for <strong>the</strong> returned page, we can see that <strong>the</strong> <strong>application</strong><br />

simply copies <strong>the</strong> value of <strong>the</strong> message parameter in <strong>the</strong> URL and inserts<br />

it into <strong>the</strong> error page template at <strong>the</strong> appropriate place:<br />

Sorry, an error occurred.<br />

This behavior of taking user-supplied input and inserting it into <strong>the</strong> HTML<br />

of <strong>the</strong> server’s response is one of <strong>the</strong> signatures of reflected XSS vulnerabilities,<br />

and if no filtering or sanitization is being performed, <strong>the</strong> <strong>application</strong> is certainly<br />

vulnerable. Let’s see how.<br />

The following URL has been crafted to replace <strong>the</strong> error message with a piece<br />

of JavaScript that generates a pop-up dialog:<br />

http://mdsec.net/error/5/Error.ashx?message=alert(1)<br />

Requesting this URL generates an HTML page that contains <strong>the</strong> following<br />

in place of <strong>the</strong> original message:<br />

alert(1);

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

Saved successfully!

Ooh no, something went wrong!