What a long challenge name. This one is a simple oracle attack. Let’s dive right in.
The challenge gives us one simple lines to netcat to:
1 | nc ec2-13-251-81-16.ap-southeast-1.compute.amazonaws.com 3333 |
Connecting to this server gives us the following:
1 | $ nc ec2-13-251-81-16.ap-southeast-1.compute.amazonaws.com 3333 |
Choosing option 1 gives you an oracle which will encrypt things you give it and give you the base64 encoded ciphertext:
1 | $ nc ec2-13-251-81-16.ap-southeast-1.compute.amazonaws.com 3333 |
Luckily, this connection seemingly stays open indefinitely (or at least longer than 10 minutes). Decoding some of the base64 gives us sequences of capital characters:
1 | $ python -c "import base64; print base64.b64decode('SkVEQg==')" |
By experimenting around, it seems that each character maps to 4 capital ascii letters (after base64 decode). I also found that the four capital characters corresponding to a particular input character in the plaintext will be different depending on where that character is in the input string. As in the above examples, a plaintext of 1
maps to a ciphertext of JEDB
but a plaintext of 11
maps to a ciphertext of JEDBKFAA
. Thus, we can only assume that the crypto algorithm being used is using previous portions of the plaintext to determine subsequent ciphertext output.
When I choose option 2, I’m given a “challenge message” and told to guess what the plaintext is. Each time I open a new connection, I’m given a different challenge message. Some challenge messages are longer than others, but not significantly so. It’s also important to note that every challenge message received is some length that is divisible by 4, which further backs up my previous assumption that each character of the plaintext maps to four capital letters in the ciphertext. Similar to when I chose option 1, it also seems like this connection just stays open. This makes it incredibly easy to open two connections at once – one for getting the challenge message and another for brute forcing using the oracle.
1 | $ nc ec2-13-251-81-16.ap-southeast-1.compute.amazonaws.com 3333 |
So here’s the basic idea:
- Open a remote connection to the server to get the challenge message.
- Open another remote connection to the server to use the oracle.
- Slowly brute force the oracle for each character of the plaintext of the challenge message.
And here’s my script which solves it:
dusol.py
1 | # Wellington Lee |
After running the above script, I’m given:
1 | [+] Challenge solution: 9t0cfkn6q4DrFo20R2UOjV9iDuCDWcnUin8bWyxp5lFuxTzS5BS |
Thus, the flag for the challenge was matesctf{Good fun with bad crypto}
.