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

The simplest and still most common means of implementing sessions is to<br />

issue each user a unique session token or identifier. On each subsequent request<br />

to <strong>the</strong> <strong>application</strong>, <strong>the</strong> user resubmits this token, enabling <strong>the</strong> <strong>application</strong> to<br />

determine which sequence of earlier requests <strong>the</strong> current request relates to.<br />

In most cases, <strong>application</strong>s use HTTP cookies as <strong>the</strong> transmission mechanism<br />

for passing <strong>the</strong>se session tokens between server and client. The server’s first<br />

response to a new client contains an HTTP header like <strong>the</strong> following:<br />

Set-Cookie: ASP.NET_SessionId=mza2ji454s04cwbgwb2ttj55<br />

and subsequent requests from <strong>the</strong> client contain this header:<br />

Cookie: ASP.NET_SessionId=mza2ji454s04cwbgwb2ttj55<br />

This standard session management mechanism is inherently vulnerable to<br />

various categories of attack. An attacker’s primary objective in targeting <strong>the</strong><br />

mechanism is to somehow hijack <strong>the</strong> session of a legitimate user and <strong>the</strong>reby<br />

masquerade as that person. If <strong>the</strong> user has been au<strong>the</strong>nticated to <strong>the</strong> <strong>application</strong>,<br />

<strong>the</strong> attacker may be able to access private data belonging to <strong>the</strong> user or carry<br />

out unauthorized actions on that person’s behalf. If <strong>the</strong> user is unau<strong>the</strong>nticated,<br />

<strong>the</strong> attacker may still be able to view sensitive information submitted by <strong>the</strong><br />

user during her session.<br />

As in <strong>the</strong> previous example of a Microsoft IIS server running ASP.NET, most<br />

commercial <strong>web</strong> servers and <strong>web</strong> <strong>application</strong> platforms implement <strong>the</strong>ir own<br />

off-<strong>the</strong>-shelf session management solution based on HTTP cookies. They provide<br />

APIs that <strong>web</strong> <strong>application</strong> developers can use to integrate <strong>the</strong>ir own sessiondependent<br />

functionality with this solution.<br />

Some off-<strong>the</strong>-shelf implementations of session management have been found to<br />

be vulnerable to various attacks, which results in users’ sessions being compromised<br />

(<strong>the</strong>se are discussed later in this chapter). In addition, some developers find<br />

that <strong>the</strong>y need more fine-grained control over session behavior than is provided<br />

for <strong>the</strong>m by <strong>the</strong> built-in solutions, or <strong>the</strong>y want to avoid some vulnerabilities<br />

inherent in cookie-based solutions. For <strong>the</strong>se reasons, it is fairly common to see<br />

bespoke and/or non-cookie-based session management mechanisms used in<br />

security-critical <strong>application</strong>s such as online banking.<br />

The vulnerabilities that exist in session management mechanisms largely<br />

fall into two categories:<br />

n Weaknesses in <strong>the</strong> generation of session tokens<br />

n Weaknesses in <strong>the</strong> handling of session tokens throughout <strong>the</strong>ir life cycle<br />

We will look at each of <strong>the</strong>se areas in turn, describing <strong>the</strong> different types of<br />

defects that are commonly found in real-world session management mechanisms,<br />

and practical techniques for discovering and exploiting <strong>the</strong>se. Finally,<br />

we will describe measures that <strong>application</strong>s can take to defend <strong>the</strong>mselves<br />

against <strong>the</strong>se attacks.

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

Saved successfully!

Ooh no, something went wrong!