There are many ways in which a malicious actor can take over a valid user session. Broadly speaking, they can be categorized as either active or passive attacks. In an active attack, the cybercriminal might use phishing or malware to obtain a session token and even alter web page content. Passive techniques tend to focus on observing traffic or activity to capture token data without immediately changing anything.
Man-in-the-Middle (MITM) Attacks
Cybercriminals can use man-in-the-middle (MITM) attacks to intercept a session token. The attacker may use a compromised network device or unsafe WiFi connection to place themselves between the target and the web server. From there they monitor the target's network traffic, waiting for them to log in to a secured account. Common subtypes include:
IP Spoofing: The attacker uses modified Internet Protocol (IP) packets to pose as an authenticated client or server.
Session Sidejacking: The attacker exploits a vulnerability found in a website's SSL (Secure Sockets Layer) encryption to expose and steal session tokens.
DNS Spoofing: The attacker exploits the caching process of a web server's Domain Name System (DNS) by replacing a stored IP address with an address that leads to an unsafe server they control.
Adversary-in-the-Middle (AiTM) Attacks
AiTM attacks are an evolution of MITM. While this approach can begin by eavesdropping on traffic, it becomes active when the attacker manipulates the data being passed between user and server. A common pattern uses phishing proxy sites that relay authentication to the real site while capturing the resulting session token.
Cross-Site Scripting (XSS)
XSS takes advantage of web application vulnerabilities to send malicious browser-side scripts to unsuspecting users. The attacker can inject a script into a trusted website, which then relays that script to the user. The target's browser sees the script as coming from a trusted source and executes it. The malicious script then accesses the target's session token and returns it to the attacker, who can use it to gain control of the account.
Session Fixation
Rather than steal a client's session token, session fixation gains access to an account by forcing the target to use a token that is already known to the attacker. This is often done via a phishing scam. The cybercriminal sends the client a link to the target web server that already contains the chosen token (typically in the URL). When the client logs in using that link, their session token becomes the one chosen by the attacker. By visiting that same URL, the attacker now has access to the target's account.
This can be done even if the web server uses server-generated session tokens. The attacker simply visits the web server to generate an ID, then sends the client a link containing that same session token in the URL. Once the client has logged in, the attacker gains access.
Cookie Theft
Cookie theft uses phishing and malware to steal a client's session token once they have logged into a secured web server. Info-stealing malware is often designed to scrape browser cookies and export them to attackers, who can then import these cookies into their own browsers to bypass authentication.
Session Token Prediction
In this type of attack, the cybercriminal gains access by predicting what a valid token will look like. Web applications that generate tokens using predictable information (such as sequential numbers, timestamps, or other patterns) are vulnerable. Attackers can analyze token patterns and then attempt possible IDs until one is successful.