Score:2

Padding Oracle Attack Example

ax flag

I try to understand a oracle Padding Oracle Attack example. I try to solve this question but I didn't figure out the answer.

A 7-byte message is padded per PKCS#5 and encrypted using the CBC mode of operation. The resulting ciphertext is
0x07 06 05 04 03 02 01 01, 0x08 09 0A 0B 0C 0D 0E 0F

Assume an Attacker modified that to
0x07 06 05 04 03 02 00 02, 0x08 09 0A 0B 0C 0D 0E 0F
and observed that the ciphertext was decrypted without any problems.

What is byte 7 of the original message?


What I did so far is separate the blocks as
Block 1: 0x07 06 05 04 03 02 00 02
Block 2: 0x08 09 0A 0B 0C 0D 0E 0F

The modified block is changed at the 7th and 8th byte so the key length should be 7. The Xor operation could be 0x02 xor 0x07 xor cipher text.

fgrieu avatar
ng flag
The tentative resolution of this homework is lacking. We can't tell "the key length", it could be e.g. 24 bytes if the block cipher is 3DES. Block size is 8 bytes: the question hints at that, and it's in the formal definition of PKCS#5 padding ([RFC 8018 6.1.1 §4](https://www.rfc-editor.org/rfc/rfc8018.html#section-6.1.1)). If you think "xor 0x07" has to do with that padding, check Wikipedia's [entry on PKCS#5 padding](https://en.wikipedia.org/wiki/Padding_(cryptography)#PKCS#5_and_PKCS#7). The [entry on CBC](https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation#CBC) might also help.
fgrieu avatar
ng flag
Further hints: Since message is 7 bytes and padded per PKCS#5, what is the size of the padded message, and what are the byte(s) added by padding? What can be deduced about the nature of the first and second 8-byte blocks of the question's "ciphertext"? (note: CBC mode requires an IV and it must be transmitted somehow). How do these 2 blocks relate to the padded plaintext? What is the last byte of the deciphered (still padded) message obtained by deciphering per CBC the attacker's modified message? Assuming a maximally stringent PKCS#5 padding check, what must the previous byte be? Conclude.
MariaDb avatar
ax flag
I think the solution is hidden in the $F^{-1}(c)\oplus\mathsf{IV}$ formula. If the solution was reached when the password was tried by changing the data in the last 2 bytes, the fact that the result is similar when we xor these 2 values to each other gives us how many empty values the data is filled with. I think it can be solved successfully when we xor the given value with 05 and 06 consecutively. Based on this, I made the assumption that the data was filled with 02 02 02 02 in the parts after 6 bytes.
MariaDb avatar
ax flag
Given ciphertext: 0x07 06 06 05 04 04 03 02 02 01 01, 0x08 09 0A 0B 0C 0D 0E 0F Modified ciphertext: 0x07 06 06 05 04 03 02 00 02, 0x08 09 0A 0B 0C 0D 0E 0F We decrypt ciphertext using CBC mode and PKCS#5 padding, replacing the last two bytes (00 02) of the modified ciphertext to find a faulty padding in the last block: Our initial assumption: The last byte is a real padding byte, we add a padding byte with the same value as the last byte Ciphertext : 0x07 06 05 04 03 02 00 02, 0x08 09 0A 0B 0C 0D 0E 0F Deciphered text assume: 0x07 06 06 05 04 04 03 02 02 01 01, 0x08 09 0A 0B 0C 0D 0E 0F
MariaDb avatar
ax flag
Since it did not give a padding error on the first try, the last byte is a real padding byte. Using the actual padding byte we found (p =0x01), last block: Last block: 0x01 Previous block encrypted: 0x02 00 02 02 02 02 02 02 02 02 Previous block solved: 0x02 02 02 02 02 02 02 02 02 02 01 Last byte (m[-1]⊕p): 0x01 We decrypt the modified ciphertext using CBC mode and PKCS#5 padding: Ciphertext: 0x07 06 05 04 03 02 00 02, 0x08 09 0A 0B 0C 0D 0E 0F Deciphered text: 0x05 04 03 03 02 01 00 00 00 00, 0x02 02 02 02 02 02 02 02 02 01 (m[-1] XOR C[-2][-1]): 0x 7th byte: (0x00⊕0x02) = 0x02
MariaDb avatar
ax flag
I am not sure of the answer and steps of course
fgrieu avatar
ng flag
I can't follow the reasoning, and in particular the statement that 00 02 is the last two bytes of the modified ciphertext, when these seem to be 0E 0F. In any case, 0x02 is not the correct result. That's too long a discussion for comments, but you can [continue in chat](https://chat.stackexchange.com/rooms/145933/discussion-on-question-by-mariadb-padding-oracle-attack-example).
kelalaka avatar
in flag
[Bit Flipping Attack on CBC Mode](https://crypto.stackexchange.com/q/66085/18298)
Score:1
ng flag

Here is a guide to this is homework:

  1. We are told that "a 7-byte message is padded per PKCS#5". What does that perform? Name the outcome "padded message" and note that $P$. What is the length of $P$? What byte(s) have been added to the plaintext to form $P$ according to PKCS#5 padding? Therefore, what's the last byte of $P$?
  2. We see that the question gives the "ciphertext" as two blocks of 8 bytes. We need to make sense of that, for it does not match the length in step 1. Since this is CBC, we understand that the first block is actually the Initialisation Vector (IV), and the second block is the one block of actual ciphertext. Note $\mathsf{IV}$ for the first block, and $C$ for the second block (the first and only block of ciphertext that carries information about the message).
  3. Given how CBC works, what is the equation linking $\mathsf{IV}$, $P$, $C$, and the function $F$ performing block encryption (under whatever key is used, that we can't know; $F$ could for example be 3DES).
  4. When the attacker modifies the "ciphertext", what does it actually change ? Express that change as XOR with an 8-byte constant $Δ$, and determine $Δ$ explicitly.
  5. Name $P'$ the padded message after CBC decryption. Using the equation of step 3, what's the equation linking $P$, $P'$, $Δ$ ?
  6. What's thus the last byte of $P'$ ?
  7. We are told that "the ciphertext was decrypted without any problems", which includes padding checks. What can we thus deduce about other bytes of $P'$ ?
  8. Reusing the relation of step 5, what can we deduce about $P$? Conclude.

Clarifying the question's notation (already in the revised original): 0x is to indicate hexadecimal notation in the 8 bytes that follow (8 blocks of 2 hexadecimal characters separated by one space). The , is to visually separate 8 block bytes among the flow of bytes physically sent to the legitimate receiver.

Summary of PKCS#5 padding: it's objective is to prepare the plaintext, consisting of some arbitrary number of bytes (here, 7 bytes), for CBC encryption using a block cipher with 8-byte blocks. That requires transforming the plaintext into a padded plaintext of size a multiple of 8 bytes. This is performed by appending from 1 to 8 byte(s) to the message, such that the number of bytes added satisfies the requirement that the padded message has size a multiple of 8 bytes. The value of each byte added is the number of bytes added.
On decryption, PKCS#5 prescribes to check the padding: the last byte must be for 01 to 08, which tells the total number of padding bytes, and (when that's 2 to 8) the other padding bytes are (per PKCS#5 6.1.2 §5) checked to be equal to the last padding byte. These 1 to 8 padding byte(s) are removed in order to recover the plaintext with it's original length.

fgrieu avatar
ng flag
Please follow-up [there](https://chat.stackexchange.com/rooms/145933/discussion-on-question-by-mariadb-padding-oracle-attack-example).
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.