BUPCTF{SUN_W1ll_RiSE_Wh3n_y0U_woke_UP}BUPCTF{Something_h3r3}riddle.txt - Contains a riddle to solve for the passphraseencrypt.py - Shows the key derivation methodciphertext.bin - Encrypted flag using AES-256-GCMYou are given a tiny "noob" encryptor, a ciphertext and a riddle. Solve the riddle to get the passphrase, hash it with SHA-256 to form the AES-256-GCM key, then decrypt the ciphertext to recover the flag.
Note: Password will be 7 characters.
The riddle in riddle.txt reads:
I paint the eastern clouds in gold and red,
I wake the fields where sleeping rivers spread.
Poets greet me with a song so fine,
Name me in one word to open time.
What one word am I?
Analysis: This riddle describes something that:
Answer: sunrise (7 characters ✓)
From encrypt.py, we can see the key derivation method:
from hashlib import sha256
def m(p): return sha256(p.encode()).digest()
This shows that the passphrase is hashed using SHA-256 to create the encryption key.
The ciphertext.bin file is 66 bytes long. For AES-256-GCM, we need:
The challenge was determining the correct arrangement of these components.
After trying various standard GCM formats (nonce + ciphertext + tag), the correct format was found to be:
from Crypto.Cipher import AES
from hashlib import sha256
def decrypt_flag():
# The passphrase from the riddle
passphrase = "sunrise"
# Hash the passphrase with SHA-256 to get the key
key = sha256(passphrase.encode()).digest()
# Read the ciphertext file
with open("ciphertext.bin", "rb") as f:
data = f.read()
# Parse the GCM components: nonce + tag + ciphertext
nonce = data[:12] # First 12 bytes
tag = data[12:28] # Next 16 bytes
ciphertext = data[28:] # Remaining bytes
# Decrypt using AES-256-GCM
cipher = AES.new(key, AES.MODE_GCM, nonce=nonce)
plaintext = cipher.decrypt_and_verify(ciphertext, tag)
return plaintext.decode('utf-8')
# Result
flag = decrypt_flag()
print(f"Flag: {flag}")
BUPCTF{SUN_W1ll_RiSE_Wh3n_y0U_woke_UP}
Riddle Solving: The riddle clearly pointed to "sunrise" as a 7-character word describing dawn.
Standard Cryptography: The challenge used standard SHA-256 for key derivation and AES-256-GCM for encryption.
Format Discovery: The main challenge was discovering the non-standard arrangement of GCM components (nonce + tag + ciphertext instead of the typical nonce + ciphertext + tag).
Systematic Approach: When standard formats failed, systematically trying different arrangements of the nonce, tag, and ciphertext components led to success.
pycryptodome library for AES-GCM implementationhashlib for SHA-256 hashing