$cat strcmp-strlen-strncmp.mdReversingHacknite 2.0
strcmp(), strlen(), strncmp()
The flag is stored as plain text inside the compiled program, so it shows up the moment you open the file in a disassembler.
$man strcmp-strlen-strncmp
What this one teaches:
- What a compiled program is, and that readable text can survive inside it.
- Opening a binary in a disassembler like IDA, or just running the strings command.
Task description
Ema wanted to play with the ultimate question of life, the universe and everything, so she wrote a C program that asks for a secret number. And no, it isn’t 42. The answer is in the strings, but she’s not sure how to get at it any more.
The original was in Croatian; this is my translation.
Text inside a program
A compiled program is the machine-code version of someone’s source, the form the computer actually runs. You can’t read it like source, but any plain text the program uses, such as messages it prints or values written directly into it, is still sitting in the file as readable characters.
The hint is right there in the task: “the answer is in the strings.” We opened the Linux program in IDA, a disassembler (a tool that takes a compiled program apart so you can inspect it). Looking at the main function, the flag was sitting there in plain text, written straight into the program.
That’s the whole task. You don’t even need IDA for this one. On Linux or macOS, the strings command lists every run of readable text in a file:
strings program | grep 'CTF2021'
It prints the flag. The point of the task is that a value baked into a program isn’t hidden at all; the next two reversing tasks make it progressively harder to read.
$cat flag.txt reveal
CTF2021[255990385189]