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.

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

to use a different tag with a suitable event handler. Here, you should consider<br />

all <strong>the</strong> techniques already discussed for dealing with signature-based filters,<br />

including using layers of encoding, NULL bytes, nonstandard syntax, and<br />

obfuscated script code. By modifying your input in <strong>the</strong> various ways described,<br />

you may be able to devise an attack that does not contain any of <strong>the</strong> characters<br />

or expressions that <strong>the</strong> filter is sanitizing and <strong>the</strong>refore successfully bypass it.<br />

If it appears impossible to perform an attack without using input that is being<br />

sanitized, you need to test <strong>the</strong> effectiveness of <strong>the</strong> sanitizing filter to establish<br />

whe<strong>the</strong>r any bypasses exist.<br />

As described in Chapter 2, several mistakes often appear in sanitizing filters.<br />

Some string manipulation APIs contain methods to replace only <strong>the</strong> first instance<br />

of a matched expression, and <strong>the</strong>se are sometimes easily confused with methods<br />

that replace all instances. So if is being stripped from your input, you<br />

should try <strong>the</strong> following to check whe<strong>the</strong>r all instances are being removed:<br />

alert(1)<br />

In this situation, you should also check whe<strong>the</strong>r <strong>the</strong> sanitization is being<br />

performed recursively:<br />

alert(1)<br />

Fur<strong>the</strong>rmore, if <strong>the</strong> filter performs several sanitizing steps on your input, you<br />

should check whe<strong>the</strong>r <strong>the</strong> order or interplay between <strong>the</strong>se can be exploited.<br />

For example, if <strong>the</strong> filter strips recursively and <strong>the</strong>n strips <br />

recursively, <strong>the</strong> following attack may succeed:<br />

alert(1)<br />

When you are injecting into a quoted string in an existing script, it is common<br />

to find that <strong>the</strong> <strong>application</strong> sanitizes your input by placing <strong>the</strong> backslash<br />

character before any quotation mark characters you submit. This escapes your<br />

quotation marks, preventing you from terminating <strong>the</strong> string and injecting<br />

arbitrary script. In this situation, you should always verify whe<strong>the</strong>r <strong>the</strong> backslash<br />

character itself is being escaped. If not, a simple filter bypass is possible.<br />

For example, if you control <strong>the</strong> value foo in:<br />

var a = ‘foo’;<br />

you can inject:<br />

foo\’; alert(1);//<br />

This results in <strong>the</strong> following response, in which your injected script executes.<br />

Note <strong>the</strong> use of <strong>the</strong> JavaScript comment character // to comment out <strong>the</strong>

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

Saved successfully!

Ooh no, something went wrong!