CSAW 2020 Qualifiers - modus_operandi

This is a crypto challenge from the CSAW 2020 CTF originally worth 150 points.
The challenge initially tells us to connect as such:
|
|
We need to tell if the cipher being used to encode our plaintext is ECB or CBC. The big difference is that ECB, which stands for Electronic Code Book, always produces the same ciphertext for a given block.
The first thing to do is figure out the cipher block size. We can do this easily by entering only a letter and check out the size of the output.
|
|
We got 333b2ddd618ce8a23993af9e094d7769
as the ciphertext. Since this is hexadecimal representation, every character is 4 bits, thus making our block size 128 bits (4 * 32).
So to differentiate ECB from CBC we only need to send enough characters in the plaintext and then split our ciphertext every 32 characters (128 bits) and compare the first block of the ciphertext with the second. If these are equal then it’s ECB, otherwise it’s CBC.
I coded this into python and this is the result:
|
|
We will send 32 characters since these make up 32 bytes (256 bits), to make our 2 blocks. When we run it we get:
|
|
It gave us an EOF after a while. After trying a couple of times we would understand this behaviour is recurrent.
After fiddling a bit (a lot actually) we can get to the result by checking out the cipher modes sequence.
|
|
Our resulting binary is:
|
|
If we translate this to characters we get flag{ECB_re@lly_sUck$}
. That’s it.