baby_crypt The cookie is input + flag AES ECB encrypted with the sha256 of the flag as the key.
nc crypto.chal.csaw.io 1578
The first step that we took was to find out how many AES 16 byte blocks that the flag has. To measure this we simply sent an empty request to the service.
1 2 3
DiogoMonteiro @ ~/baby_crypt -> nc crypto.chal.csaw.io 1578 Enter your username (no whitespace): Your Cookie is: f9cc1330ae5830732a18d1a23211ffbce3725519adb9e6f10d658d87c80825ed
At this stage, and having a hex string with 64 chars, we know that the flag has 32 bytes (including any padding). Therefore, the flag represents two AES 16 byte blocks.
From the challenge description we know that the encryption is performed using AES ECB, which is vulnerable to chosen plaintext attacks. As a matter of fact, we have control over the first (any) bytes of the plaintext. With a chosen plaintext attack on AES, to find the 32 bytes of the flag, we need to brute force each one of its bytes, resulting in a search space with size 32 x 94 = 3008 chars, which is easy.
The chosen plaintext attack that we performed works as follows. The idea is to input 32 bytes where the last byte is the one that we are going to brute force.
We start by sending to the service the input = AAAAAAAAAAAAAAAX (16 chars) for each char X in the range of printable chars, and store the resulting ciphertext of the second block in a dictionary D1.
1 2 3 4 5 6 7 8 9 10
(X = byte to brute force, ! = byte of the secret, P = padding byte)
| AAAAAAAAAAAAAAAA | AAAAAAAAAAAAAAAX | !!!!!!!!!!!!!!!! | !!!!!!!!!!!!!!!! | for each X in 0x20 to 0x7E | ---------------input ---------------| --------------secret ---------------|
To find the first character of the flag, we compute the ciphertext of the second block with input = AAAAAAAAAAAAAAA (15 chars) and lookup for that ciphertext in the dictionary D1.
The next round is similar. For each byte X in the range of printable chars we send input = AAAAAAAAAAAAAAfX (16 chars, and notice the previously found “f” char) to the server and store the resulting ciphertext of the second block in a dictionary D2.