Tags: crypto
Rating:
This is an interested AES problem ! I will show map of this AES and code !
![Imgur](https://i.imgur.com/RutkrST.png)
--------------------------------------------------------------------
And this is my code !
```py
import binascii
from Crypto.Cipher import AES
from Crypto.Util.number import long_to_bytes, bytes_to_long
from pwn import *
conn = remote('103.152.242.242',10016)
def split_block(message):
block_message = [ message[i:i+16] for i in range(0,len(message), 16) ]
return block_message
def get_decrypt(enc):
enc = binascii.hexlify(enc)
conn.recvuntil('> ').decode()
conn.sendline('3'.encode())
conn.recvuntil('= ').decode()
conn.sendline(enc)
conn.recvuntil('= ').decode()
msg = binascii.unhexlify(conn.recvline().decode()[:-1])
return msg
def decrypt_flag(enc):
msg = get_decrypt(enc)
block_msg = split_block(msg)
for i in range(1, len(block_msg)):
block_msg[i] = long_to_bytes(bytes_to_long(block_msg[i]) ^ bytes_to_long(block_msg[i-1]))
enc2 = b''.join(block_msg)
cipher = AES.new(IV, AES.MODE_ECB)
flag = cipher.decrypt(enc2)
return flag
cipher = b'0'*16
plain = get_decrypt(cipher*2)
block_plain = split_block(plain)
IV = long_to_bytes(bytes_to_long(cipher) ^ bytes_to_long(block_plain[0]) ^ bytes_to_long(block_plain[1]))
conn.sendline('1\n'.encode())
conn.recvuntil('= ').decode()
enc_flag = binascii.unhexlify(conn.recvline()[:-1].decode())
flag = decrypt_flag(enc_flag)
print('Flag = ', flag)
```