Skip to content

Sessions

A session attack is any path from “anonymous attacker outside the application” to “logged-in user inside it” that doesn’t require knowing the victim’s password. The session identifier (a cookie, almost always) is the only thing the server checks for every request after login - so anything that puts a valid identifier in the attacker’s hands grants the victim’s identity.

# 1. Identify the session identifier
# Browser DevTools → Storage → Cookies; look for HttpOnly, Secure, SameSite flags
# 2. Harvest it via one of:
# - Sniffing plaintext HTTP (network position required)
# - XSS that exfiltrates document.cookie (HttpOnly absent)
# - Open redirect that leaks tokens in URL parameters
# - Post-exploit retrieval from /var/lib/php/sessions or the DB
# 3. Ride it
# Browser: open private window, paste cookie, navigate, you are logged in
# curl: curl -b 'session=ABC...' http://target/account
# Burp: swap cookie in Repeater/Intercept
# 4. Chain when sessions are well-defended
# XSS → bypasses SameSite (request originates from the target's own origin)
# Open redirect → leaks tokens included in redirect URLs
# CSRF token theft via HTML injection → bypasses anti-CSRF on POST

Success indicator: the attacker’s browser, curl, or Burp lab is making authenticated requests on the victim’s behalf - the server treats the requests as the victim’s own.

HTTP is stateless. Every request stands alone - the server has no way to know it’s the same user from one request to the next except by what the request itself carries. Web apps solve this by issuing a session identifier (random string) at login, storing it as a cookie in the browser, and looking up the user’s state in a server-side store on every subsequent request that presents that identifier. The session identifier is therefore equivalent to the user’s authenticated identity for the duration of the session. Steal it, and you’re them.

A “session attack” is any of:

AttackWhat it doesWhen it works
HijackingTake a session identifier you already have, use itAlways - the question is how you got the identifier
FixationForce the victim to use an identifier you set, then ride it after they log inWhen the app reuses pre-login session IDs after auth
SniffingRead identifiers off the wirePlaintext HTTP traffic + network position
XSS exfiltrationJavaScript in the victim’s browser reads document.cookie and sends it to youXSS + HttpOnly not set on cookies
CSRFIssue authenticated requests in the victim’s name without needing the cookie valueThe server checks cookies but no anti-CSRF token (or you can bypass it)
Open redirect token leakCoerce the app to include the token in a URL pointing to attacker-controlled domainApp’s redirect doesn’t validate target + tokens travel in URLs or POST bodies that follow redirects
Post-exploitation retrievalRead session-store files from a server you’ve already compromisedRCE on the app server
Database session theftRead session table from a compromised databaseDB compromise + sessions stored in DB

The TL;DR’s flow - identify → harvest → ride → chain - is the four-step lens you apply to every engagement.

Knowing where the identifier is stored tells you which attacks are viable:

StorageStealable viaSurvives across
Cookie (HTTP Cookie: header)XSS (unless HttpOnly), sniffing (unless Secure+TLS), CSRF without needing the valueTabs, restarts (if persistent)
URL parameterReferer header leak, browser history, server logs, screen-share recordingsURL navigation only
Hidden form fieldXSS (read the DOM), HTML injection (leak via crafted markup)Page reload only - gone on navigation
localStorageXSS (any script can read it; HttpOnly doesn’t apply)Browser restart
sessionStorageXSS (same scope as localStorage)Tab close
HTTP Authorization: header (Bearer token)XSS + JS reads from app state, sniffing without TLS, RCE on app serverSession lifetime
Server-side filePost-exploit RCE on app serverUntil session expires server-side
Server-side DB rowDB compromise (SQLi, credential theft)Until session expires server-side

The cookie with HttpOnly + Secure + SameSite=Strict is the strongest browser-side configuration. Cookies without these flags are XSS-readable, sniff-able, and CSRF-rideable respectively. Tokens stored in localStorage are always JavaScript-accessible - moving a token from a HttpOnly cookie to localStorage for “convenience” downgrades security.

PageFocus
HijackingThe mechanics of riding a stolen identifier - DevTools cookie swap, Burp swap, curl with -b/-c
FixationForcing a known identifier on the victim; auth-doesn’t-regenerate detection
Obtaining tokensSniffing (Wireshark, mitmproxy, ARP poisoning context), post-exploit retrieval (PHP/Java/.NET paths), DB extraction
XSS to sessionXSS as a cookie-stealing primitive; cookie-logger PHP server; HttpOnly check; XSSHunter/Collaborator/Interactsh callback infra
CSRFCSRF fundamentals; HTML auto-submit forms; GET vs POST; SameSite; anti-CSRF tokens
CSRF token bypassWeak token analysis (md5(username)), null/blank/random token bypass, cross-account tokens, Referer regex bypass, method tampering
XSS + CSRF chainWhen SameSite blocks cross-origin requests: stage the request from the target’s own origin via XSS; the XMLHttpRequest token-extract pattern
Open redirectDiscovery patterns (?url=, ?redirect=, ?next=…); leaking session tokens that travel with redirects; phishing chains
Chaining finalEnd-to-end engagement: XSS in profile + open redirect on admin endpoint → admin session theft, the canonical real-world chain

This cluster overlaps with several others; each link gives the operator-level details the sessions material assumes:

TopicPage
Cookie attributes deep-diveAuth: cookie tampering
Session fixation fundamentalsAuth: session fixation
JWT-specific attacksAuth: JWT
Password reset flowsAuth: reset tokens
File upload that delivers XSSUploads
Server-side compromise to access sessionsLFI, Server-side
SQL injection to dump session tablesSQLi cluster

XSS and CSRF have full pentest curricula of their own - XSS especially has its own taxonomy (reflected, stored, DOM-based, mutation, blind). This cluster covers them through the lens of what makes them useful for stealing or hijacking sessions specifically, which is one of the highest-impact outcomes of those vulnerabilities. The page on XSS-to-session doesn’t try to be a complete XSS reference; it covers cookie exfiltration patterns and callback infrastructure. Similarly, CSRF coverage focuses on session-effective abuse (state-changing actions on the user’s behalf), not on every CSRF defense or weird edge case.

When a finding turns out to deserve fuller treatment beyond session-attack utility - e.g., a DOM-based XSS chain that requires deep prototype-pollution understanding - that’s the moment to escalate beyond this cluster.