The Penguin AES ECB problem demonstrates the vulnerability of the Electronic Codebook (ECB) mode of AES encryption when applied to images that have large regions of similar colors. ECB mode encrypts each block of data independently, which means identical plaintext blocks are encrypted into identical ciphertext blocks. This characteristic can reveal patterns in the encrypted data, making it impractical for encrypting images or other data with repeating patterns.
This example is a demonstration of why ECB is vulnerable to simple attacks, and how ECB can reveal plaintext patterns in ciphertext. In this example, we use AES with ECB to encrypt a bitmap image that has large regions of uniform color. Although each pixel's color is meant to be encrypted, the overall image can still be recognized, as the arrangement of identically colored pixels in the original remains visible in the encrypted output.
-
Go To CyberChef at https://gchq.github.io/CyberChef/.
-
Load the Image:
- Download the sample pengin (tux) image using this link or find it in the comment below.
- Drag and drop
TUX.png
into CyberChef to load the image.
-
Convert Image to Hex:
- Add the "To Hex" operation to convert the image to a hexadecimal string. Leave the default parameters (delimiter "Space" and Bytes per line "0").
-
Encrypt the Image:
- Add the "AES Encrypt" operation.
- Set the mode to "ECB". We do not need IV in ECB.
- Choose the key type as "UTF8" and a key (e.g.,
1234567890abcdef
). - Set the input type to "Hex" and the output type to "Hex".
-
Convert Encrypted Hex to Base64:
- Add the "To Base64" operation to convert the encrypted hex string to a Base64 string.
-
Convert Base64 to Hex:
- Add the "From Base64" operation to convert the Base64 string back to a hex string.
-
Decrypt the Image:
- Add the "AES Decrypt" operation.
- Set the mode to "ECB".
- Use the same key as in the encryption step.
- Set the input type to "Hex" and the output type to "Hex".
-
Convert Decrypted Hex to Image:
- Add the "From Hex" operation to convert the decrypted hex string back to bytes.
-
Download the image bytes as a file: In the output pane, click on Save output to file and open the file to view the decrypted image.