Courses3 levels
Level 1 · Foundations11 courses
Level 2 · Core5 courses
Level 3 · Advanced5 courses
Labs8 topics
Library Practice exams AI Range Pricing Start free

Practice library / Web attacks

Lab · Medium · 1.5 hoursFree account

Broken Authentication & Sessions

Session fixation, token prediction, hijacking, weak cookie flags, and logout/timeout failures.

  • session-management
  • session-fixation
  • cookies
  • authentication
On this page 13 sections
  1. ·Why Sessions Break
  2. ·Prerequisites
  3. ·Build the target
  4. 1Read the Session Cookie's Attributes
  5. 2Measure Whether the Token Is Predictable
  6. Locked: Exploit Session Fixation
  7. Locked: Hijack the Session
  8. Locked: Capture the Cookie in Cleartext
  9. Locked: Confirm Logout Never Invalidates the Session
  10. Locked: Confirm the Idle Timeout Is Not Enforced
  11. Locked: Map Each Finding to a Detection Signal and a Control
  12. Locked: Check Your Work
  13. Locked: Clean Up and Next Lab

Most logins fail long after the password check. Once a server hands a user a session token, the token — not the credentials — is what every later request trusts, and weak cookie flags, predictable IDs, or a logout that never invalidates server state turn that trust into a hijack. The engineer walks the full session lifecycle: fixation, replay, cookie-flag audits, and an idle timeout that never fires.

What You'll Learn

  • Read a session cookie's attributes and name which protections (Secure, HttpOnly, SameSite) are missing
  • Measure whether a session token is predictable, by comparing several freshly issued IDs
  • Exploit session fixation by planting a session ID that a victim's login never replaces
  • Hijack an authenticated session by replaying a captured or guessed session ID
  • Prove a session stays valid after logout and after its own idle timeout
  • Map each finding to a log-based detection signal and a server-side control that closes it

Why Sessions Break

OWASP groups this under A07:2021 — Identification and Authentication Failures (OWASP Top 10, CC BY-SA 4.0), which absorbed the old "Broken Authentication" category. Most of these findings have nothing to do with the password check. Once a user authenticates, the server hands them a session token and trusts that token for every request that follows. If that token is predictable, never rotates, outlives logout, or travels without the cookie flags that protect it, the login form itself was never the weak point — the session was.

This lab works entirely after a successful login. You will attack the session mechanism of a target that you build, confirm each weakness with a command and its output, and finish by writing down how a defender catches the same activity in logs.

Prerequisites

  • Burp Suite Basics — this lab repeats requests with one changed value (a cookie). Burp Repeater does that without retyping a curl command each time; the steps below give you the raw curl form either way.
  • Web Fuzzing & Directory Brute Forcing — recommended, not required. If the login, dashboard and logout paths were not given to you, this is how you would have found them.
  • HTTP Misconfiguration Abuse — recommended. It covers cookie and header misconfiguration in more depth than this lab's Step 1.
  • Comfort with curl and with reading raw HTTP request and response headers.

Build the target

KaliRange hosts no targets, no virtual machines and no lab files. You run this lab on your own machine, against a small portal that you build. 10.0.5.20, "RangeCorp Intranet" and the 10.0.6.x addresses are the example names and addresses of this lab. Replace them with your own.

Your lab must have these parts:

  • Attack box: your own Kali Linux machine with curl and tcpdump installed. Burp Suite is optional. Every step gives the raw curl command, and you can repeat the same request in Burp Repeater instead if you prefer.
  • Target: a small portal at 10.0.5.20 with POST /login, GET /dashboard (session-protected) and GET /logout. The session cookie is named RANGESESSID.
  • Lab account: username analyst, password TrainLab2026!. It exists only on your target. Use your own password and put it in the commands. Never reuse it anywhere else.
  • Session behaviour that the steps show: the cookie value is a small number that counts up (10621, 10622, ...). The cookie has no Secure, HttpOnly or SameSite attribute. Login keeps the session ID that the client sends. Logout does not end the session on the server. The idle timeout is set to two minutes, and the server does not enforce it.
  • Plain HTTP: the target serves RANGESESSID over plain HTTP, so that Step 5 can show the cookie on the wire. A real application must use HTTPS only.
  • Access log (Step 8): /var/log/rangecorp/access.log records the client address first and then the cookie. It holds one session ID, RANGESESSID=10621, from two client addresses (10.0.6.15 and 10.0.6.20).

Build it from free, legal parts: a small web application of your own, in a container or a virtual machine on your own computer. No public training target is named here, because this lab needs this exact cookie behaviour. Take a snapshot or note the container state before Step 1.

Authorized lab only. Run every command in this lab only against a target that you own or have written permission to test, here 10.0.5.20, using only the lab account above. Do not point these techniques at any system you do not own or do not have explicit written authorization to test. Session hijacking against a real user is a criminal offense in most countries.

Step 1: Read the Session Cookie's Attributes

1

Log in and inspect the Set-Cookie header, not the page

The attributes on Set-Cookie decide how much protection the token gets. Read them before you touch anything else.

curl -s -i -X POST http://10.0.5.20/login \
  -d "username=analyst&password=TrainLab2026!" | grep -i '^set-cookie:'

Example output:

Set-Cookie: RANGESESSID=10621; Path=/

Why it matters. Compare this to what a hardened session cookie needs. Secure means the browser never sends the cookie over plain HTTP. HttpOnly means JavaScript cannot read the cookie, so a script-injection bug cannot steal it. SameSite=Strict means the browser never sends the cookie on any cross-site request. SameSite=Lax withholds the cookie on cross-site subresource and non-GET requests, but still sends it on a cross-site top-level navigation, such as following a link. All three are absent here. Each missing attribute is a separate finding you will exploit or reference in the steps below.

Step 2: Measure Whether the Token Is Predictable

2

Request several fresh sessions and compare the IDs

A session ID must be unguessable. Request the login page several times with no cookie sent, and look at the pattern across the values the server hands back.

for i in {1..5}; do
  curl -s -D - http://10.0.5.20/login -o /dev/null | grep -i '^set-cookie:'
done

Example output:

Set-Cookie: RANGESESSID=10621; Path=/
Set-Cookie: RANGESESSID=10622; Path=/
Set-Cookie: RANGESESSID=10623; Path=/
Set-Cookie: RANGESESSID=10624; Path=/
Set-Cookie: RANGESESSID=10625; Path=/

Why it matters. This is not a random token. It is a small incrementing integer, almost certainly a database row ID reused as the session identifier. A session ID built this way carries close to zero bits of real unpredictability: an attacker who knows one valid value can try its neighbours. A production session ID needs at least 128 bits from a cryptographically secure generator, not a counter. The numbers in this lab are illustrative. The counter increases with every request, so your own session IDs will be higher than the examples shown here, and they will differ between runs.

Sign in to continue

8 more sections are for signed-in members. It is free: sign in with Google.

Related