9.15 BUUCTF [ACTF 2020 crpto-aes]

It is a problem to learn how to solve AES's problem.
In AES, we use key and vector iv and the mode(CBC)to encrypt the flag.
We should first search for urandom():
image
So in this popblem, key is 256 bits(32 Bytes), iv is 128 bits(16 Bytes). We know key^iv, what can we do with xor's value?
Notice that when key xor iv, only the lower 128 bits will be changed, where the higer 128 bits of key will remain.
And for the lower 128 bits, we could xor the xor to decrypt.
Some details have to be take care when coding.Especially the transfer from bytes to long.
Here we code:

from Crypto.Cipher import AES
import os
import gmpy2
from Crypto.Util.number import *

def main():
    encryped_flag = b'\x8c-\xcd\xde\xa7\xe9\x7f.b\x8aKs\xf1\xba\xc75\xc4d\x13\x07\xac\xa4&\xd6\x91\xfe\xf3\x14\x10|\xf8p'
    xor = 91144196586662942563895769614300232343026691029427747065707381728622849079757
    xor_2 = long_to_bytes(xor)
    key = xor_2[:16]*2
    iv = bytes_to_long(key[16:])^bytes_to_long(xor_2[16:])
    iv = long_to_bytes(iv)
    aes = AES.new(key,AES.MODE_CBC,iv)
    flag = aes.decrypt(encryped_flag)
    print(flag)

    pass
if __name__ == '__main__':
    main()
posted @ 2023-09-15 16:15  N0zoM1z0  阅读(26)  评论(0编辑  收藏  举报