ECB Byte At A Time

This blog post is about AES ECB Byte At A Time attack. If you don’t have any prior knowledge regarding AES ECB please do refer to it, so that the attack will be understood clearly.

Some Important Points Regarding AES

  • AES is a block cipher, each block of size 16bytes long
  • If the length of message is not a multiple of 16, padding bytes are added to make it a multiple of 16. When it is multiple of 16 an extra 16bytes of padding are added.

Note: In ECB, encryption of first block is independent of the next block.

Generally, AES ECB ciphertext is of the format

ciphertext = AES(input, key)

We can use this attack when an unknown secret is appended to the input and therefore, we can determine the secret by manipulating our input.

Now our ciphertext is of the format

ciphertext = AES(input+secret, key)

Screenshot from 2018-08-10 14-59-58

Attack!!

How do we get to know the secret without knowing the key??

As already mentioned we got to manipulate our input. So, take the input as 15 * ‘a’ s. Now, send the input to the server and it returns the corresponding ciphertext.  So, first block of our ciphertext is the encryption of 15bytes of input + 1byte of the secret and the next block contains encryption of rest of the secret and its padding. Now we again take our input append characters from ASCII  value (0,255) one by one and send it to the server. We compare the first block of ciphertext obtained with the initial ciphertext block one. At a particular character, it matches with our ciphertext and that gives our first byte of secret 😀 .

Screenshot from 2018-08-10 14-59-45

Now we reduce our input to 14 * ‘a’ s. Add the obtained first byte of our secret to it and repeat the same again.

We do the same until we get our entire secret.

So, from this attack it is clear that we can find the appended secret even without the knowledge of the key using ECB byte at a time attack!

Thank You!! 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s