Skip to main content

electronic-code-book-ecb

Electronic Code Book (ECB)

ECB (Electronic Code Book) encryption can be abused to tamper with authentication cookies and gain access to another user’s account without knowing the encryption key.

If the target application encrypts authentication data using ECB and stores it directly in a cookie. Because ECB encrypts each block independently, it introduces critical weaknesses that attackers can exploit.


What Is ECB

ECB splits plaintext into fixed-size blocks and encrypts each block independently using the same key.

TODO image

Key Weaknesses of ECB

  • Identical plaintext blocks → identical ciphertext blocks
  • Encrypted blocks can be:
    • Removed
    • Reordered
    • Reused
  • No integrity or authenticity protection

Detecting the Vulnerability

  • Logging in multiple times returns the same cookie
  • Indicates:
    • No randomness
    • No session invalidation
    • Cookie is likely reusable forever

The cookie is:

  • URL-encoded
  • Base64-encoded

Example indicator:

%3D%3D   →   ==

After decoding, the output is binary, meaning the data is encrypted—not signed.


Identifying ECB in Use

Comparing Similar Users

Create two users:

  • test1 / password
  • test2 / password

Decoded cookies show:

  • Large portions of ciphertext are identical
  • Only blocks corresponding to username differ
info

This confirms block-based encryption.

Finding the Block Size

Create a user with long repetitive input:

  • Username: aaaaaaaaaaaaaaaaaaaa
  • Password: aaaaaaaaaaaaaaaaaaaa

Decoded cookie shows repeated 8-byte patterns.

So, our ECB block size = 8 bytes

By testing different username/password lengths, we infer:

[ username ][ delimiter ][ password ]
<strong># OR
</strong>[ password ][ delimiter ][ username ]

Key findings to notice using different length too:

  • Delimiter size: 1 byte
  • Password is not used when validating the cookie
  • Only the username portion matters for authentication

Exploitation Techniques

Exploitation by Removing Blocks

We can forge a cookie that decrypts to:

admin[delimiter]

Steps:

  1. Create a user:

    aaaaaaaaadmin
  2. Decode the cookie

  3. Remove the first 8 bytes (ECB block boundary)

  4. Re-encode the remaining ciphertext

  5. Replace the cookie in the browser

It allows you to login as admin.