Our engine only fires with the right password. We built it tough: pop it open in a disassembler and the important part is pure noise. It only makes sense once the engine is running.
Flag: csaw{c0d3_th4t_rewr1t3s_1ts3lf_c4nt_b3_tru5t3d}
$ file nitro
nitro: ELF 64-bit LSB executable, x86-64, ..., not stripped
$ nm -C nitro
...
000000000040130d T __start_enccode
000000000040146b T __stop_enccode
0000000000402020 r enc_flag
00000000004020a8 r smc_key.0
000000000040130d T secret_check
Two things stand out immediately:
enccode, holding secret_check — separate from .text.enc_flag and smc_key, strongly hinting at
self-modifying / self-decrypting code (“SMC”).Disassembling secret_check directly produces garbage — that’s the “pure
noise” the prompt mentions, because the bytes on disk are XOR-encrypted.
main()call sysconf(0x1e) ; get page size
lea rax, [secret_check]
lea rdx, [__stop_enccode]
sub rax, rdx ; size of enccode section
...
call mprotect(page, size, PROT_READ|WRITE|EXEC)
main():
enccode section.mprotect() to make it writable (it’s normally just r-x).for (i = 0; i < enc_size; i++)
secret_check[i] ^= smc_key[i % 8];
secret_check(argv[1]).So the code only becomes valid x86 after this XOR pass runs at startup — hence “it only makes sense once the engine is running.”
No need to actually run it — we can replicate the XOR in Python using the
raw file bytes, since enccode’s file offset equals vaddr - 0x400000 for
this non-PIE binary.
data = bytearray(open('nitro','rb').read())
base = 0x400000
enc = data[0x40130d - base : 0x40130d - base + 0x15e] # __start/__stop_enccode
key = data[0x4020a8 - base : 0x4020a8 - base + 8] # smc_key
dec = bytes(b ^ key[i % 8] for i, b in enumerate(enc))
key turned out to be 13 37 C0 DE BA AD F0 0D.
Disassembling the decrypted bytes (objdump -D -b binary -m i386:x86-64 --adjust-vma=0x40130d) gives real, readable code:
char check[10] = "n2o_boost";
bool ok = true;
for (i = 0; i <= 8; i++)
if (password[i] != check[i]) { ok = false; break; }
if (password[9] != 0) ok = false; // length must be exactly 9
if (ok) {
// decrypt enc_flag and printf("NITRO ENGAGED: %s\n", flag);
} else {
puts("Access denied. The engine stays cold.");
}
So the required password is simply n2o_boost.
The flag bytes (enc_flag, 47 bytes at 0x402020) are XOR’d with a
keystream that is itself derived from bytes of the decrypted secret_check
function — another small self-referential trick:
key_byte[i] = 0x6B + secret_check_bytes[(7*i + 3) % 0x15e] + 5*i;
flag[i] = enc_flag[i] ^ key_byte[i];
Reimplementing that in Python with the already-decrypted secret_check
bytes:
key_size = len(dec) # 0x15e
enc_flag = data[0x402020-base : 0x402020-base+0x2f]
flag = bytearray()
for i in range(0x2f):
idx = (7*i + 3) % key_size
kb = (0x6b + dec[idx] + 5*i) & 0xff
flag.append(enc_flag[i] ^ kb)
print(bytes(flag))
Output:
csaw{c0d3_th4t_rewr1t3s_1ts3lf_c4nt_b3_tru5t3d}
$ ./nitro n2o_boost
NITRO ENGAGED: csaw{c0d3_th4t_rewr1t3s_1ts3lf_c4nt_b3_tru5t3d}
mprotect + XOR-decrypt-in-place pattern as classic SMC.