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.

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

Exploiting CSRF Flaws<br />

CSRF vulnerabilities arise primarily in cases where <strong>application</strong>s rely solely on<br />

HTTP cookies for tracking sessions. Once an <strong>application</strong> has set a cookie in a<br />

user’s browser, <strong>the</strong> browser automatically submits that cookie to <strong>the</strong> <strong>application</strong><br />

in every subsequent request. This is true regardless of whe<strong>the</strong>r <strong>the</strong> request originates<br />

from a link, form within <strong>the</strong> <strong>application</strong> itself, or from any o<strong>the</strong>r source<br />

such as an external <strong>web</strong>site or a link clicked in an e-mail. If <strong>the</strong> <strong>application</strong> does<br />

not take precautions against an attacker’s “riding” on its users’ sessions in this<br />

way, it is vulnerable to CSRF.<br />

HACK STEPS<br />

1. Review <strong>the</strong> key functionality within <strong>the</strong> <strong>application</strong>, as identified in your<br />

<strong>application</strong> mapping exercises (see Chapter 4).<br />

2. Find an <strong>application</strong> function that can be used to perform some sensitive<br />

action on behalf of an unwitting user, that relies solely on cookies<br />

for tracking user sessions, and that employs request parameters that an<br />

attacker can fully determine in advance—that is, that do not contain any<br />

o<strong>the</strong>r tokens or unpredictable items.<br />

3. Create an HTML page that issues <strong>the</strong> desired request without any user<br />

interaction. For GET requests, you can place an tag with <strong>the</strong> src<br />

attribute set to <strong>the</strong> vulnerable URL. For POST requests, you can create a<br />

form that contains hidden fields for all <strong>the</strong> relevant parameters required<br />

for <strong>the</strong> attack and that has its target set to <strong>the</strong> vulnerable URL. You can<br />

use JavaScript to autosubmit <strong>the</strong> form as soon as <strong>the</strong> page loads.<br />

4. While logged in to <strong>the</strong> <strong>application</strong>, use <strong>the</strong> same browser to load your<br />

crafted HTML page. Verify that <strong>the</strong> desired action is carried out within <strong>the</strong><br />

<strong>application</strong>.<br />

TIP The possibility of CSRF attacks alters <strong>the</strong> impact of numerous o<strong>the</strong>r<br />

categories of vulnerability by introducing an additional vector for <strong>the</strong>ir exploitation.<br />

For example, consider an administrative function that takes a user<br />

identifier in a parameter and displays information about <strong>the</strong> specified user.<br />

The function is subject to rigorous access control, but it contains a SQL injection<br />

vulnerability in <strong>the</strong> uid parameter. Since <strong>application</strong> administrators are<br />

trusted and have full control of <strong>the</strong> database in any case, <strong>the</strong> SQL injection<br />

vulnerability might be considered low risk. However, because <strong>the</strong> function<br />

does not (as originally intended) perform any administrative action, it is not<br />

protected against CSRF. From an attacker’s perspective, <strong>the</strong> function is just as

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

Saved successfully!

Ooh no, something went wrong!