I made this cool service that lets you protect your secrets with state-of-the-art encryption. It’s so secure that we don’t even tell you the key we used to encrypt your message!
nc challs.bcactf.com 31594
Here’s the Python source file:
1 | from Crypto.Cipher import ChaCha20 |
Essentially, this is just an encryption oracle, in which we are allowed to encrypt a message once with standard ChaCha20 and then decrypt the server’s previous encrypted message.
Basically, the key idea is that ChaCha20 is a stream cipher. What that means is that it will generate a byte string and perform a XOR encryption with the provided ciphertext. The byte string is deterministically produced from the key and nonce.
Notice how the key and nonce are the same for both the secret string encryption and the user’s own encryption? Because of this, the byte string produced by ChaCha20 for both encryptions is the exact same! Therefore, we can simply send in several null bytes to be encrypted to get the byte string, and then XOR that with the server’s encrypted secret message to get the plaintext!
1 | from pwn import * |
bcactf{b3_C4rEFu1_wItH_crypT0Gr4phy_7d12be3b}