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.

344 Chapter 9 n Attacking Data Stores<br />

}<br />

else<br />

{<br />

}<br />

$logged_in=0;<br />

$js is a JavaScript function, <strong>the</strong> code for which is constructed dynamically<br />

and includes <strong>the</strong> user-supplied username and password. An attacker can bypass<br />

<strong>the</strong> au<strong>the</strong>ntication logic by supplying a username:<br />

Marcus’//<br />

and any password. The resulting JavaScript function looks like this:<br />

function() { return this.username == ‘Marcus’//’ & this.password == ‘aaa’; }<br />

NOTE In JavaScript, a double forward slash (//) signifies a rest-of-line comment,<br />

so <strong>the</strong> remaining code in <strong>the</strong> function is commented out.<br />

An alternative means of ensuring that <strong>the</strong> $js function always returns<br />

true, without using a comment, would be to supply a username of:<br />

a’ || 1==1 || ‘a’==’a<br />

JavaScript interprets <strong>the</strong> various operators like this:<br />

(this.username == ‘a’ || 1==1) || (‘a’==’a’ & this.password ==<br />

‘aaa’);<br />

This results in all of <strong>the</strong> resources in <strong>the</strong> user collection being matched,<br />

since <strong>the</strong> first disjunctive condition is always true (1 is always equal to 1).<br />

Injecting into XPath<br />

The XML Path Language (XPath) is an interpreted language used to navigate<br />

around XML documents and to retrieve data from within <strong>the</strong>m. In most cases,<br />

an XPath expression represents a sequence of steps that is required to navigate<br />

from one node of a document to ano<strong>the</strong>r.<br />

Where <strong>web</strong> <strong>application</strong>s store data within XML documents, <strong>the</strong>y may use<br />

XPath to access <strong>the</strong> data in response to user-supplied input. If this input is<br />

inserted into <strong>the</strong> XPath query without any filtering or sanitization, an attacker<br />

may be able to manipulate <strong>the</strong> query to interfere with <strong>the</strong> <strong>application</strong>’s logic or<br />

retrieve data for which she is not authorized.<br />

XML documents generally are not a preferred vehicle for storing enterprise data.<br />

However, <strong>the</strong>y are frequently used to store <strong>application</strong> configuration data that may<br />

be retrieved on <strong>the</strong> basis of user input. They may also be used by smaller <strong>application</strong>s<br />

to persist simple information such as user credentials, roles, and privileges.

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

Saved successfully!

Ooh no, something went wrong!