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 7 n Attacking Session Management 217<br />

This second observation immediately alerts us to <strong>the</strong> role played by time<br />

in generating session tokens. Apparently, only five tokens have been issued<br />

between <strong>the</strong> two token-grabbing exercises. However, a period of approximately<br />

10 minutes has elapsed. The most likely explanation is that <strong>the</strong> second number<br />

is time-dependent and is probably a simple count of milliseconds.<br />

Indeed, our hunch is correct. In a subsequent phase of our testing we perform<br />

a code review, which reveals <strong>the</strong> following token-generation algorithm:<br />

String sessId = Integer.toString(s_SessionIndex++) +<br />

“-” +<br />

System.currentTimeMillis();<br />

Given our analysis of how tokens are created, it is straightforward to construct<br />

a scripted attack to harvest <strong>the</strong> session tokens that <strong>the</strong> <strong>application</strong> issues<br />

to o<strong>the</strong>r users:<br />

n We continue polling <strong>the</strong> server to obtain new session tokens in quick<br />

succession.<br />

n We monitor <strong>the</strong> increments in <strong>the</strong> first number. When this increases by<br />

more than 1, we know that a token has been issued to ano<strong>the</strong>r user.<br />

n When a token has been issued to ano<strong>the</strong>r user, we know <strong>the</strong> upper and<br />

lower bounds of <strong>the</strong> second number that was issued to that person, because<br />

we possess <strong>the</strong> tokens that were issued immediately before and after<br />

his. Because we are obtaining new session tokens frequently, <strong>the</strong> range<br />

between <strong>the</strong>se bounds will typically consist of only a few hundred values.<br />

n Each time a token is issued to ano<strong>the</strong>r user, we launch a brute-force attack<br />

to iterate through each number in <strong>the</strong> range, appending this to <strong>the</strong> missing<br />

incremental number that we know was issued to <strong>the</strong> o<strong>the</strong>r user. We<br />

attempt to access a protected page using each token we construct, until<br />

<strong>the</strong> attempt succeeds and we have compromised <strong>the</strong> user’s session.<br />

n Running this scripted attack continuously will enable us to capture <strong>the</strong><br />

session token of every o<strong>the</strong>r <strong>application</strong> user. When an administrative<br />

user logs in, we will fully compromise <strong>the</strong> entire <strong>application</strong>.<br />

TRY IT!<br />

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

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

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

http://mdsec.net/auth/351/

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

Saved successfully!

Ooh no, something went wrong!