I would like to simulate the CBC IV attack where the IV is predictable. It's described in the answer to this question: chosen plaintext attack on CBC, predictable iv
(Only "Yes" and "No" are valid messages and the attacker knows this)
I am using 128-bit AES, CBC mode. Everything is in hex
Key: 00112233445566778899aabbccddeeff
IV1: 12121212121212121212121212121212
Msg: Yes
Ciphertext: 030a 6eac 2641 e072 bd51 0d84 fb87 08da
I have encrypted the message like this:
printf "Yes" > yes
openssl enc -aes-128-cbc -e -in yes -out yes.aes -K 00112233445566778899aabbccddeeff -iv 12121212121212121212121212121212
The next IV (IV2) is going to be:
12121212121212121212121212121213
When an attacker knows this, it can calculate
IV1 XOR IV2 XOR "Yes"
and submit it to be encrypted with the next IV. If the ciphertexts match, then the attacker knows that the first message was in fact "Yes"
In my example the XOR calculation results to 59 65 72 which is in ASCII:
Yer
(calculated with http://xor.pw)
Now let's encrypt this and check if the ciphertexts match:
printf "Yer" > yer
openssl enc -aes-128-cbc -e -in yer -out yer.aes -K 00112233445566778899aabbccddeeff -iv 12121212121212121212121212121213
But now I get this as the ciphertext:
4378 8d70 de54 d287 8f64 1c8d ec40 de91
I was expecting it to be the same ciphertext as the one for the original "Yes"
I can't find my error. The attack should be correct, so I guess I am using OpenSSL incorrectly?
12121312121212121212121212121212
instead. – Maarten Bodewes Nov 03 '18 at 18:565965 730d 0d0d 0d0d 0d0d 0d0d 0d0d 0d0c
("Yes", followed by 13 in hex, last bit changed) I still don't get the original ciphertext. – daniel7558 Nov 03 '18 at 19:225965 73 = Yes
Oh, when I submit the 128 bit long message, the ciphertext has an extra block. That should be because it needs to add a complete block of padding if the ciphertext already is a multiple of the blocksize. But when this is always added, how would I do the attack when the IV is just incremented? In order to change the last bit of the plaintext I need to make my plaintext to be the same size as the block size which would result in an extra block being added for padding. – daniel7558 Nov 03 '18 at 19:40-nopad
soenc
doesn't do another, extra padding. – dave_thompson_085 Nov 04 '18 at 02:52