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.

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

An alternative to session hijacking, where an attacker simply wants to carry<br />

out a specific set of actions on behalf of each compromised user, is to use <strong>the</strong><br />

attack payload script itself to perform <strong>the</strong> actions. This attack payload is particularly<br />

useful in cases where an attacker wants to perform some action that<br />

requires administrative privileges, such as modifying <strong>the</strong> permissions assigned<br />

to an account he controls. With a large user base, it would be laborious to hijack<br />

each user’s session and establish whe<strong>the</strong>r <strong>the</strong> victim was an administrator. A<br />

more effective approach is to induce every compromised user to attempt to<br />

upgrade <strong>the</strong> permissions on <strong>the</strong> attacker’s account. Most attempts will fail, but<br />

<strong>the</strong> moment an administrative user is compromised, <strong>the</strong> attacker succeeds in<br />

escalating privileges. Ways of inducing actions on behalf of o<strong>the</strong>r users are<br />

described in <strong>the</strong> “Request Forgery” section of Chapter 13.<br />

The MySpace XSS worm described earlier is an example of this attack payload.<br />

It illustrates <strong>the</strong> power of such an attack to perform unauthorized actions on<br />

behalf of a mass user base with minimal effort by <strong>the</strong> attacker. This attack used<br />

a complex series of requests using Ajax techniques (described in Chapter 3) to<br />

carry out <strong>the</strong> various actions that were required to allow <strong>the</strong> worm to propagate.<br />

An attacker whose primary target is <strong>the</strong> <strong>application</strong> itself, but who wants<br />

to remain as stealthy as possible, can leverage this type of XSS attack payload<br />

to cause o<strong>the</strong>r users to carry out malicious actions of his choosing against <strong>the</strong><br />

<strong>application</strong>. For example, <strong>the</strong> attacker could cause ano<strong>the</strong>r user to exploit a SQL<br />

injection vulnerability to add a new administrator to <strong>the</strong> table of user accounts<br />

within <strong>the</strong> database. The attacker would control <strong>the</strong> new account, but any investigation<br />

of <strong>application</strong> logs may conclude that a different user was responsible.<br />

Exploiting Any Trust Relationships<br />

You have already seen one important trust relationship that XSS may exploit:<br />

browsers trust JavaScript received from a <strong>web</strong>site with <strong>the</strong> cookies issued by<br />

that <strong>web</strong>site. Several o<strong>the</strong>r trust relationships can sometimes be exploited in<br />

an XSS attack:<br />

n If <strong>the</strong> <strong>application</strong> employs forms with autocomplete enabled, JavaScript<br />

issued by <strong>the</strong> <strong>application</strong> can capture any previously entered data that<br />

<strong>the</strong> user’s browser has stored in <strong>the</strong> autocomplete cache. By instantiating<br />

<strong>the</strong> relevant form, waiting for <strong>the</strong> browser to autocomplete its contents,<br />

and <strong>the</strong>n querying <strong>the</strong> form field values, <strong>the</strong> script may be able to steal<br />

this data and transmit it to <strong>the</strong> attacker’s server. This attack can be more<br />

powerful than injecting Trojan functionality, because sensitive data can<br />

be captured without requiring any interaction from <strong>the</strong> user.<br />

n Some <strong>web</strong> <strong>application</strong>s recommend or require that users add <strong>the</strong>ir domain<br />

name to <strong>the</strong>ir browser’s “Trusted Sites” zone. This is almost always undesirable<br />

and means that any XSS-type flaw can be exploited to perform

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

Saved successfully!

Ooh no, something went wrong!