$ cat writeup.md…
$ cat writeup.md…
hackthebox
"Secure coding is the keystone of the application security!"
The challenge provides a zip file (password: hackthebox) containing an iOS .app bundle. The goal is to reverse-engineer the app to find and decrypt a hidden flag.
After unzipping the archive, we find an iOS app bundle hackthebox.app/ with key files:
| File | Description |
|---|---|
hackthebox | Mach-O 64-bit executable x86_64 (iPhone Simulator build) |
challenge.plist | Binary plist containing encrypted data |
Info.plist | App metadata (bundle ID: ben.hackthebox) |
htb-company.png | Company logo image |
Parsing the binary plist reveals:
{ "flag": "Tq+CWzQS0wYzs2rJ+GNrPLP6qekDbwze6fIeRRwBK2WXHOhba7WR2OGNUFKoAvyW7njTCMlQzlwIRdJvaP2iYQ==", "id": "123", "title": "HackTheBoxIsCool" }
The flag field is a base64-encoded AES ciphertext.
Running strings on the Mach-O binary reveals critical information:
SecretManager:key:iv:data: -- indicates AES encryption with key and IV!A%D*G-KaPdSgVkY (the AES key)QfTjWnZq4t7w!z%C (the IV -- but ultimately ignored)initWithBase64EncodedString:options: confirming base64 decoding of the flagpathForResource:ofType: with strings challenge and plist confirming it reads challenge.plistDisassembling the SecretManager method and viewDidLoad reveals the CCCrypt call:
CCCrypt(
op = 1, // kCCDecrypt
alg = 0, // kCCAlgorithmAES128
options = 3, // kCCOptionPKCS7Padding (1) | kCCOptionECBMode (2)
key = "!A%D*G-KaPdSgVkY",
keyLen = 16, // AES-128
iv = "QfTjWnZq4t7w!z%C", // IGNORED in ECB mode
...
)
Critical insight: The options field is 0x3 = kCCOptionPKCS7Padding | kCCOptionECBMode. Despite the method accepting an IV parameter, ECB mode does not use an IV -- it is completely ignored. This is one of the "horrific" crypto practices the challenge highlights.
#!/usr/bin/env python3 """ HackTheBox CTF - Cryptohorrific AES-128-ECB decryption with hardcoded key extracted from Mach-O binary """ from Crypto.Cipher import AES import base64 # Base64 ciphertext from challenge.plist ciphertext_b64 = "Tq+CWzQS0wYzs2rJ+GNrPLP6qekDbwze6fIeRRwBK2WXHOhba7WR2OGNUFKoAvyW7njTCMlQzlwIRdJvaP2iYQ==" ciphertext = base64.b64decode(ciphertext_b64) # Hardcoded AES-128 key from binary strings key = b"!A%D*G-KaPdSgVkY" # ECB mode -- no IV needed (options = 3 includes kCCOptionECBMode) cipher = AES.new(key, AES.MODE_ECB) plaintext = cipher.decrypt(ciphertext) # Remove PKCS7 padding pad_len = plaintext[-1] flag = plaintext[:-pad_len].decode("utf-8") print(flag) # HTB{REDACTED}
The challenge name "Cryptohorrific" and description "Secure coding is the keystone" highlight multiple terrible security practices:
strings$ cat /etc/motd
Liked this one?
Pro unlocks every complete writeup and expanded API access. $9/mo.
$ cat pricing.md$ grep --similar