1. Challenge Overview
The challenge provides a Windows executable named:
The-first-binary.exe
Running it through Wine presents the following prompt:
=== SECURE STORAGE VERIFIER v3.4 ===
[*] Initialising AES-256 subsystem...
[+] Cryptographic subsystem ready.
Enter the access password:
Entering an arbitrary password results in:
[ERROR] Invalid password. Access denied.
The objective is therefore to reverse engineer the executable and recover the valid 24-byte password.
2.1 Execute the binary
wine The-first-binary.exe
Example:
=== SECURE STORAGE VERIFIER v3.4 ===
[*] Initialising AES-256 subsystem...
[+] Cryptographic subsystem ready.
Enter the access password: password
[ERROR] Invalid password. Access denied.
The banner claims that an AES-256 subsystem is initialized.
However, this does not necessarily mean AES is actually used to verify the password. This needs to be confirmed through static analysis.
3. Identify the Binary
Use file:
file The-first-binary.exe
Output:
The-first-binary.exe: PE32 executable for MS Windows 6.00 (console), Intel i386, 5 sections
Important characteristics:
| Property | Value |
|---|---|
| Format | PE |
| Architecture | x86 |
| Bits | 32-bit |
| OS | Windows |
| Endianness | Little-endian |
| Language | C |
| Entry base | 0x400000 |
| Size | 140800 bytes |
| Sections | 5 |
The binary is therefore a 32-bit x86 Windows executable.
4. Inspect PE Sections
rabin2 -S The-first-binary.exe
Relevant sections:
.text 0x00401000 0x1a000 -r-x
.rdata 0x0041b000 0x07000 -r--
.data 0x00422000 0x01000 -rw-
.fptable 0x00423000 0x01000 -rw-
.reloc 0x00424000 0x02000 -r--
The important areas are:
-
.text— executable code -
.rdata— read-only constants and strings -
.data— writable global/static data
The password-verification code is located in .text, while the constants used by it are stored in .rdata.
5. Extract Interesting Strings
Use:
strings The-first-binary.exe
The most interesting strings are:
=== SECURE STORAGE VERIFIER v3.4 ===
[*] Initialising AES-256 subsystem...
[+] Cryptographic subsystem ready.
Enter the access password:
[SUCCESS] Access granted.
Flag: %s
[ERROR] Invalid password. Access denied.
Use rabin2 to obtain their virtual addresses:
rabin2 -zz The-first-binary.exe | grep -Ei \
'SECURE STORAGE|access password|Access granted|Invalid password|Flag:'
Output:
949 0x000199d0 0x0041b1d0 37 38 .rdata ascii === SECURE STORAGE VERIFIER v3.4 ===\n
952 0x00019a44 0x0041b244 27 28 .rdata ascii Enter the access password:
954 0x00019a68 0x0041b268 27 28 .rdata ascii \n[SUCCESS] Access granted.\n
955 0x00019a84 0x0041b284 9 10 .rdata ascii Flag: %s\n
956 0x00019a90 0x0041b290 42 43 .rdata ascii \n[ERROR] Invalid password. Access denied.\n
The important addresses are:
0x0041b244 -> password prompt
0x0041b268 -> success message
0x0041b284 -> flag format string
0x0041b290 -> failure message
6. Find Cross-References
The next step is to determine which function references these strings.
For the success string:
r2 -A -q -c 'axt @ 0x0041b268' The-first-binary.exe
Result:
main 0x40125e [STRN:r--] push str._n_SUCCESS__Access_granted._n
For the failure string:
r2 -A -q -c 'axt @ 0x0041b290' The-first-binary.exe
Result:
main 0x401284 [STRN:r--] push str._n_ERROR__Invalid_password._Access_denied._n
For the password prompt:
r2 -A -q -c 'axt @ 0x0041b244' The-first-binary.exe
Result:
main 0x40113a [STRN:r--] push str.Enter_the_access_password:
This establishes that the relevant logic is all inside:
main
The interesting code range is approximately:
0x40113a -> 0x401284
7. Analyze main
Disassemble it:
r2 -A -q -c 'pdf @ main' The-first-binary.exe
The important discovery is that the password is not compared directly against a plaintext string.
Instead, the program:
-
Reads the password.
-
Checks its length.
-
Generates a small
scratcharray from static constants. -
Processes every password byte independently.
-
Applies XOR, rotation, addition and another XOR.
-
ORs every result into an accumulator.
-
Requires the accumulator to remain zero.
8. Password Length Check
The first major constraint is the password length.
The disassembly contains:
cmp ecx, 0x18
jne 0x401284
0x18 is decimal:
0x18 = 24
Therefore:
The password must contain exactly 24 bytes.
This immediately eliminates ordinary brute-force approaches based on arbitrary-length input.
9. Understanding the Scratch-Key Generation
The verifier first generates four bytes of temporary state.
The static data involved is located around:
0x41b170
We extracted the relevant data with:
r2 -q -c 'p8 64 @ 0x41b170;q' The-first-binary.exe
The resulting regions were separated into:
seed
table
A
B
The solver recovered:
scratch = 13 d9 67 6b
table = 6b d2 39 a5 17 c8 4e f1
A =
8a 6f bb 21 05 60 8a 81
fd 6f 79 52 00 1e aa 7a
ef 4c 08 16 d2 3c 12 c6
B =
58 08 3e db 61 98 f0 d0
d9 a8 52 d8 de 9c 32 b1
3a af 4e 7f db 23 44 66
10. The Per-Byte Password Transformation
The important part of the verifier processes each byte i of the 24-byte password.
For every byte:
i = 0 ... 23
the verifier constructs an intermediate value.
The transformation can be represented as:
table[(3*i + 1) & 7]
XOR
scratch[i & 3]
XOR
password[i]
XOR
((17*i + 0x3d) & 0xff)
This value is then rotated left.
The rotation amount is:
((5*i + 3) % 7) + 1
Then the rotated value is added to:
(13*i + 0x27) & 0xff
Finally it is XORed with:
A[i] XOR B[i]
The result must be zero.
11. The Acceptance Condition
The program maintains an accumulator.
Conceptually:
accumulator |= transformed_byte;
At the end:
if (accumulator != 0)
failure();
else
success();
The relevant logic is effectively:
or al, byte [var_13h]
...
test al, al
jne 0x401284
Because the accumulator starts at zero and only receives OR operations, the only way to pass is:
transformed_byte[i] == 0
for every i.
This is the key to solving the challenge.
Instead of searching for the password, we can mathematically reverse each byte independently.
12. Write the Verification Equation
Define:
T = table[(3*i + 1) & 7]
S = scratch[i & 3]
D = (17*i + 0x3d) & 0xff
R = ((5*i + 3) % 7) + 1
C = (13*i + 0x27) & 0xff
H = A[i] XOR B[i]
The verifier effectively computes:
x = T XOR S XOR password[i] XOR D
x = ROL8(x, R)
x = (x + C) mod 256
x = x XOR H
The verifier requires:
x = 0
Therefore:
ROL8(x_before_rotation, R) + C = H
modulo 256.
13. Reverse the Addition
We know:
rotated + C = H
Therefore:
rotated = H - C
modulo 256.
So:
rotated = (H - C) & 0xff
14. Reverse the Rotation
The original operation was:
ROL8(value, R)
The inverse operation is:
ROR8(value, R)
Therefore:
pre_rotation = ROR8(H - C, R)
15. Reverse the XOR Operations
Before rotation:
pre_rotation =
T XOR S XOR password[i] XOR D
XOR is its own inverse.
Therefore:
password[i] =
pre_rotation
XOR T
XOR S
XOR D
So the password byte can be recovered directly.
There is no brute force involved.
16. Solver
The following Python script reconstructs the scratch state and reverses all 24 password bytes.
#!/usr/bin/env python3
import re
import subprocess
import sys
def rol8(x, n):
n &= 7
if n == 0:
return x & 0xff
return ((x << n) | (x >> (8 - n))) & 0xff
def ror8(x, n):
n &= 7
if n == 0:
return x & 0xff
return ((x >> n) | (x << (8 - n))) & 0xff
if len(sys.argv) != 2:
print(f"usage: {sys.argv[0]} The-first-binary.exe")
sys.exit(1)
exe = sys.argv[1]
p = subprocess.run(
["r2", "-q", "-c", "p8 64 @ 0x41b170;q", exe],
capture_output=True,
text=True,
check=True,
)
tokens = re.findall(
r"(?<![0-9a-fA-F])([0-9a-fA-F]{2})(?![0-9a-fA-F])",
p.stdout
)
if len(tokens) < 64:
h = re.sub(r"[^0-9a-fA-F]", "", p.stdout)
if len(h) < 128:
print("[!] Could not extract 64 bytes")
print(p.stdout)
sys.exit(1)
data = bytes.fromhex(h[:128])
else:
data = bytes.fromhex("".join(tokens[:64]))
assert len(data) == 64
# Data at 0x41b170
#
# 0x00..0x07 -> seed
# 0x08..0x0f -> table
# 0x10..0x27 -> A
# 0x28..0x3f -> B
seed = data[0:8]
table = data[8:16]
A = data[16:40]
B = data[40:64]
# Reconstruct scratch bytes.
scratch = bytearray(4)
for i in range(4):
k = data[4 + ((i + 1) & 3)]
k = rol8(
k,
(i + 1) & 7
)
scratch[i] = (
((i * 0x13 + 0x5a) & 0xff)
^ seed[i]
^ k
)
print("[+] scratch :", scratch.hex())
print("[+] table :", table.hex())
print("[+] A :", A.hex())
print("[+] B :", B.hex())
password = bytearray(24)
for i in range(24):
# Final XOR constant.
h = B[i] ^ A[i]
# Static table byte.
t = table[(3 * i + 1) & 7]
# Position-dependent XOR.
d = (17 * i + 0x3d) & 0xff
# Rotation amount.
rot = ((5 * i + 3) % 7) + 1
# Position-dependent addition.
add = (13 * i + 0x27) & 0xff
# Reverse addition.
target = (h - add) & 0xff
# Reverse ROL.
value = ror8(target, rot)
# Reverse XOR operations.
password[i] = (
value
^ t
^ scratch[i & 3]
^ d
)
candidate = bytes(password)
print()
print("[+] Candidate bytes:")
print(candidate)
print()
try:
print("[+] Candidate ASCII:")
print(candidate.decode("ascii"))
except UnicodeDecodeError:
print("[!] Candidate is not pure ASCII")
print()
print("[+] Hex:")
print(candidate.hex())
17. Execute the Solver
Run:
python3 solve.py ./The-first-binary.exe
The solver produces:
[+] scratch : 13d9676b
[+] table : 6bd239a517c84ef1
[+] A : 8a6fbb2105608a81fd6f7952001eaa7aef4c0816d23c12c6
[+] B : 58083edb6198f0d0d9a852d8de9c32b13aaf4e7fdb234466
[+] Candidate bytes:
b'FLAG{REDACTED}'
[+] Candidate ASCII:
FLAG{REDACTED}
[+] Hex:
464c41477b68756d614e65305f625261316e5f77316e357d
Therefore the recovered password is:
FLAG{REDACTED}
18. Validate Against the Binary
The recovered password can be tested directly:
wine The-first-binary.exe
Enter:
FLAG{REDACTED}
The verifier should reach:
[SUCCESS] Access granted.
Flag: FLAG{REDACTED}
This confirms that the mathematical inversion is correct.
19. Why the “AES-256” Banner Is Misleading
The program displays:
[*] Initialising AES-256 subsystem...
[+] Cryptographic subsystem ready.
At first glance, this suggests that the password might need to be recovered through AES cryptanalysis.
However, static analysis shows that the actual acceptance condition is a custom byte transformation involving:
-
XOR
-
byte rotation
-
modular addition
-
static lookup bytes
-
position-dependent constants
The important password verification does not require breaking AES.
This is a common reverse-engineering technique in CTFs: a program can contain convincing cryptographic terminology while the actual security-critical logic is a custom transformation.
20.1 Exact length check
The verifier requires:
24 bytes
because of:
cmp ecx, 0x18
jne failure
20.2 Independent byte constraints
Each password character is processed independently.
There is no dependency such as:
password[i] depends on password[i-1]
Instead, the only state shared between positions is the small repeating scratch[i & 3] value.
This makes the entire password reversible byte-by-byte.
20.3 XOR is easy to reverse
The verifier contains multiple XOR operations:
x XOR key
Since:
(a XOR b) XOR b = a
the XOR operations can simply be applied again in reverse.
20.4 Rotation is reversible
The forward operation is:
ROL8(x, n)
and its inverse is:
ROR8(x, n)
Therefore the rotation provides no one-way security.
20.5 Addition is modular
The verifier operates on bytes, so addition wraps at 256:
(x + C) mod 256
This can be reversed with:
x = (result - C) mod 256
21. Full Mathematical Derivation
For position i, the verifier computes:
p = password[i]
t = table[(3i + 1) & 7]
s = scratch[i & 3]
d = (17i + 0x3d) mod 256
r = ((5i + 3) mod 7) + 1
c = (13i + 0x27) mod 256
h = A[i] XOR B[i]
Then:
x = t XOR s XOR p XOR d
Rotate:
y = ROL8(x, r)
Add:
z = (y + c) mod 256
Final XOR:
w = z XOR h
The verifier requires:
w = 0
Therefore:
z XOR h = 0
which gives:
z = h
Undo the addition:
y = (h - c) mod 256
Undo the rotation:
x = ROR8(y, r)
Undo the XOR operations:
p = x XOR t XOR s XOR d
Thus:
password[i] =
ROR8(
(A[i] XOR B[i] - (13i + 0x27)) mod 256,
((5i + 3) mod 7) + 1
)
XOR table[(3i + 1) & 7]
XOR scratch[i & 3]
XOR ((17i + 0x3d) & 0xff)
Applying this for:
i = 0 ... 23
produces the complete password.
22. Final Flag
23. Takeaways
The challenge demonstrates several useful reverse-engineering techniques:
-
Identify the executable format and architecture
file binary.exe rabin2 -I binary.exe -
Locate important strings
rabin2 -zz binary.exe -
Use cross-references to find the relevant function
axt @ <string_address> -
Disassemble the containing function
pdf @ main -
Identify input constraints
- The password must be 24 bytes.
-
Translate assembly into mathematical operations
-
XOR
-
ROL
-
addition
-
XOR
-
-
Recognize reversible transformations
-
XOR → XOR again
-
ROL → ROR
-
addition → subtraction modulo 256
-
-
Solve each byte independently
-
Validate the recovered credential against the executable
The critical insight was that the verifier was not performing a one-way cryptographic operation. Every transformation applied to the password was reversible, and the final comparison forced every transformed byte to zero.
Flag
FLAG{REDACTED}

