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.

240 Chapter 7 n Attacking Session Management<br />

TRY IT!<br />

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

Vulnerable Mapping of Tokens to Sessions<br />

Various common vulnerabilities in session management mechanisms arise<br />

because of weaknesses in how <strong>the</strong> <strong>application</strong> maps <strong>the</strong> creation and processing<br />

of session tokens to individual users’ sessions <strong>the</strong>mselves.<br />

The simplest weakness is to allow multiple valid tokens to be concurrently<br />

assigned to <strong>the</strong> same user account. In virtually every <strong>application</strong>, <strong>the</strong>re is no<br />

legitimate reason why any user should have more than one session active at<br />

one time. Of course, it is fairly common for a user to abandon an active session<br />

and start a new one — for example, because he closes a browser window or<br />

moves to a different computer. But if a user appears to be using two different<br />

sessions simultaneously, this usually indicates that a security compromise has<br />

occurred: ei<strong>the</strong>r <strong>the</strong> user has disclosed his credentials to ano<strong>the</strong>r party, or an<br />

attacker has obtained his credentials through some o<strong>the</strong>r means. In both cases,<br />

permitting concurrent sessions is undesirable, because it allows users to persist<br />

in undesirable practices without inconvenience and because it allows an attacker<br />

to use captured credentials without risk of detection.<br />

A related but distinct weakness is for <strong>application</strong>s to use “static” tokens.<br />

These look like session tokens and may initially appear to function like <strong>the</strong>m,<br />

but in fact <strong>the</strong>y are no such thing. In <strong>the</strong>se <strong>application</strong>s, each user is assigned<br />

a token, and this same token is reissued to <strong>the</strong> user every time he logs in. The<br />

<strong>application</strong> always accepts <strong>the</strong> token as valid regardless of whe<strong>the</strong>r <strong>the</strong> user<br />

has recently logged in and been issued with it. Applications like this really<br />

involve a misunderstanding about <strong>the</strong> whole concept of what a session is, and<br />

<strong>the</strong> benefits it provides for managing and controlling access to <strong>the</strong> <strong>application</strong>.<br />

Sometimes, <strong>application</strong>s operate like this as a means of implementing poorly<br />

designed “remember me” functionality, and <strong>the</strong> static token is accordingly<br />

stored in a persistent cookie (see Chapter 6). Sometimes <strong>the</strong> tokens <strong>the</strong>mselves<br />

are vulnerable to prediction attacks, making <strong>the</strong> vulnerability far more serious.<br />

Ra<strong>the</strong>r than compromising <strong>the</strong> sessions of currently logged-in users, a successful<br />

attack compromises, for all time, <strong>the</strong> accounts of all registered users.<br />

O<strong>the</strong>r kinds of strange <strong>application</strong> behavior are also occasionally observed<br />

that demonstrate a fundamental defect in <strong>the</strong> relationship between tokens and<br />

sessions. One example is where a meaningful token is constructed based on a<br />

username and a random component. For example, consider <strong>the</strong> token:<br />

dXNlcj1kYWY7cjE9MTMwOTQxODEyMTM0NTkwMTI=<br />

which Base64-decodes to:<br />

user=daf;r1=13094181213459012

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

Saved successfully!

Ooh no, something went wrong!