Level 7: AES in ECB mode
Task
The Base64-encoded content in this file has been encrypted via AES-128 in ECB mode under the key
"YELLOW SUBMARINE".
(case-sensitive, without the quotes; exactly 16 characters; I like "YELLOW SUBMARINE" because it's exactly 16 bytes long, and now you do too).
Decrypt it. You know the key, after all.
Easiest way: use OpenSSL::Cipher and give it AES-128-ECB as the cipher.
Do this with code.
You can obviously decrypt this using the OpenSSL command-line tool, but we're having you get ECB working in code for a reason. You'll need it a lot later on, and not just for attacking ECB.
Explanation
What is AES?
AES (Advanced Encryption Standard) is a symmetric cipher algorithm that operates on 16-byte blocks. It is widely used for secure data encryption. AES supports several operation modes, including ECB, CBC, and GCM, among others.
What is ECB?
ECB (Electronic Codebook) is one of the operation modes of AES-128. It determines how AES processes multiple data blocks. In ECB mode, the message is split into 16-byte blocks, and each block is encrypted or decrypted independently using the same key.
However, ECB does not use an Initialization Vector (IV), a random value that provides additional security. As a result, ECB is vulnerable to certain attacks, especially when encrypting repetitive or structured data.
In this exercise, we need to use AES-128-ECB because the cipher key is already provided.
Resolution
First, we are going to create a file named task7.py
Understanding the code
AES and base64 libraries are imported to handle AES decryption and Base64 decoding.
The script opens the 7.txt file with
open()
in read mode, assigning its content to theencrypted_base64
variable.You can download the file using a terminal command:
encrypted_base64
is then Base64 decoded and stored in theencrypted_bytes
variable.The
key
variable is initialized with the string YELLOW SUBMARINE, which is the decryption key provided in the challenge.cipher
is created as a new AES object, where thekey
andAES.MODE_ECB
are passed as parameters.decrypted_bytes
is initialized by decryptingencrypted_bytes
using thecipher.decrypt()
method.decrypted_text
is initialized withdecrypted_bytes
decoded to "UTF-8", converting the bytes to a readable string.Finally,
decrypted_text
is printed, revealing the plaintext message.
Result
The result is the same that task 6.
Last updated