10. ECB Cut-and-Paste Attack Notes
Because AES-ECB encrypts each block independently, identical plaintext blocks map to identical ciphertext blocks. This property can be used to create a privilege-escalation token in a CTF.
Core idea
- Control the input so the
role=userblock androle=adminblock align exactly on block boundaries - Cut and paste ciphertext blocks to construct a new token containing the
adminblock
Quick procedure
- Detect the block size (usually 16 bytes)
- Align the padding so
adminappears at the start of a block - Extract the
adminblock and replace the role block in a valid token
Defense points
- Do not use ECB → CBC/GCM recommended
- Verify integrity with authenticated encryption (AEAD)
- Use signed tokens (JWT) plus server-side authorization checks
ECB becomes an attack surface the moment it is chosen "for convenience." If the block boundaries are visible, the game is already over.