Course contentsShow
← Security
Lesson 97 of 3,0523. Symmetric Cryptography Deep DiveFree lesson

CBC Padding Oracle Attacks

Explore how padding validation errors can leak plaintext byte-by-byte in CBC mode implementations.

CBC Padding Oracle Attacks

What you'll learn: How attackers can exploit padding validation errors in CBC mode to decrypt ciphertext byte-by-byte without knowing the encryption key.

The Core Vulnerability

You learned that CBC mode chains blocks together for security. Most block cipher implementations also add padding to the final block to reach the required block size. Here's the critical weakness: if an application tells you whether padding is valid or invalid when decrypting, an attacker can use that information leak to decrypt entire messages.

How the Attack Works

Imagine you intercept ciphertext encrypted with CBC mode. You don't have the key, but you can send modified ciphertext to a server that decrypts it and responds differently based on whether the padding is correct:

  • Valid padding: Server accepts and processes
  • Invalid padding: Server returns an error or behaves differently

An attacker can manipulate the second-to-last ciphertext block (which XORs with the last block's decryption in CBC) to systematically guess each byte of plaintext. By observing which modifications produce valid padding, they deduce the actual plaintext values—one byte at a time, working backwards through the block.

This is called an oracle because the server "answers questions" about padding validity without realizing it's leaking secrets.

Why It's Devastating

The attacker doesn't need the encryption key. They only need:

  1. Intercepted ciphertext
  2. An endpoint that validates padding and reveals success/failure

Each byte typically requires ~128 attempts on average, making full decryption feasible in minutes.

Key Takeaway: Never expose padding validation results to untrusted parties—silent failure or authenticated encryption modes (covered later) prevent CBC padding oracle attacks entirely.