1 How Padding Oracle Attacks Work
AES-CBC encryption requires plaintext to be padded to block boundaries (PKCS#7). When the server decrypts ciphertext and reveals padding errors differently from other errors, an attacker can exploit this "oracle" to decrypt any ciphertext without knowing the key.
The attack mechanism:
- Attacker modifies ciphertext bytes and submits to server
- Server decrypts and checks padding — returns "padding error" or "wrong data"
- Different error = information about decrypted bytes
- By systematically modifying ciphertext and observing errors, attacker recovers plaintext byte by byte
Real-world examples:
- POODLE (2014): Exploited SSLv3 CBC padding
- Lucky Thirteen: Timing-based padding oracle against TLS
- ASP.NET viewstate padding oracle (MS10-070)
Vulnerable pattern:
try:
plaintext = aes_cbc_decrypt(ciphertext, key, iv)
except PaddingError:
return "Invalid padding" # Oracle!
except Exception:
return "Invalid data" # Different message = different error = oracle!