Skip to content
All tools
Modern cryptoRuns locallyNo account

CBC padding oracle attack

Decrypt CBC ciphertext one byte at a time using only a valid/invalid padding signal - Vaudenay’s attack, explained and driven.

Open in ctfpal

A padding oracle is any observable difference between 'the padding was wrong' and 'the padding was fine but something else failed'. That one bit of information, asked repeatedly, decrypts the entire ciphertext without the key.

How one byte falls

In CBC, P[i] = D(C[i]) XOR C[i-1]. You control C[i-1] because you are submitting it. Take the target block, prepend a block of your own bytes, and vary the last byte through all 256 values. Exactly one (usually) produces valid padding - which means the decrypted last byte became \x01. That tells you D(C[i]) for that position, and XORing with the real previous block gives the real plaintext byte. Move to the second-to-last byte, forcing \x02\x02, and repeat.

  • 256 requests per byte in the worst case, 128 on average. A 16-byte block is a few thousand requests.
  • The oracle need not be an error message. A timing difference, a different HTTP status, or a different response length all work.
  • The same control lets you forge plaintext, not just read it - CBC bit flipping changes a decrypted byte by XORing the corresponding byte of the previous block.

Related tools