Challenges › Cryptography

Recover Plaintext with a Padding Oracle

medium · 100 XP · machine with a lab · free · solves: 0

A test service decrypts AES-CBC messages with a fixed secret key. It tells you only one thing: whether the PKCS#7 padding of the result is valid. You captured one message: a 16-byte IV and a one-block ciphertext. They are in target.txt. The block size is 16 bytes.

Start the lab. The service runs on host oracle, TCP port 9000.

Protocol. The service sends four banner lines when you connect: a help line, the target IV, the target ciphertext and the query count. Send one command per line:

client.py opens one connection and gives you Oracle.check(iv, ciphertext) for your scripts. It returns True for valid padding.

Your task.

  1. Keep the target ciphertext block. Change only the IV that you submit.
  2. Recover the intermediate state D(C) of the block, from the last byte to the first.
  3. For the last byte, confirm each passing candidate: change the byte before it and check that the padding stays valid.
  4. XOR the intermediate state with the original IV, then remove the PKCS#7 padding.
  5. Run python3 verify.py <plaintext> to check your answer.

The flag is CSEMA{<plaintext>}, with the plaintext after padding removal.

Tags: learn

Try next