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

For input1, <strong>the</strong> <strong>application</strong> blocks input containing quotation marks to prevent<br />

an attacker from terminating <strong>the</strong> quoted attribute. For input2, <strong>the</strong> <strong>application</strong><br />

blocks input containing angle brackets to prevent an attacker from using any<br />

HTML tags. This appears to be robust, but an attacker may be able to deliver<br />

an exploit using <strong>the</strong> following two inputs:<br />

input1: [%f0]<br />

input2: “onload=alert(1);<br />

In <strong>the</strong> Shift-JIS character set, various raw byte values, including 0xf0, are used<br />

to signal a 2-byte character that is composed of that byte and <strong>the</strong> following byte.<br />

Hence, when <strong>the</strong> browser processes input1, <strong>the</strong> quotation mark following <strong>the</strong><br />

0xf0 byte is interpreted as part of a 2-byte character and <strong>the</strong>refore does not delimit<br />

<strong>the</strong> attribute value. The HTML parser continues until it reaches <strong>the</strong> quotation<br />

mark supplied in input2, which terminates <strong>the</strong> attribute, allowing <strong>the</strong> attacker’s<br />

supplied event handler to be interpreted as an additional tag attribute:<br />

... “onload=alert(1);<br />

When exploits of this kind were identified in <strong>the</strong> widely used multibyte<br />

character set UTF-8, browser vendors responded with a fix that prevented <strong>the</strong><br />

attack from succeeding. However, currently <strong>the</strong> same attack still works on some<br />

browsers against several o<strong>the</strong>r lesser-used multibyte character sets, including<br />

Shift-JIS, EUC-JP, and BIG5.<br />

Bypassing Filters: Script Code<br />

In some situations, you will find a way to manipulate reflected input to introduce<br />

a script context into <strong>the</strong> <strong>application</strong>’s response. However, various o<strong>the</strong>r obstacles<br />

may prevent you from executing <strong>the</strong> code you need to deliver an actual attack.<br />

The kind of filters you may encounter here typically seek to block <strong>the</strong> use of<br />

certain JavaScript keywords and o<strong>the</strong>r expressions. They may also block useful<br />

characters such as quotes, brackets, and dots.<br />

As with <strong>the</strong> obfuscation of attacks using HTML, you can use numerous<br />

techniques to modify your desired script code to bypass common input filters.<br />

Using JavaScript Escaping<br />

JavaScript allows various kinds of character escaping, which you can use to<br />

avoid including required expressions in <strong>the</strong>ir literal form.<br />

Unicode escapes can be used to represent characters within JavaScript keywords,<br />

allowing you to bypass many kinds of filters:<br />

a\u006cert(1);<br />

If you can make use of <strong>the</strong> eval command, possibly by using <strong>the</strong> preceding<br />

technique to escape some of its characters, you can execute o<strong>the</strong>r commands<br />

by passing <strong>the</strong>m to <strong>the</strong> eval command in string form. This allows you to

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

Saved successfully!

Ooh no, something went wrong!