CBC padding oracle
This is one of the most famous attacks in cryptography. The server decrypts the ciphertext and returns a different error if the PKCS#7 padding is incorrect. This single bit of information ("is the padding correct?") is enough to recover the entire message.
Note — for PKCS#7 padding to be correct, the last byte must be v (1..16) and the last v bytes must be exactly equal to v.
We have a single-block ciphertext: C1, and its IV. Decryption: P = D(K, C1) XOR IV. Here we call I = D(K, C1) the intermediate value — it does not depend on the IV at all!
IV = 83eb6a67d0b7b499635a3223f0f2cefc
C1 = 9dcb38a36ee45bd1f9f6a8272430685c
The attack works in the following order (starting from the last byte):
j = 15,P = 16 - j = 1. We constructIV'like this: all bytes beforejare0x00,IV'[j] = g, the bytes after it areIV'[k] = I[k] XOR P(if they are not found yet, there are no subsequent bytes at this step).- We test
gfrom 0 to 255. For the singlegwhere the oracle says "padding is correct", the last byte was equal toP, thereforeI[j] = g XOR P. - We decrease
jby one,P = 16 - jincreases and the above step is repeated (now the subsequent bytes are padded using the already knownI[k]). - Once all 16 bytes are found:
P = I XOR IV(with the real IV).
There is no live server — the responses to all 4096 requests are pre-fetched and written to the oracle_javoblari.json file. The key is the SHA-256 hex hash of the 16 bytes of IV', the value is true (padding is correct) or false.
The recovered plaintext will have PKCS#7 padding at the end — remove it and put the remaining text into the flag:
BAYROQ{A3S_<ochiq matn>}
The table contains only the exact requests described above (with 0x00 in place of unfound bytes). If you construct a different IV', you will not find it in the table.