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 537<br />

if <strong>the</strong> targeted <strong>application</strong> uses only HTTPS and its cookies are flagged as<br />

secure. This kind of attack is described in more detail later in this chapter.<br />

If an attacker can set an arbitrary cookie, this can be leveraged in various<br />

ways to compromise <strong>the</strong> targeted user:<br />

n Depending on <strong>the</strong> <strong>application</strong>, setting a specific cookie may interfere<br />

with <strong>the</strong> <strong>application</strong>’s logic to <strong>the</strong> user’s disadvantage (for example,<br />

UseHttps=false).<br />

n Since cookies usually are set only by <strong>the</strong> <strong>application</strong> itself, <strong>the</strong>y may be<br />

trusted by client-side code. This code may process cookie values in ways<br />

that are dangerous for attacker-controllable data, leading to DOM-based<br />

XSS or JavaScript injection.<br />

n Instead of tying anti-CSRF tokens to a user’s session, some <strong>application</strong>s<br />

work by placing <strong>the</strong> token into both a cookie and a request parameter and<br />

<strong>the</strong>n comparing <strong>the</strong>se values to prevent CSRF attacks. If <strong>the</strong> attacker controls<br />

both <strong>the</strong> cookie and <strong>the</strong> parameter value, this defense can be bypassed.<br />

n As was described earlier in this chapter, some same-user persistent XSS<br />

can be exploited via a CSRF attack against <strong>the</strong> login function to log <strong>the</strong> user<br />

in to <strong>the</strong> attacker’s account and <strong>the</strong>refore access <strong>the</strong> XSS payload. If <strong>the</strong><br />

login page is robustly protected against CSRF, this attack fails. However,<br />

if <strong>the</strong> attacker can set an arbitrary cookie in <strong>the</strong> user’s browser, he can<br />

perform <strong>the</strong> same attack by passing his own session token directly to <strong>the</strong><br />

user, bypassing <strong>the</strong> need for a CSRF attack against <strong>the</strong> login function.<br />

n Setting arbitrary cookies can allow session fixation vulnerabilities to be<br />

exploited, as described in <strong>the</strong> next section.<br />

Session Fixation<br />

Session fixation vulnerabilities typically arise when an <strong>application</strong> creates an<br />

anonymous session for each user when she first accesses <strong>the</strong> <strong>application</strong>. If <strong>the</strong><br />

<strong>application</strong> contains a login function, this anonymous session is created prior<br />

to login and <strong>the</strong>n is upgraded to an au<strong>the</strong>nticated session after <strong>the</strong> user logs in.<br />

The same token that initially confers no special access later allows privileged<br />

access within <strong>the</strong> security context of <strong>the</strong> au<strong>the</strong>nticated user.<br />

In a standard session hijacking attack, <strong>the</strong> attacker must use some means to<br />

capture <strong>the</strong> session token of an <strong>application</strong> user. In a session fixation attack, on<br />

<strong>the</strong> o<strong>the</strong>r hand, <strong>the</strong> attacker first obtains an anonymous token directly from<br />

<strong>the</strong> <strong>application</strong> and <strong>the</strong>n uses some means to fix this token within a victim’s<br />

browser. After <strong>the</strong> user has logged in, <strong>the</strong> attacker can use <strong>the</strong> token to hijack<br />

<strong>the</strong> user’s session.<br />

Figure 13-4 shows <strong>the</strong> steps involved in a successful session fixation attack.

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

Saved successfully!

Ooh no, something went wrong!