Practice library / Web attacks
Lab · Medium · 1.5 hoursFree account
Attacking Authentication Mechanisms
Enumerate accounts, break MFA logic, steal a reset token, and abuse OAuth state and redirect_uri flaws.
On this page 16 sections
- ·Overview
- ·Prerequisites
- ·Lab setup
- ·Build the target
- 1Enumerate accounts from the login response
- 2Call the session endpoint directly to skip MFA
- Locked: Show the MFA code has no rate limit
- Locked: Inspect the password-reset token
- Locked: Steal a reset link with a forged Host header
- Locked: Check the session JWT's algorithm
- Locked: Find a redirect_uri validation bug
- Locked: Confirm sessions survive a password change
- Locked: Detection and defence
- Locked: Check
- Locked: Clean-up
- Locked: Command reference
A login system is a chain: a password check, an MFA step, a reset flow, a session, and often an OAuth hand-off to another app. Each link fails on its own, without the password hash ever being weak — many real account takeovers start from a predictable reset token or a redirect_uri prefix bug, not from brute force. Attacking the chain, not the password, is the point of the exercises that follow.
Lab Objectives
- Enumerate valid accounts from a login endpoint's different error responses
- Bypass a client-enforced MFA step by calling the session-issuing endpoint directly
- Show that an MFA code with no rate limit is brute-forceable
- Abuse a predictable password-reset token and a Host-header-poisoned reset link
- Read a session JWT's header to judge its algorithm and signing risk
- Exploit a missing OAuth
stateparameter and a redirect_uri prefix-match bug that leaks an authorization code to an unregistered path
Overview
A login form is rarely one check. It is a chain: a password check, an MFA (multi-factor authentication) step, a password-reset flow, a session, and sometimes an OAuth (a token-based single sign-on protocol) hand-off to another app. Each link in that chain can fail on its own, without the password hash or the crypto ever being weak. This lab attacks the chain, not the password.
Prerequisites
- Finish Broken Authentication & Sessions first. It covers how a session cookie and a session store are supposed to work; this lab assumes that baseline and attacks the flows around it.
- Hydra Brute Force is useful before Step 3. The same lockout and rate-limit defences you test there apply to the MFA code you test here.
- This lab's JWT (JSON Web Token) and OAuth steps are intentionally light — enough to judge the risk, not a full break. For the deeper algorithm-confusion and secret-cracking attacks, do OAuth & JWT Attacks after this lab.
Lab setup
| Item | Purpose |
|---|---|
curl | Sends every request in this lab and reads status codes, headers and bodies |
jq | Pretty-prints JSON responses and reads the captured outbox file |
| A text editor | Reads the captured mail file and keeps a log of tokens you extract |
Build the target
KaliRange hosts no targets, no virtual machines and no lab files. You run this lab on your own machine, against two applications that you build. The names and the addresses 10.0.15.40:8090 and 10.0.15.41:8091 below are the example values of this lab. Replace them with your own addresses.
| App | Address | Role |
|---|---|---|
| NimbusID | 10.0.15.40:8090 | Identity service: /api/login, /api/mfa/verify, /api/session, /api/password/forgot, /api/password/reset, /api/password/change, /api/me, /oauth/authorize |
| Northwind Partner Portal | 10.0.15.41:8091 | A second app that signs in through NimbusID over OAuth 2.0, registered as client partner-portal with a fixed redirect_uri at /oauth/callback |
- The account
alice@corp.local, passwordStr0ngPass!23. Use your own password. - NimbusID writes every outgoing email to a local file instead of sending it. This lab reads it at
~/nimbusid-mail/outbox.json. Use your own path if yours differs. - The session cookie that
/api/sessionissues is a JWT signed withHS256(Step 6 reads its header). - No other account or data is needed.
Build such applications yourself, or run NimbusID and the Partner Portal as small services with the behaviour the steps use. Run both in containers or virtual machines on your own computer. Note the state before Step 1 so that you can go back.
Authorized-lab only. Run every command in this lab only against 10.0.15.40 and 10.0.15.41, your own applications, and nowhere else. Every technique here — enumeration, MFA bypass, token theft, redirect abuse — is for a system you own or have explicit written permission to test. Running it against a system you do not control is unauthorized access in most countries.
Step 1: Enumerate accounts from the login response
Compare the response for a real account and a guessed one
Send the same wrong password against an account you know exists and one you guess does not. A login endpoint that treats the two differently tells you which accounts are real before you touch MFA or passwords at all.
# Real account, wrong password
curl -s -o /dev/null -w "%{http_code}\n" -X POST "http://10.0.15.40:8090/api/login" \
-H "Content-Type: application/json" \
-d '{"email":"alice@corp.local","password":"wrong-password"}'
# Guessed account that does not exist
curl -s -o /dev/null -w "%{http_code}\n" -X POST "http://10.0.15.40:8090/api/login" \
-H "Content-Type: application/json" \
-d '{"email":"nobody@corp.local","password":"wrong-password"}'Example output:
401
404401 means the account exists and the password is wrong. 404 means the account does not exist. That difference turns the login endpoint into a username oracle. You can now run a list of guessed addresses against it and keep only the ones that come back 401. Do this before you spend any effort on passwords or MFA.
Step 2: Call the session endpoint directly to skip MFA
Log in, then call the final session step without the MFA code
A correct password alone must never authenticate you. Log in first to see what the server returns before MFA. Then check whether the endpoint that issues the real session can be called with only that response, no code required.
# Correct password — the server must now demand an MFA code
curl -s -c cookies.txt -X POST "http://10.0.15.40:8090/api/login" \
-H "Content-Type: application/json" \
-d '{"email":"alice@corp.local","password":"Str0ngPass!23"}'Example output:
{"mfa_required":true,"challenge_id":"a1e4f9-7b22"}# Call the session-issuing endpoint directly, using only the challenge_id
curl -s -b cookies.txt -c cookies.txt -X POST "http://10.0.15.40:8090/api/session" \
-H "Content-Type: application/json" \
-d '{"challenge_id":"a1e4f9-7b22"}'Example output:
{"status":"authenticated","user":"alice@corp.local"}The web client is built to show an MFA screen next, but the server never checked that an OTP was verified before it issued a session for this challenge_id. MFA was enforced in the browser, not on the server. Defence: the server must store a mfa_verified flag against the challenge and refuse /api/session until that flag is set by a correct /api/mfa/verify call.
Sign in to continue
10 more sections are for signed-in members. It is free: sign in with Google.