I am currently trying to solve a training challenge based on AES with CBC.
This is the infos I'm given:
KEY = "yn9RB3Lr43xJK2██".encode()
IV = "████████████████".encode()
msg = "AES with CBC is very unbreakable".encode()
Those spaces are unknown characters, and I also have the output:
c5██████████████████████████d49e78c670cb67a9e5773d696dc96b78c4e0
Does anyone have any idea on where I can start? My idea would be to bruteforce the key since only 2 characters are missing but I don't know how can I do it.
Note that the output was produces via the following python code:
aes = AES.new(KEY, AES.MODE_CBC, IV)
print binascii.hexlify(aes.encrypt(msg)).decode()
Edit:
from Crypto.Cipher import AES
import binascii
from pwn import xor
from Crypto.Util.number import bytes_to_long
alphabet = [chr(i) for i in range(31,128)]
key_base = b"yn9RB3Lr43xJK2"
iv = ""
output = b'c500000000000000000000000000d49e78c670cb67a9e5773d696dc96b78c4e0'
output_bytes = binascii.unhexlify(output)
msg = "AES with CBC is very unbreakable".encode()
for char1 in alphabet:
for char2 in alphabet:
key = key_base + char1.encode() + char2.encode()
aes = AES.new(key, AES.MODE_CBC)
decryptedMsg = aes.decrypt(output_bytes)
if decryptedMsg[16] == msg[16] and decryptedMsg[31] == msg[31] and decryptedMsg[30] == msg[30]:
print(key)
cipher_1 = xor(msg[16:], decryptedMsg[16:])
iv = xor(aes.decrypt(cipher_1), msg[:16])
#print(AES.new(key, AES.MODE_CBC, iv).encrypt(msg[:16]) == cipher_1)
# Now let's verify if we got the correct value or not..
aes = AES.new(key, AES.MODE_CBC, iv)
print(binascii.hexlify(aes.encrypt(msg)).decode()) #This value should correspond to output_bytes