Skip to main content

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=user block and role=admin block align exactly on block boundaries
  • Cut and paste ciphertext blocks to construct a new token containing the admin block

Quick procedure

  1. Detect the block size (usually 16 bytes)
  2. Align the padding so admin appears at the start of a block
  3. Extract the admin block 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.