Attacking Session Management | Session Hijack Attack




Let’s start with the explanation of the session management role. This mechanism is a fundamental security component in the majority of web apps. It enables the application to uniquely identify a given user across a number of different requests. It also enables handling the data that it accumulates about the state of the user’s interaction with the application. The session management mechanism persists the insurance of any given user’s identity beyond the request in which he supplies his credentials. They are the crucial target of the malicious attacks because they have such an important role in securing the user and the system. Before we go further, I would recommend you to take a look at the cyber security tips for better understanding the text that will follow.

The Need for State

We know that the HTTP protocol is stateless. Based on a simple request-response model. Nowadays, the things changed. Most of the web sites are actually the web applications, allowing you to register and log in. They let you do almost everything over the internet-sell and buy things, promotion, and anything you use for your purposes. But do you really know how to use the internet in a proper and safe way? Before I go further, read about the internet security tips.

Some web applications use other techniques to stay safe, not only sessions employ. We will talk about the alternatives now. Let’s start from the HTTP authentication. With this authentication, the client component interacts with the authentication mechanism directly over the browser. It uses HTTP headers. There is another alternative method called sessionless state mechanisms. Some apps transmit the data which is required to manage that state via the client. It happens usually in a cookie or a hidden form field.

Weakness in Token Generation

Tokens are mostly generated in an unsafe way and that is why session management mechanisms are often vulnerable to attacks. The hacker can easily identify the value of the token that has been issued to the other users. Most of the times those tokens contain meaningful data which often exhibit a structure. In that extracted case, the attacker can easily identify the parts of the tokens and get into the account username, email address or the client IP address and much more.

But, there are some session tokens which don’t contain any meaningful data which can be associated with a particular user. Those tokens are called predictable tokens. And why is that so? Because they can be guessed easily. They also contain the sequences and patterns that allow an attacker to extrapolate from a sample of tokens in the order to find the other valid token which is recently issued by the app.

Weakness in Session Token Handling

It really doesn’t matter how effective the application is at ensuring that the session tokens it generates don’t have any information which is meaningful and are not suspectable to any analysis or prediction. Still, its session mechanisms will be wide opened for the attacks. It happens in the case the tokens are not handled carefully after generation.

So, what is the best thing to do? We will now talk about the disclosure of tokens on the network. This threat arises when the session token transmits across the network in the unencrypted form. In that way, it enables a suitably positioned eavesdropper to obtain that token and the attacker can mask himself as the legitimate user.

What is the simplest weakness? It happens when the multiple valid tokens allow being concurrently assigned to the same user account. There is another related and similar weakness, and it happens within the applications which use the static tokens. They mainly and initially appears to look like session tokens, but in the reality, they’re nothing like them. Here, each user is assigned token and in that case, that same token is reissued to the user every time he logs in.

Client Exposure to Token Hijacking

In the attempt to capture or misuse the victim’s session token in various ways, the attacker can target the other users of the application. It can happen through a payload for cross-site scripting attacks. The hijacker sometimes waits for the user to log in, and once that happens, he hijacks the user’s session.

Securing Session Management

What are the defensive measures that web application must take to prevent the attacks on their session management mechanisms? Well, the application must generate its tokens in a robust way and must protect these tokens throughout their life cycle from creating to disposal.

Let’s talk about generating the strong tokens. The tokens which are used to reidentify a user between successive requests should be generated in such a manner that does not provide any scope for the attacker who may obtain a large sample of tokens from the app in the usual way to predict or extrapolate the tokens issued to the other users. So, what are the most effective token generation mechanisms? First of all, to use an extremely large set of possible values. And the second thing would be containing a strong source of pseudorandomness, which ensures an even and unpredictable spread of the tokens across the range of possible values. The strong tokens should be extremely unlikely that a determined attacker with large amounts of bandwidth and processing resources should be successful in guessing a single valid token within the life span of the token’s validity. They also shouldn’t consist anything more than an identifier used by the server for locating the relevant session object which is going to be used for processing the user’s request. It should contain also no meaning of structure (overtly or wrapped in layers of encoding or obfuscating).

Log, Monitor, and Alert

It is highly recommended that the app’s session management functionality should be closely integrated with its mechanisms for logging, and alerting. That provides suitable records of anomalous activity and enables the administrators to take the proper defensive actions when and where it is necessary.

The app needs to monitor the requests which contain invalid tokens. Sometimes, it is the truth that brute-force attacks cannot be prevented. Although, not all is lost. Keeping detailed logs and alerting administrators enables the investigation of the attack and taking the appropriate actions where needed and possible.

The user should be always alerted, whenever it is possible, to anomalous events relating to their sessions. For an example, concurrent logins or apparent hijacking. It can be detected by using per-page tokens.

So, let’s make a summary and take a look what have we learned today! I hope you’ve gained so many important information about session management mechanisms. They provide a rich source of potential vulnerabilities. They are literally the key to the kingdom. That is why we talked so much about the tokens in this article, and what are the best and proper ways to use them. It is normal to expect the wide range of defects in real-world session management functionality. The possible weaknesses and avenues of attack may appear to be endless when bespoke mechanisms are employed.