๐ What Is It?
Cryptographic Failures (formerly "Sensitive Data Exposure") occur when applications fail to adequately protect sensitive data through proper encryption, hashing, and key management. This class covers weak or missing cryptography โ in transit and at rest โ that leads directly to the exposure of passwords, personal data, and secrets.
A04
OWASP Rank
46
Mapped CWEs
Data
Exposure Impact
โ ๏ธ Common Attack Vectors
- Hash cracking via rainbow tables (unsalted MD5/SHA-1)
- GPU brute force against fast hashes
- Man-in-the-middle on unencrypted HTTP
- Weak TLS / downgrade (BEAST, CRIME, POODLE)
- Hard-coded keys in source, config, or Git
- Predictable tokens / insufficient entropy
๐ด Attack Flow
1. Attacker obtains DB of password hashes
โ
2. Identifies algorithm (MD5 = 32 hex chars)
โ
3. Looks up hash in a rainbow table
โ
4. Unsalted โ direct match, recovers plaintext
โ
5. BREACH: account takeover & cred stuffing!
โ
2. Identifies algorithm (MD5 = 32 hex chars)
โ
3. Looks up hash in a rainbow table
โ
4. Unsalted โ direct match, recovers plaintext
โ
5. BREACH: account takeover & cred stuffing!
โ Vulnerable Code
import hashlib
def store_password(username, password):
# Problem: MD5 is too fast, no salt
password_hash = hashlib.md5(password.encode()).hexdigest()
database.save(username, password_hash)
# Cracked in seconds with modern GPUs!
โ Secure Code
import bcrypt
def store_password(username, password):
# bcrypt is slow (good) and includes a salt
salt = bcrypt.gensalt(rounds=12)
password_hash = bcrypt.hashpw(password.encode(), salt)
database.save(username, password_hash)
def verify_password(username, password):
stored_hash = database.get_password_hash(username)
return bcrypt.checkpw(password.encode(), stored_hash)
โ Prevention Checklist
- Hash passwords with bcrypt, Argon2, or scrypt
- Never use MD5 or SHA-1 for passwords
- Include a unique salt per user
- Encrypt with AES-256-GCM or ChaCha20-Poly1305; no ECB
- Generate random values with the secrets module
- Load keys from env vars / a vault; never hard-code
- Enforce HTTPS/TLS 1.2+; disable weak ciphers; add HSTS
- Encrypt sensitive data at rest and in transit
- Never store passwords in plaintext (hash, don't encrypt)
- Rotate keys; use different keys per environment
๐ Real-World & Pitfalls
LinkedIn (2012): passwords were stored as unsalted SHA-1 โ 6.5M hashes leaked and were cracked quickly, because a fast, saltless hash is barely protection at all.
Common pitfall: Encrypting passwords instead of hashing them. Passwords must be hashed (bcrypt/Argon2), never encrypted โ an encrypted password can be decrypted; a hash cannot.
Common pitfall: Encrypting passwords instead of hashing them. Passwords must be hashed (bcrypt/Argon2), never encrypted โ an encrypted password can be decrypted; a hash cannot.
๐ Tools & Takeaway
testssl.sh
nmap ssl-enum
sslyze
SSL Labs
bandit
semgrep
Key Takeaway: Use established, peer-reviewed crypto libraries โ hash passwords with bcrypt/Argon2, encrypt sensitive data at rest and in transit, and never roll your own cryptography or hard-code keys.