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.

508 Chapter 13 n Attacking Users: O<strong>the</strong>r Techniques<br />

<strong>the</strong> attacker’s account, this need not be <strong>the</strong> end of <strong>the</strong> attack. As described in<br />

Chapter 12, <strong>the</strong> XSS exploit can persist in <strong>the</strong> user’s browser and perform arbitrary<br />

actions, logging <strong>the</strong> user out of her current session with <strong>the</strong> vulnerable<br />

<strong>application</strong> and inducing her to log back in using her own credentials.<br />

Preventing CSRF Flaws<br />

CSRF vulnerabilities arise because of how browsers automatically submit cookies<br />

back to <strong>the</strong> issuing <strong>web</strong> server with each subsequent request. If a <strong>web</strong> <strong>application</strong><br />

relies solely on HTTP cookies as its mechanism for tracking sessions, it is<br />

inherently at risk from this type of attack.<br />

The standard defense against CSRF attacks is to supplement HTTP cookies<br />

with additional methods of tracking sessions. This typically takes <strong>the</strong> form<br />

of additional tokens that are transmitted via hidden fields in HTML forms.<br />

When each request is submitted, in addition to validating session cookies, <strong>the</strong><br />

<strong>application</strong> verifies that <strong>the</strong> correct token was received in <strong>the</strong> form submission.<br />

Assuming that <strong>the</strong> attacker has no way to determine <strong>the</strong> value of this token,<br />

he cannot construct a cross-domain request that succeeds in performing <strong>the</strong><br />

desired action.<br />

NOTE Even functions that are robustly defended using CSRF tokens may<br />

be vulnerable to user interface (UI) redress attacks, as described later in this<br />

chapter.<br />

When anti-CSRF tokens are used in this way, <strong>the</strong>y must be subjected to <strong>the</strong><br />

same safeguards as normal session tokens. If an attacker can predict <strong>the</strong> values<br />

of tokens that are issued to o<strong>the</strong>r users, he may be able to determine all <strong>the</strong><br />

parameters required for a CSRF request and <strong>the</strong>refore still deliver an attack.<br />

Fur<strong>the</strong>rmore, if <strong>the</strong> anti-CSRF tokens are not tied to <strong>the</strong> session of <strong>the</strong> user to<br />

whom <strong>the</strong>y were issued, an attacker may be able to obtain a valid token within his<br />

own session and use this in a CSRF attack that targets a different user’s session.<br />

TRY IT!<br />

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

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

WARNING Some <strong>application</strong>s use relatively short anti-CSRF tokens on <strong>the</strong><br />

assumption that <strong>the</strong>y will not be subjected to brute-force attacks in <strong>the</strong> way<br />

that short session tokens might be. Any attack that sent a range of possible<br />

values to <strong>the</strong> <strong>application</strong> would need to send <strong>the</strong>se via <strong>the</strong> victim’s browser,<br />

involving a large number of requests that might easily be noticed. Fur<strong>the</strong>rmore,

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

Saved successfully!

Ooh no, something went wrong!