Signal backup: deleted evidence
A forensic team took case.zip (the relevant parts of the image) from a suspect's Android device: case_notes.txt (a case note), device/vault_export.json (a password manager export) and device/Signal/*.backup (a Signal backup). The goal — to find the evidence flag in the archive that was sent to the number given in the note and then attached to a message that was "deleted for everyone". You do not need to break the cryptography: everything is solved by implementing the format described below correctly and linking the evidence.
Password manager: JSON, PBKDF2-HMAC-SHA256(PIN, salt, iter, 48); the first 16 bytes — the AES-128-CBC (PKCS#7) key, the remaining 32 bytes — the HMAC-SHA256 key; mac = HMAC(iv || shifrmatn). The PIN — 4 digits. The list inside contains several Signal passwords; the backup itself shows which one matches it.
Signal backup (a simplified version based on the Signal Android format). The password — 30 digits (without spaces). The file: consecutive frames. Frame 1 is in the clear: [4 bayt BE uzunlik][BackupFrame], containing Header{iv=1, salt=2}. Key: h = parol; birinchi iteratsiyada SHA512(salt || h || parol), keyingilari SHA512(h || parol), 250000 times in total (h — the previous 64-byte result); backupKey = h[:32]. Then HKDF-SHA256 (salt = 32 zero bytes, info = "Backup Export", 64 bytes): the first 32 bytes — cipherKey, the second 32 bytes — macKey.
Each following frame: [4 bayt BE uzunlik L][shifrmatn (L-10 bayt)][MAC (10 bayt)], MAC = HMAC-SHA256(macKey, shifrmatn)[:10], cipher — AES-256-CTR, IV = [4 bayt BE hisoblagich] || header.iv[4:]; the counter starts at header.iv[:4] (BE) and increases by 1 for each encrypted unit (a frame or attachment data). For an attachment frame, right after Attachment{rowId=1, attachmentId=2, length=3} come length bytes of ciphertext + a 10-byte MAC (without a length prefix), the IV — is the next counter, MAC = HMAC-SHA256(macKey, iv || shifrmatn)[:10].
BackupFrame fields: header=1, statement=2 (SqlStatement{statement=1 (string), parameters=2 (takror)}; SqlParameter{stringParamter=1, integerParameter=2 (varint), nullparameter=5}), preference=3, attachment=4, version=5, end=6. Execute the SQL frames in sequence (CREATE, INSERT, UPDATE) in SQLite: message.remote_deleted, part.unique_id ↔ attachmentId.
Flag format: BAYROQ{SIGNAL_ZAXIRA_xxxxxxxxxxxxxxxx} (the last 16 characters are lowercase hex). Many messages and archives contain decoy flag-like strings.