A stripped, non-PIE ELF asks for a 16-character "chassis licence" and
only prints a calibration record - which holds the flag - if it checks
out. The check is a four-round Feistel network over two
u64s, with a splitmix64 finalizer as the round function and round keys
derived from a hash of the binary's own code.
Hint
If attaching a debugger makes the binary immediately bail with an error message, it's checking for you. Go static instead.
No tracer allowed
$ ltrace -e strcmp ./metronome AAAAAAAAAAAAAAAA
METRONOME: escapement fault
That's ptrace(PTRACE_TRACEME) at the top of main - the binary
refuses to run under any tracer at all, so there's no dynamic shortcut.
Static analysis from here on.
Mapping the functions
main copies argv[1] into a buffer, strips the newline, and requires
exactly 16 characters, then calls keygen (fills four round keys) and
check (returns nonzero on a good licence); on success it calls a
printer that decrypts and prints the record.
Insight
keygen hashes a fixed window of its own code with an variant,
so the resulting hash is a constant baked into the binary - not
something that depends on runtime state. There's also an rdtsc delta
check right after it: if a single run takes more than 50 million cycles,
the hash gets XORed with a garbage constant. That's purely an
anti-single-stepping trick - at normal execution speed the branch never
fires, so the keys are deterministic and recoverable without ever
running the binary.
Pitfall
The key-generation loop runs rcx += 0x6a09e667f3bcc909 until
rcx == 0xa827999fcef32424. Reading that target value as a byte count
made no sense against four round keys. It's actually
0xa827999fcef32424 / 0x6a09e667f3bcc909 (mod 2^64) - and since the
step is odd (invertible mod 2^64), that division resolves cleanly to
exactly 4. Four round keys, matching four Feistel rounds.
check loads A = lic[0:8] and B = lic[8:16] as little-endian u64s
and runs four rounds of (A, B) -> (B, A ^ mix(B, k_i)), where mix is
a splitmix64 finalizer with rotations instead of shifts:
1def mix(a, b):
2 z = (a + b) & M
3 z = (z * 0x9e3779b97f4a7c15) & M
4 z ^= rol(z, 29)
5 z = (z * 0xbf58476d1ce4e5b9) & M
6 return (z ^ rol(z, 32)) & M
It accepts when the final (A, B) matches a fixed 16-byte target in
.rodata. Every round is invertible - this is a cipher, not a hash - so
the licence is just the inverse chain run on that target.
Pitfall
The success format string looked, at a glance, like two separate
strings: "METRONOME: licence accepted\n" and something else. It's
actually one single string, "METRONOME: licence accepted\n%s\n". The
record isn't printed somewhere else in the binary - the %s is the
record, decrypted at runtime right before this printf.
Recovering the licence and decrypting the record
Inverting the Feistel chain gives 16 printable bytes:
QJGF5CBFPQ-BN4Q6 - a strong sign this is the intended gate, not a
decoy (garbage input would invert to garbage bytes). The printer then
seeds a rolling hash with the licence string and uses it as an
xorshift64* state to generate a keystream, which XORs byte-wise against
a 137-byte ciphertext blob in .rodata:
1def decrypt_record(lic, data):
2 state = str_hash(lic)
3 blob = data[0x20c0:0x20c0 + 137]
4 out, word = bytearray(), 0
5 for i, c in enumerate(blob):
6 if i % 8 == 0:
7 x = state
8 x ^= x >> 12
9 x ^= (x << 25) & M
10 x ^= x >> 27
11 state = x & M
12 word = (x * 0x2545f4914f6cdd1d) & M
13 out.append(c ^ ((word >> ((i % 8) * 8)) & 0xff))
14 return bytes(out)
[*] licence = QJGF5CBFPQ-BN4Q6
TIMING RACK CALIBRATION RECORD
chassis licence accepted, escapement nominal
vendor token: L3m0n{it_ticks_because_it_watches_itself_3087}
Note
Confirmed by running the actual binary with the recovered licence (no
tracer attached this time) and getting the identical output. The flag
string doesn't exist anywhere in the binary as plaintext - it's
genuinely decrypted using the licence as a key, not sitting in .rodata
waiting to be grepped. The token itself is a wink at the ptrace
self-trace at the top of main: the thing ticks because it watches
itself.