Hidden Cipher 2
- Technique
- Static RE of a reversible transform
- The transform
- encoded = flag_byte × answer
- Tools
- file, strings, objdump, Python
- Binary
- ELF64 PIE, not stripped
Vulnerability Analysis
Root Cause: The "encoding" is a single known multiplication, not an actual cryptographic transform — anyone who knows the multiplier (the math prompt's own answer) can invert it with one division per byte.
- CWE-327: Use of a Broken or Risky Cryptographic Algorithm — A trivially-invertible multiply stands in for encryption and offers no real confidentiality
Severity: No CVSS score applies — this is a lab-built obfuscation, not a scored vulnerability in a shipped product.
References:
CWE-327
Summary
The binary asks a simple math question (What is A op B?). Answer correctly and it prints the flag — but encoded: each flag byte is multiplied by your answer. Because multiplication is reversible, dividing each encoded value by the answer recovers the original byte.
The “cipher” is just encoded = flag_byte × answer. Knowing the answer, flag_byte = encoded ÷ answer — a clean, exact inverse.
Recon & static analysis
Standard triage, then read the disassembly — the binary isn't stripped, so function names survive:
file hiddencipher2 # ELF 64-bit PIE, not stripped
strings hiddencipher2 | head # "Encoded flag values:", "%d %c %d?", ...
objdump -d hiddencipher2 | grep -A200 '<main>'
objdump -d hiddencipher2 | grep -A100 '<encode_flag>'
In encode_flag the transform is plain: for each character it prints flag_byte * answer, comma-separated. So the decode is one division per value.
Automated solve
The solver parses the question, computes the answer, sends it, reads the encoded list, and divides it back:
m = re.search(r'What is (\d+) ([+\-*]) (\d+)\?', prompt)
a, op, b = int(m[1]), m[2], int(m[3])
answer = a+b if op=='+' else abs(a-b) if op=='-' else a*b
sock.sendall(f"{answer}\n".encode())
encoded = [int(x) for x in re.search(r'Encoded flag values:\s*\n([\d,\s]+)', out)[1].split(',') if x.strip().isdigit()]
flag = bytes(v // answer for v in encoded).decode()
print(flag)
Remote runner
python3 solve_remote.py shape-of-you.picoctf.net 49821
Takeaways
- Start with
file+strings. The strings named the exact behaviour before any disassembly. - Unstripped symbols made locating
encode_flagtrivial. - A reversible transform is not encryption. Multiply-by-known inverts cleanly with division.
References & Standards
- Common Weakness Enumeration
- CWE-327: Use of a Broken or Risky Cryptographic Algorithm
- Security Guidance
- OWASP Cryptographic Storage Cheat Sheet