Padding Oracle Attack Fundamentals
What you'll learn: How attackers exploit padding validation errors to decrypt encrypted data without ever obtaining the secret key.
The Core Vulnerability
A padding oracle attack exploits a subtle information leak: when a system tells you whether padding is valid or invalid after decryption. Remember from PKCS#7 padding that decrypted blocks must end with correct padding bytes. If an application reveals padding validity—even through timing differences or distinct error messages—it becomes an "oracle" that answers yes/no questions about decrypted plaintext.
How the Attack Works
Imagine you intercept CBC-encrypted ciphertext. You don't have the key, but you can send modified ciphertext to the server and observe whether it returns "padding error" or "data error" (which comes after successful padding validation).
Here's the insight: by systematically modifying the previous ciphertext block and watching for padding errors, you can deduce the plaintext one byte at a time. You're essentially asking the oracle: "If I XOR this value with the previous block, does the last byte decrypt to 0x01 (valid padding)?" By trying all 256 possibilities, you discover which value produces valid padding—revealing the original plaintext byte.
Why It's Devastating
This attack turns encryption into a decryption service. The attacker:
- Needs no cryptographic key
- Can decrypt entire messages block-by-block
- Only requires the ability to submit ciphertexts and observe padding validation results
- Can even encrypt chosen plaintext by reversing the process
The attack works against CBC mode specifically because modifying one ciphertext block predictably affects the next block's decryption through XOR operations.
Key Takeaway: Padding oracle attacks prove that even strong encryption like AES becomes vulnerable when implementations leak information about padding validity—never reveal whether decryption failed due to bad padding versus bad data.