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

n In some <strong>application</strong>s, anti-CSRF tokens are tied only to <strong>the</strong> current user,<br />

and not to his session. In this situation, if <strong>the</strong> login form is not protected<br />

against CSRF, a multistage exploit may still be possible. First, <strong>the</strong> attacker<br />

logs in to his own account to obtain a valid anti-CSRF token that is tied<br />

to his user identity. He <strong>the</strong>n uses CSRF against <strong>the</strong> login form to force<br />

<strong>the</strong> victim user to log in using <strong>the</strong> attacker’s credentials, as was already<br />

described for <strong>the</strong> exploitation of same-user stored XSS vulnerabilities.<br />

Once <strong>the</strong> user is logged in as <strong>the</strong> attacker, <strong>the</strong> attacker uses CSRF to cause<br />

<strong>the</strong> user to issue a request exploiting <strong>the</strong> XSS bug, using <strong>the</strong> anti-CSRF<br />

token previously acquired by <strong>the</strong> attacker. The attacker’s XSS payload<br />

<strong>the</strong>n executes in <strong>the</strong> user’s browser. Since <strong>the</strong> user is still logged in as <strong>the</strong><br />

attacker, <strong>the</strong> XSS payload may need to log <strong>the</strong> user out again and induce<br />

<strong>the</strong> user to log back in, with <strong>the</strong> result that <strong>the</strong> user’s login credentials<br />

and resulting <strong>application</strong> session are fully compromised.<br />

n If anti-CSRF tokens are tied not to <strong>the</strong> user but to <strong>the</strong> current session,<br />

a variation on <strong>the</strong> preceding attack may be possible if any methods are<br />

available for <strong>the</strong> attacker to inject cookies into <strong>the</strong> user’s browser (as<br />

described later in this chapter). Instead of using a CSRF attack against<br />

<strong>the</strong> login form with <strong>the</strong> attacker’s own credentials, <strong>the</strong> attacker can<br />

directly feed to <strong>the</strong> user both his current session token and <strong>the</strong> anti-<br />

CSRF token that is tied to it. The remainder of <strong>the</strong> attack <strong>the</strong>n proceeds<br />

as previously described.<br />

These scenarios aside, robust defenses against CSRF attacks do in many situations<br />

make it considerably harder, if not impossible, to exploit some reflected XSS<br />

vulnerabilities. However, it goes without saying that any XSS conditions in an<br />

<strong>application</strong> should always be fixed, regardless of any anti-CSRF protections in place<br />

that may, in some situations, frustrate an attacker who is seeking to exploit <strong>the</strong>m.<br />

UI Redress<br />

Fundamentally, anti-CSRF defenses involving tokens within <strong>the</strong> page aim to<br />

ensure that requests made by a user originate from that user’s actions within <strong>the</strong><br />

<strong>application</strong> itself and are not induced by some third-party domain. UI redress<br />

attacks are designed to allow a third-party site to induce user actions on ano<strong>the</strong>r<br />

domain even if anti-CSRF tokens are being used. These attacks work because,<br />

in <strong>the</strong> relevant sense, <strong>the</strong> resulting requests actually do originate within <strong>the</strong><br />

<strong>application</strong> being targeted. UI redress techniques are also often referred to as<br />

“clickjacking,” “strokejacking,” and o<strong>the</strong>r buzzwords.<br />

In its basic form, a UI redress attack involves <strong>the</strong> attacker’s <strong>web</strong> page loading<br />

<strong>the</strong> target <strong>application</strong> within an iframe on <strong>the</strong> attacker’s page. In effect,<br />

<strong>the</strong> attacker overlays <strong>the</strong> target <strong>application</strong>’s interface with a different interface

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

Saved successfully!

Ooh no, something went wrong!