Description
A message has been encrypted using RSA. The public key is gone... but someone might have been careless with the private key. Can you recover it and decrypt the message? Download the flag.enc and image.jpg .
Setup
Download flag.enc and image.jpg.
Examine the image metadata -- something may be hidden there.
exiftool image.jpg
strings image.jpg
Solution
- Step 1Extract the RSA private key from the imageThe RSA private key is hidden in the EXIF metadata of image.jpg, encoded as a hex string. Use exiftool to extract all metadata fields and look for a PEM-encoded or hex-encoded key.exiftool image.jpgexiftool -b -Comment image.jpg
- Step 2Decode the private keyConvert the hex string found in the metadata back to a PEM file.python3 -c " import binascii hex_key = 'YOUR_HEX_KEY_HERE' pem = binascii.unhexlify(hex_key).decode() open('private.pem', 'w').write(pem) print('Key written to private.pem') "
- Step 3Decrypt the flagUse the recovered RSA private key to decrypt flag.enc.openssl rsautl -decrypt -inkey private.pem -in flag.enc -out flag.txtcat flag.txt
Flag
picoCTF{rs4_k3y_1n_1mg_66388eb3}
The RSA private key is hidden in the EXIF metadata (Comment field) of the image as a hex-encoded PEM string.