Session Hijacking

Session Hijacking

Session hijacking is a sophisticated cyberattack method aimed at exploiting a valid computer session or session key to gain unauthorized access to information or services within a system. It is categorized as an active attack because it tampers with the data in transit or disrupts communication between systems to bypass security controls.

Pasted image 20250615180918.png

Session Hijacking Concepts and Mechanisms

In the context of web applications, session hijacking often refers to the theft of a magic cookie used to authenticate a user to a remote server. These HTTP cookies, used to maintain sessions on many websites, can be easily stolen by an attacker using an intermediary computer or access to the saved cookies on the victim's computer.

Session hijacking attempts to steal, predict, or negotiate the control mechanism of a real, valid web session to gain access to authenticated parts of a web application.

Session hijacking is also listed as an attack vector for VoIP systems and mobile platforms.

Techniques and Types of Session Hijacking

Session hijacking attacks can generally be classified into two main areas: Application-Level and Network-Level.

1. Application-Level Session Hijacking Techniques

Application-level attacks focus on compromising the session management mechanism. Attackers attempt to capture valid session cookies and IDs in established sessions.

Technique Description
Session Token Prediction Attackers determine a pattern between session IDs that the server uses. By successfully guessing previous and next session IDs, the attacker can perform malicious activities. Predicting the Initial Sequence Number (ISN) in a TCP connection is a related method used to hijack the connection.
Session Fixation This is a class of Session Hijacking where the attacker fixes an established session on the victim's browser before the user logs in. The attacker tricks the victim into authenticating the application using the attacker's known Session Identifier. If session IDs are exposed in the URL, the web application is vulnerable to session fixation attacks.
Session Replay Attackers capture user session IDs from websites and services and then reuse them to gain unauthorized access to the user account.
Session Token Tampering The attacker gains the previous and next session ID, allowing them to tamper with the session data and engage in further malicious activities.
Cookie/Session Poisoning Attackers modify cookie data to gain escalated access or assume the identity of another user. This involves modifying session-specific data such as user IDs, passwords, or account numbers stored in cookies.
Pass-the-Cookie Attack Attackers obtain a clone of a cookie from a user's browser and inject it to establish a session with the target web server, bypassing authentication controls.
Session Donation A social engineering technique where an attacker creates an account and convinces the victim to authenticate using the attacker's session ID, linking the victim's actions (e.g., payment details) to the attacker's account.
Cross-Site Scripting (XSS) Attack Attackers exploit XSS vulnerabilities to steal session cookies/tokens.
QRLJacking This social engineering attack exploits the QR Code Login method in web applications to hijack login sessions and gain unauthorized access. The attacker clones a legitimate QR code and tricks the victim into scanning it on a phishing page, sending device IDs and login credentials to the attacker's malicious web server.
Man-in-the-Middle (MiTM) In web servers, an attacker sniffs the communication between a user and the web server to steal session IDs.
Sidejacking A technique used to capture valid session cookies and IDs.

2. Network-Level Session Hijacking Techniques

Network-level attacks typically involve intercepting or monitoring network traffic.

Tools Used in Session Hijacking

Tools are used to automate the session hijacking process and test the randomness of session tokens:

Session Hijacking Process

Session hijacking can be divided into three broad phases.

Tracking the connection

The attacker uses a network sniffer to track a victim and host or uses a tool such as nmap to scan the network for a target with a TCP sequence that is easy to predict

Desynchronizing the connection

A desynchronized state occurs when a connection between a target and host is established, or stable with no data transmission or the server’s sequence number is not equal to the client’s acknowledgment number, or vice versa.

To desynchronize the connection between the target and host, the attacker must change the sequence number or acknowledgment number (SEQ/ACK) of the server

Another approach is to send a reset flag to the server to break the connection on the server side

with both the server and target attempting to verify the correct sequence

An attacker can add a desynchronizing stage to the hijack sequence to deceive the target host

Injecting the attacker's packet

Once the attacker has interrupted the connection between the server and target, they can either inject data into the network or actively participate as the man in the middle, passing data from the target to the server and vice-versa while reading and injecting data at will.

Session Hijacking Countermeasures

Countermeasures are generally divided into network configuration defenses and session management best practices.

Network and Encryption Countermeasures

To protect against session hijacking, especially those relying on sniffing:

Session Management and Application Countermeasures

Developers and administrators should implement robust session management practices:

Random Session IDs (ISN)

Use long, random session identifiers to prevent prediction and guessing. Employ random initial sequence numbers (ISNs) to prevent IP spoofing attacks based on sequence number prediction.

Server-Side Tracking

Use server-side session ID tracking and match connections with parameters such as timestamps and IP addresses.

Authentication

Implement multi-factor authentication (MFA). Do not rely solely on IP-based authentication.

Session Management

Secure Coding

Use secure session management techniques, including random session token generation. Use safe APIs that offer a parameterized interface or avoid the use of the interpreter completely.

Client-Side Security

Clear stored cookies from the browser regularly/automatically upon termination.