1 ECB's Fatal Flaw: Pattern Leakage
Electronic Codebook (ECB) mode encrypts each block of plaintext independently with the same key. This means identical plaintext blocks always produce identical ciphertext blocks — leaking structure even without decrypting.
ECB encryption (vulnerable):
from Crypto.Cipher import AES
cipher = AES.new(key, AES.MODE_ECB) # NEVER use ECB!
ciphertext = cipher.encrypt(pad(data, 16))The classic demonstration is encrypting a bitmap image with ECB — the encrypted image still reveals the outlines of the original, because identical pixel blocks produce identical ciphertext blocks.
Practical attack scenario:
Consider an API that encrypts user role tokens in ECB mode. If an attacker discovers that a block at position N corresponds to "role=admin", they can copy that block from an admin token they observe into their own token at the same position.
ECB also enables cut-and-paste attacks: rearranging ciphertext blocks to rearrange plaintext blocks without knowing the key.