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 13 n Attacking Users: O<strong>the</strong>r Techniques 521<br />

JSON<br />

In a variation on <strong>the</strong> preceding example, <strong>the</strong> <strong>application</strong> does not perform a<br />

function callback in <strong>the</strong> dynamically invoked script, but instead just returns<br />

<strong>the</strong> JSON array containing <strong>the</strong> user’s details:<br />

[<br />

]<br />

[ ‘Name’, ‘Mat<strong>the</strong>w Adamson’ ],<br />

[ ‘Username’, ‘adammatt’ ],<br />

[ ‘Password’, ‘4nl1ub3’ ],<br />

[ ‘Uid’, ‘88’ ],<br />

[ ‘Role’, ‘User’ ]<br />

As described in Chapter 3, JSON is a flexible notation for representing arrays<br />

of data and can be consumed directly by a JavaScript interpreter.<br />

In older versions of Firefox, it was possible to perform a cross-domain script<br />

include attack to capture this data by overriding <strong>the</strong> default Array constructor<br />

in JavaScript. For example:<br />

<br />

function capture(s) {<br />

alert(s);<br />

}<br />

function Array() {<br />

for (var i = 0; i < 5; i++)<br />

this[i] setter = capture;<br />

}<br />

<br />

<br />

<br />

This attack modifies <strong>the</strong> default Array object and defines a custom setter<br />

function, which is invoked when values are assigned to elements in an array. It<br />

<strong>the</strong>n executes <strong>the</strong> response containing <strong>the</strong> JSON data. The JavaScript interpreter<br />

consumes <strong>the</strong> JSON data, constructs an Array to hold its values, and invokes<br />

<strong>the</strong> attacker’s custom setter function for each value in <strong>the</strong> array.<br />

Since this type of attack was discovered in 2006, <strong>the</strong> Firefox browser has been<br />

modified so that custom setters are not invoked during array initialization. This<br />

attack is not possible in current browsers.<br />

TRY IT!<br />

http://mdsec.net/auth/409/<br />

You need to download version 2.0 of Firefox to exploit this example. You<br />

can download this from <strong>the</strong> following URL:<br />

www.oldapps.com/firefox.php?old_firefox=26

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

Saved successfully!

Ooh no, something went wrong!