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.

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

Cross-Site Request Forgery<br />

In cross-site request forgery (CSRF) attacks, <strong>the</strong> attacker creates an innocuouslooking<br />

<strong>web</strong>site that causes <strong>the</strong> user’s browser to submit a request directly to<br />

<strong>the</strong> vulnerable <strong>application</strong> to perform some unintended action that is beneficial<br />

to <strong>the</strong> attacker.<br />

Recall that <strong>the</strong> same-origin policy does not prohibit one <strong>web</strong>site from issuing<br />

requests to a different domain. It does, however, prevent <strong>the</strong> originating <strong>web</strong>site<br />

from processing <strong>the</strong> responses to cross-domain requests. Hence, CSRF attacks<br />

normally are “one-way” only. Multistage actions such as those involved in <strong>the</strong><br />

Samy XSS worm, in which data is read from responses and incorporated into<br />

later requests, cannot be performed using a pure CSRF attack. (Some methods<br />

by which CSRF techniques can be extended to perform limited two-way attacks,<br />

and capture data cross-domain, are described later in this chapter.)<br />

Consider an <strong>application</strong> in which administrators can create new user accounts<br />

using requests like <strong>the</strong> following:<br />

POST /auth/390/NewUserStep2.ashx HTTP/1.1<br />

Host: mdsec.net<br />

Cookie: SessionId=8299BE6B260193DA076383A2385B07B9<br />

Content-Type: <strong>application</strong>/x-www-form-urlencoded<br />

Content-Length: 83<br />

realname=daf&username=daf&userrole=admin&password=letmein1&<br />

confirmpassword=letmein1<br />

This request has three key features that make it vulnerable to CSRF attacks:<br />

n The request performs a privileged action. In <strong>the</strong> example shown, <strong>the</strong><br />

request creates a new user with administrative privileges.<br />

n The <strong>application</strong> relies solely on HTTP cookies for tracking sessions. No<br />

session-related tokens are transmitted elsewhere within <strong>the</strong> request.<br />

n The attacker can determine all <strong>the</strong> parameters required to perform <strong>the</strong><br />

action. Aside from <strong>the</strong> session token in <strong>the</strong> cookie, no unpredictable values<br />

need to be included in <strong>the</strong> request.<br />

Taken toge<strong>the</strong>r, <strong>the</strong>se features mean that an attacker can construct a <strong>web</strong><br />

page that makes a cross-domain request to <strong>the</strong> vulnerable <strong>application</strong> containing<br />

everything needed to perform <strong>the</strong> privileged action. Here is an example of<br />

such an attack:<br />

<br />

<br />

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

Saved successfully!

Ooh no, something went wrong!