ecb-cbc-wtf
- •
What it asked
- •
Decrypt a CBC-encrypted flag using only an oracle that decrypts arbitrary blocks under AES-ECB with the same key.
- •
- •
Approach
- •
Wrote out the CBC decryption formula and noticed the ECB oracle gives exactly the raw block decryption with no chaining applied — which is precisely the missing piece needed to manually reconstruct CBC decryption by hand, one block at a time.
- •
- •
Solution
- •
blocks = [ciphertext[i:i+16] for i in range(0, len(ciphertext), 16)] iv, blocks = blocks[0], blocks[1:] plaintext = xor(iv, ecb_decrypt_oracle(blocks[0])) plaintext += xor(blocks[0], ecb_decrypt_oracle(blocks[1]))
- •
- •
Concepts