h4XOR
Category: Crypto
75 points
Can you recover the flag.png image ?
Format : Hero{}
Author : xanhacks
Hint: The xor function is from the pwntools module.
flag.png.enc
Binary blob.
xor.py
#!/usr/bin/env python3
from os import urandom
from random import randint
from pwn import xor
input_img = open("flag.png", "rb").read()
outpout_img = open("flag.png.enc", "wb")
key = urandom(8) + bytes([randint(0, 9)])
outpout_img.write(xor(input_img, key))
Solution
from pwn import xor
f = open('flag.png.enc', 'rb').read()
key = xor(f[:9], bytes.fromhex('89504e470d0a1a0a00'))
ff = open('flag_decrypted.png', 'wb')
ff.write(xor(f, key))
ff.close()
The hex used to obtain key contains png
magic bytes. Decrypted image is below.
Flag
Hero{123_xor_321}