Challenge example
Code source example
from Crypto.Cipher import AES
from Crypto.Util.Padding import pad, unpad
import os
KEY = os.urandom(16)
FLAG = "FLAG{FakeFLAG}"
def encrypt(plaintext):
padded = pad(plaintext + FLAG.encode(), 16)
cipher = AES.new(KEY, AES.MODE_ECB)
try:
encrypted = cipher.encrypt(padded)
except ValueError as e:
return {"error": str(e)}
return {"ciphertext": encrypted.hex()}
data = input("Data to encrypt : ")
data = bytes.fromhex(data)
cipher = encrypt(data)
print(cipher)The objective of this challenge is to retrieve the FLAG which is encrypted with the user input.
The challenge is served using socat so the user can only send data and receive the ciphertext.
Exploitation
Here an oracle is possible as the user can inject and manipulate arbitrary data into the targeted ciphertext as he want and he have the ciphertext output.
By sending 32 bytes, the user can prooved that ECB mode is used :
output :
As ECB is used, it's possible to bruteforce the FLAG :
Last updated