Session fixation

From ShulkwiSEC/bb-huge · View interactive version

Session fixation is an AI agent skill from the GitHub repository ShulkwiSEC/bb-huge. Detect and exploit session fixation (WSTG-SESS-01, WSTG-SESS-03) and session exposure (WSTG-SESS-04) by testing whether the server issues a new session token post-authentication, whether pre-login tokens remain valid after login, and whether session IDs are transmitted over HTTP or included in GET p

How to use this skill

Skill file

Session Fixation and Session Token Exposure

What Is Broken and Why

Session fixation occurs when an application authenticates a user but retains the pre-authentication

session token rather than issuing a fresh one. An attacker who plants a known token (via URL

parameter, XSS, or network manipulation) can then authenticate as the victim by using that

same token once the victim logs in. Session token exposure extends the attack surface by allowing

tokens to be harvested from HTTP traffic, proxy logs, browser history, and caches when tokens

are transmitted without encryption or appear in GET request URLs. Predictable session tokens

that can be forged complete the trifecta of session management failures.

Key Signals

Methodology

  1. Pre-auth token capture: Visit the login page without authenticating; record all cookies

issued (note Set-Cookie headers, cookie names, values).

  1. Authentication with token intact: Submit valid credentials while preserving the pre-login

cookie; inspect response for Set-Cookie headers.

  1. Fixation test: If no new session cookie issued, the pre-auth token has been elevated to

an authenticated session — fixation confirmed.

  1. Forced cookie test: Using two accounts (attacker + victim), perform the 9-step forced

cookie scenario: snapshot pre-login cookies, authenticate as victim, restore pre-login snapshot,

attempt authenticated action, then swap and authenticate as attacker using victim's pre-login

cookies.

  1. Token randomness analysis: Collect 50+ session tokens under identical conditions within

a 50ms window; load into Burp Sequencer for statistical analysis.

  1. Transport exposure: Force HTTP access after authentication; observe if session cookie

is transmitted. Check for Secure flag.

  1. GET parameter exposure: Review all URLs and server logs for session IDs in query strings.
  2. Cache exposure: Check Cache-Control, Pragma, and Expires headers on authenticated

responses.

Payloads & Tools

# Step 1: Capture pre-login token
PRE_TOKEN=$(curl -s -c /tmp/pre_cookies.txt "https://TARGET/login" \
  -D - | grep -i "set-cookie" | grep -i "session\|jsession\|sid")
echo "Pre-login token: $PRE_TOKEN"

# Step 2: Authenticate while keeping pre-login token
curl -s -b /tmp/pre_cookies.txt -c /tmp/post_cookies.txt \
  -X POST "https://TARGET/login" \
  -d "username=VICTIM&password=VICTIM_PASS" \
  -D - | grep -i "set-cookie"

# Step 3: Compare pre and post tokens
echo "=== Pre-login cookies ===" && cat /tmp/pre_cookies.txt
echo "=== Post-login cookies ===" && cat /tmp/post_cookies.txt

# Step 4: Test if pre-login token grants authenticated access
curl -s -b "JSESSIONID=PRE_LOGIN_TOKEN_VALUE" \
  "https://TARGET/account/dashboard" -o /dev/null -w "%{http_code}"

# Transport exposure test
curl -v "http://TARGET/account/profile" \
  -b "SessionID=VALID_TOKEN" 2>&1 | grep -iE "set-cookie|location|HTTP/"

# GET parameter session ID test
curl -s "https://TARGET/page;jsessionid=SESSION_ID_VALUE" \
  -D - | grep -i "set-cookie\|200\|302"

# Cache header audit on authenticated page
curl -sI "https://TARGET/account/dashboard" \
  -b "SessionID=VALID_TOKEN" | grep -iE "cache-control|pragma|expires"

# Token entropy collection for Burp Sequencer
# (In Burp: Proxy > HTTP History > select login response > right-click > Send to Sequencer)
# Collect 100+ tokens, run analysis for effective bits of randomness

# ASP.NET Forms Auth cookie decode (check if user ID is embedded)
python3 -c "
import base64, sys
token = 'TOKEN_VALUE_HERE'
try:
    decoded = base64.b64decode(token + '==')
    print(decoded)
except Exception as e:
    print(f'Error: {e}')
"

Bypass Techniques

via HTTP subdomain or path injection to fix the session.

token remains usable, effectively still allowing fixation.

after logout if the machine key is static and the cookie has not expired.

Exploitation Scenarios

Scenario 1 — Classic Session Fixation

Setup: Application issues session token on first visit; does not rotate after login.

Trigger: Attacker tricks victim into visiting https://TARGET/login?sessionid=KNOWN_VALUE

(if app accepts session via URL); victim logs in; attacker uses same KNOWN_VALUE to access

victim's authenticated session.

Impact: Full account takeover without knowing victim's credentials.

Scenario 2 — Network Attacker Cookie Forcing

Setup: Application accepts cookies over HTTP for legacy endpoints; no __Host- prefix protections.

Trigger: Attacker on same network injects a known session cookie via HTTP response manipulation;

victim authenticates; attacker uses planted cookie to access authenticated session.

Impact: Session hijacking of any user on the same network segment.

Scenario 3 — ASP.NET Cookie Restoration After Logout

Setup: Application uses encrypted Forms Authentication cookie without server-side session store;

machine key is static.

Trigger: Post-logout, attacker restores captured .ASPXAUTH cookie (still cryptographically

valid, only blacklisted client-side); sends it to authenticated-only endpoint.

Impact: Session restoration after logout; authentication state bypass.

False Positives

not a true rotation; only a different value confirms proper rotation.

no-store prevents all local caching.

judging entropy.

Fix Patterns

authentication (session_regenerate_id(true) in PHP; Session.Abandon() + new session in ASP.NET).

Related Skills

Session fixation and [[cookie-attacks]] are two sides of the same session management problem — fixation exploits the lack of rotation on login, while cookie-attacks exploit weak attributes after the session is established. [[csrf]] can be used to fix a session: if a login form accepts a GET with a sessionid parameter, a CSRF payload can force the victim's browser to submit it. Missing __Host- or __Secure- prefixes (covered in [[cookie-attacks]]) are also prerequisites for session fixation via HTTP subdomain injection.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.