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.

244 Chapter 7 n Attacking Session Management<br />

HACK STEPS<br />

1. Identify any cross-site scripting vulnerabilities within <strong>the</strong> <strong>application</strong>, and<br />

determine whe<strong>the</strong>r <strong>the</strong>se can be exploited to capture <strong>the</strong> session tokens<br />

of o<strong>the</strong>r users (see Chapter 12).<br />

2. If <strong>the</strong> <strong>application</strong> issues session tokens to unau<strong>the</strong>nticated users, obtain a<br />

token and perform a login. If <strong>the</strong> <strong>application</strong> does not issue a fresh token<br />

following a successful login, it is vulnerable to session fixation.<br />

3. Even if <strong>the</strong> <strong>application</strong> does not issue session tokens to unau<strong>the</strong>nticated<br />

users, obtain a token by logging in, and <strong>the</strong>n return to <strong>the</strong> login page. If<br />

<strong>the</strong> <strong>application</strong> is willing to return this page even though you are already<br />

au<strong>the</strong>nticated, submit ano<strong>the</strong>r login as a different user using <strong>the</strong> same<br />

token. If <strong>the</strong> <strong>application</strong> does not issue a fresh token after <strong>the</strong> second<br />

login, it is vulnerable to session fixation.<br />

4. Identify <strong>the</strong> format of session tokens used by <strong>the</strong> <strong>application</strong>. Modify your<br />

token to an invented value that is validly formed, and attempt to log in.<br />

If <strong>the</strong> <strong>application</strong> allows you to create an au<strong>the</strong>nticated session using an<br />

invented token, it is vulnerable to session fixation.<br />

5. If <strong>the</strong> <strong>application</strong> does not support login, but processes sensitive user<br />

information (such as personal and payment details), and allows this to be<br />

displayed after submission (such as on a “verify my order” page), carry<br />

out <strong>the</strong> previous three tests in relation to <strong>the</strong> pages displaying sensitive<br />

data. If a token set during anonymous usage of <strong>the</strong> <strong>application</strong> can later<br />

be used to retrieve sensitive user information, <strong>the</strong> <strong>application</strong> is vulnerable<br />

to session fixation.<br />

6. If <strong>the</strong> <strong>application</strong> uses HTTP cookies to transmit session tokens, it may<br />

well be vulnerable to cross-site request forgery (XSRF). First, log in to <strong>the</strong><br />

<strong>application</strong>. Then confirm that a request made to <strong>the</strong> <strong>application</strong> but originating<br />

from a page of a different <strong>application</strong> results in submission of <strong>the</strong><br />

user’s token. (This submission needs to be made from a window of <strong>the</strong><br />

same browser process that was used to log in to <strong>the</strong> target <strong>application</strong>.)<br />

Attempt to identify any sensitive <strong>application</strong> functions whose parameters<br />

an attacker can determine in advance, and exploit this to carry out unauthorized<br />

actions within <strong>the</strong> security context of a target user. See Chapter<br />

13 for more details on how to execute XSRF attacks.<br />

Liberal Cookie Scope<br />

The usual simple summary of how cookies work is that <strong>the</strong> server issues a cookie<br />

using <strong>the</strong> HTTP response header Set-cookie, and <strong>the</strong> browser <strong>the</strong>n resubmits<br />

this cookie in subsequent requests to <strong>the</strong> same server using <strong>the</strong> Cookie header.<br />

In fact, matters are ra<strong>the</strong>r more subtle than this.

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

Saved successfully!

Ooh no, something went wrong!