Unseen Newt
Description
My file sharing service is end-to-end encrypted with AES-GCM. To keep things safe, every upload goes through our content scanner first: hand it your file and key, and if the contents look clean you'll get a signed receipt. Nothing gets downloaded without one.
Help
This page offers a convenient way for you to interact with the challenge functions. You can also use GET requests to send and receive data directly from the listed routes/endpoints if you wish. For more information see the FAQ.
Your aim is to recover the FLAG value. Once you have it, submit it on the CryptoHack Symmetric Ciphers page.
Source
from Crypto.Cipher import AES
import hmac
import os
SECRET = os.urandom(32)
FLAG = ?
def decrypt(key, nonce, ciphertext, tag):
if len(key) != 16 or len(nonce) != 12 or len(tag) != 16:
raise ValueError("Invalid parameters")
cipher = AES.new(key, AES.MODE_GCM, nonce=nonce)
cipher.update(b"CryptoHack")
return cipher.decrypt_and_verify(ciphertext, tag)
def sign(nonce, ciphertext, tag):
return hmac.new(SECRET, nonce + ciphertext + tag, 'sha256').digest()
@chal.route('/unseen_newt/download/<key>/<nonce>/<ciphertext>/<tag>/<receipt>/')
def download(key, nonce, ciphertext, tag, receipt):
key = bytes.fromhex(key)
nonce = bytes.fromhex(nonce)
ciphertext = bytes.fromhex(ciphertext)
tag = bytes.fromhex(tag)
receipt = bytes.fromhex(receipt)
if not hmac.compare_digest(receipt, sign(nonce, ciphertext, tag)):
return {"error": "File has not been scanned"}
try:
plaintext = decrypt(key, nonce, ciphertext, tag)
except ValueError:
return {"error": "Invalid download"}
if b'give me the flag' in plaintext:
return {"plaintext": FLAG.encode().hex()}
return {"plaintext": plaintext.hex()}
@chal.route('/unseen_newt/upload/<key>/<nonce>/<ciphertext>/<tag>/')
def upload(key, nonce, ciphertext, tag):
key = bytes.fromhex(key)
nonce = bytes.fromhex(nonce)
ciphertext = bytes.fromhex(ciphertext)
tag = bytes.fromhex(tag)
try:
plaintext = decrypt(key, nonce, ciphertext, tag)
except ValueError:
return {"error": "Invalid upload"}
if b'flag' in plaintext:
return {"error": "Upload rejected by content scanner"}
return {"receipt": sign(nonce, ciphertext, tag).hex()}
Interact
download(key,nonce,ciphertext,tag,receipt)
upload(key,nonce,ciphertext,tag)
Output
XOR tool
Use this form to XOR two hex strings together.
Output
Hex Encoder/Decoder
This is a convenient encoder designed for ASCII <-> Hex translations. It won't work for decoding hex to byte streams and will just show [unprintable] in that case.