2
$\begingroup$

IV: 69bb375aa919c72aa561dd7b7ffacf66

Ciphertext: "c28ea025d10186510855d083747d6435c808d9857075abd9bfc54b094e60eaf3"

Plaintext: "SEND ENCRYPTED DATA"

I want to be able to change the resulting Plaintext to "SEND THE DATA", which if I understand correctly would involve altering the IV in this case.

I have read about the bit flipping and how this attack works, I am just having troubles implemeting it in this scenario, please help.

below the encryption (at the server side- we were given the code), includes the padding used,

  def encrypt(plaintext):
            log.info("[%d] encrypt data command invoked" % (client_id))
            iv = Random.new().read(AES.block_size)

# add padding if (len(plaintext) % 16 != 0): plaintext += b"_" * (16 - len(plaintext) % 16) cipher = AES.new(shared_key, AES.MODE_CBC, iv) ciphertext = cipher.encrypt(plaintext) return hexlify(iv) + b"," + hexlify(ciphertext) + b"\n" def no_tranform(plaintext): log.info("[%d] send data command invoked" % (client_id)) return hexlify(plaintext) + b"\n" commands = {"SEND ENCRYPTED DATA": encrypt, "SEND THE DATA": no_tranform}

Also you can see that the only allowed commands are "SEND ENCRYPTED DATA" and "SEND THE DATA" and I would like the latter.

$\endgroup$
7
  • $\begingroup$ Some more details would be welcome. Exactly what have you tried, and what kind of "troubles" have you had? $\endgroup$ Commented Feb 10, 2019 at 2:58
  • $\begingroup$ Also, does the modified plaintext have to be exactly "SEND THE DATA"? Because it would be easier to do this if you didn't have to change the length of the plaintext. (You can probably still do it in this case anyway, but the details will depend on the padding scheme used.) $\endgroup$ Commented Feb 10, 2019 at 3:02
  • $\begingroup$ @llmari Karonen please check my new edit, thank you $\endgroup$
    – nachofest
    Commented Feb 10, 2019 at 12:29
  • $\begingroup$ This is off-topic here. programming Questions belongs to SO. $\endgroup$
    – kelalaka
    Commented Feb 10, 2019 at 12:33
  • $\begingroup$ @kelalaka: I would say that this question can be interpreted and answered in a way that is on-topic here (i.e. the answer does not necessarily need to include any code). Whether such an answer would actually help the OP is still somewhat unclear to me. $\endgroup$ Commented Feb 10, 2019 at 15:49

1 Answer 1

2
$\begingroup$

Each bit you flipped in the IV changes the same bit in the decrypted plaintext. So if you want to change the first E character of ENCRYPTED into a T of THE then you need to XOR the binary representation of E and T (probably ASCII) and XOR that with the byte in the IV. This will of course only work for the first block of 16 bytes. Fortunately "SEND THE DATA" is small enough for that (13 bytes if I count correctly).

That leaves the problem of the padding. The original block contains the padding in the second block because of the size (19 bytes). However, you just have to adjust the padding of the first block by performing the XOR as displayed above. Instead of XOR'ing the final 16 - 3 = 3 plaintext bytes with a letter you XOR them with the value 03 in hex and XOR that with the IV. Now you've also generated the required padding.

Finally, you need to leave out the second block. And that's all me wrote, happy programming.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.