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

Example 3: An Attribute Containing a URL<br />

Suppose that <strong>the</strong> returned page contains <strong>the</strong> following:<br />

Click here ...<br />

Here, <strong>the</strong> string you control is being inserted into <strong>the</strong> href attribute of an <br />

tag. In this context, and in many o<strong>the</strong>rs in which attributes may contain URLs,<br />

you can use <strong>the</strong> javascript: protocol to introduce script directly within <strong>the</strong><br />

URL attribute:<br />

javascript:alert(1);<br />

Because your input is being reflected within a tag attribute, you can also inject<br />

an event handler, as already described.<br />

For an attack that works against all current browsers, you can use an invalid<br />

image name toge<strong>the</strong>r with an onclick event handler:<br />

#”onclick=”javascript:alert(1)<br />

TIP As with o<strong>the</strong>r attacks, be sure to URL-encode any special characters that<br />

have significance within <strong>the</strong> request, including & = + ; and space.<br />

HACK STEPS<br />

Do <strong>the</strong> following for each reflected input identified in <strong>the</strong> previous steps:<br />

1. Review <strong>the</strong> HTML source to identify <strong>the</strong> location(s) where your unique<br />

string is being reflected.<br />

2. If <strong>the</strong> string appears more than once, each occurrence needs to be treated<br />

as a separate potential vulnerability and investigated individually.<br />

3. Determine, from <strong>the</strong> location within <strong>the</strong> HTML of <strong>the</strong> user-controllable<br />

string, how you need to modify it to cause execution of arbitrary script.<br />

Typically, numerous different methods will be potential vehicles for an<br />

attack, as described later in this chapter.<br />

4. Test your exploit by submitting it to <strong>the</strong> <strong>application</strong>. If your crafted string<br />

is still returned unmodified, <strong>the</strong> <strong>application</strong> is vulnerable. Double-check<br />

that your syntax is correct by using a proof-of-concept script to display an<br />

alert dialog, and confirm that this actually appears in your browser when<br />

<strong>the</strong> response is rendered.<br />

Probing Defensive Filters<br />

Very often, you will discover that <strong>the</strong> server modifies your initial attempted<br />

exploits in some way, so <strong>the</strong>y do not succeed in executing your injected script.

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

Saved successfully!

Ooh no, something went wrong!