Hello!
In our last lesson, we successfully executed credential-based attacks to gain access to a user account. Upon a successful login, an application issues a session token to maintain the user's authenticated state. This token is the key to the kingdom for the duration of the session.
Today's lesson focuses on the learning outcome: Analyze session token generation to identify weak or predictable identifiers. A weak token can be a far more critical vulnerability than a single compromised password. If you can predict or forge a valid session token, you might be able to impersonate any user, not just the one whose password you cracked. This is a classic route to privilege escalation and a high-impact finding in bug bounties.
We will explore two primary categories of session tokens:
- Opaque tokens, which are intended to be random, unpredictable strings.
- Structured tokens, like JSON Web Tokens (JWTs), which contain data and are protected by a cryptographic signature.
Let's begin by understanding the different ways applications can manage sessions.

1. The Art of Analyzing Opaque Session Tokens
An ideal session token is a long, random string with high entropy, making it computationally infeasible to guess. However, developers sometimes make mistakes, creating tokens that are predictable. Our job as testers is to find these patterns.
The OWASP Web Security Testing Guide (WSTG) provides a solid framework for this analysis. The process involves collecting tokens, analyzing them for randomness and patterns, and identifying any manipulable information.
WSTG - Latest | Testing for Session Management Schema
To understand the foundational principles of this process, please read the following sections from the OWASP WSTG on 'Testing for Session Management Schema'.
Read the 'Summary', 'Test Objectives', and 'How to Test' sections, stopping at the 'Session Analysis' subsection. This will introduce the core concepts of session management testing and the initial steps of cookie collection.
A Systematic Approach to Token Analysis
Now that you have the theoretical foundation, let's look at a more structured, practical methodology. This involves identifying the token and then probing it for various weaknesses. The guide below breaks this down into clear, actionable steps.
AppSec Cheat Sheet: Session Management
The 'AppSec Cheat Sheet: Session Management' from TrustedSec provides an excellent, concise guide for session token analysis. We'll focus on the section about ensuring tokens are random and unpredictable.
Read the section titled 'Cryptographically Random and Unpredictable'. It details four key testing techniques: looking for cleartext patterns, detecting simple obfuscation (like Base64), performing statistical analysis with Burp Sequencer, and character modification testing. This is the core workflow for analyzing opaque tokens.
Let's highlight the key takeaways from that reading:
- Manual Review: The first step is always to look at the token. Does it contain recognizable parts, like a username, timestamp, or incrementing number? For example, a token like
1720452361-adminis weak because the first part is likely a Unix timestamp and the second is the username. - Decoding: Your background in computer science makes you familiar with encoding schemes. Is the token Base64 or hex encoded? Use Burp's built-in Decoder tool to check. A token might look random, but decoding it could reveal structured data like
is_admin=false&user_id=123. - Statistical Analysis: The human eye can't easily spot subtle patterns in long, seemingly random strings. This is where we need to automate.
Using Burp Sequencer for Statistical Analysis
Burp Suite Sequencer is a powerful tool designed specifically to test the quality of randomness in session tokens. It collects a large sample of tokens from the application and performs a series of statistical tests on them.

To see this tool in action, let's watch a brief demonstration from PortSwigger, the creators of Burp Suite.
Analyzing session token generation with Burp Suite
This video, 'Analyzing session token generation with Burp Suite', provides a quick and clear walkthrough of using Burp Sequencer to assess the randomness of a session cookie.
Watch the entire video. It's short and demonstrates the full process: capturing a session token, sending it to Sequencer, collecting a large sample of tokens, and analyzing the results.
As the video shows, Sequencer provides an "effective entropy" estimate, measured in bits. A low number indicates that the tokens are not truly random and may be predictable, making them vulnerable to brute-forcing.
2. Analyzing Structured Tokens: The Case of JWTs
Not all session identifiers are opaque strings. JSON Web Tokens (JWTs) are an increasingly popular standard. A JWT is a self-contained token that includes a header, a payload (containing claims like username and roles), and a signature. The security of a JWT relies entirely on the integrity of its signature.
Your familiarity with JavaScript and JSON will make the structure of a JWT intuitive. A typical JWT looks like this: xxxxx.yyyyy.zzzzz
xxxxx: Theheader, Base64Url encoded. Contains metadata like the signing algorithm (alg).yyyyy: Thepayload, Base64Url encoded. Contains the claims or user data.zzzzz: Thesignature. Created by signing the header and payload with a secret key.
The weakness in JWTs is often not in the randomness, but in the implementation of the signature validation.
The following video from NahamSec, a well-known bug bounty hunter, provides an excellent overview of common JWT attacks.
This Tiny JWT Mistake = Massive Bug Bounty
The video 'This Tiny JWT Mistake = Massive Bug Bounty' is a fantastic, practical guide to JWT vulnerabilities from a bug bounty perspective.
Watch from the beginning until 04:56. Pay close attention to these common JWT attacks: Algorithm Confusion (alg=none): Tricking the server into accepting a token with no signature. Weak Secret (HS256): Brute-forcing the secret key used for signing. This connects directly to our previous lesson on credential attacks. Algorithm Confusion (RS256 to HS256): A more advanced attack where you use the public key as the secret. Key Reuse: The real-world example of a dev environment key working in production is a classic bug bounty finding.
These attacks highlight a critical principle: when you see a JWT, your focus should be on attacking the signature. Can you remove it? Can you crack the secret used to create it? Can you forge your own signature?
Test your understanding!
You have captured three different session tokens from an application. For each one, what is the most likely weakness and your first step in analyzing it?
session_id=20240815093045-A4F8E2auth_token=dXNlcl9pZD0xMDEmaXNfYWRtaW49ZmFsc2U=- A JWT where the decoded header is
{"alg": "HS256", "typ": "JWT"}.
Show answer
-
Likely Weakness: Predictability. The token appears to be constructed from a timestamp (
20240815093045) followed by a short, possibly sequential or static value.
First Step: Send this to Burp Sequencer to collect many samples and analyze its randomness. You would also manually check if the first part corresponds to the exact time of the request and if the second part changes predictably. -
Likely Weakness: Information disclosure and tampering. The
=at the end is a strong indicator of Base64 encoding.
First Step: Send the token to Burp Decoder. DecodingdXNlcl9pZD0xMDEmaXNfYWRtaW49ZmFsc2U=reveals the stringuser_id=101&is_admin=false. Your next step would be to modify this tois_admin=true, re-encode it, and submit the modified token to see if you can escalate privileges. -
Likely Weakness: A weak signing secret. The
HS256algorithm uses a symmetric secret key. Developers often use weak or default secrets.
First Step: Use a tool likejwt_toolor an online JWT cracker with a common password list (likerockyou.txt) to try and brute-force the secret key. If successful, you can forge tokens with any payload you want (e.g.,{"user": "admin"}).
Conclusion
In this lesson, you learned how to dissect and analyze the session tokens that are the foundation of web application authentication. By moving beyond simply using a token to actively scrutinizing its creation, you open up a whole new class of powerful attacks.
Key Takeaways:
- Two Paths of Analysis: For opaque tokens, your primary weapon is statistical analysis with tools like Burp Sequencer to find predictability. For structured tokens like JWTs, your focus is on cryptographic attacks against the signature, such as cracking weak secrets or exploiting algorithm confusion flaws.
- Look for Patterns: Always start by manually inspecting and decoding tokens. Simple patterns like timestamps, encoded data, or incrementing numbers are common and devastating weaknesses.
- Weakness is in the Generation: The vulnerability lies not in the token itself, but in the flawed process that generated it. Understanding how a token could be created helps you figure out how to break it.
Next Lesson Preview:
Identifying a weak or predictable token is the first half of the battle. The next step is to exploit it. In our upcoming lesson, we will explore session fixation vulnerabilities. This is an attack where you force a user to authenticate using a session token that you already know, allowing you to hijack their authenticated session seamlessly.