// GDB baby step 1
Reverse Engineering · Easy · picoCTF 2025
// Summary
A program is given that produces one number when it finishes and never shows it. The task is to find that number. A program file is stored as instructions for the computer's processor, not as readable text, so a tool called a debugger1 translates those instructions into a readable list. The number is written directly in that list, so reading it is enough; the program never needs to run. Comparable to finding a recipe's final total printed in its steps instead of cooking the meal to find out.
// Objective
Given: debugger0_a, an ELF2 binary.
Asked: the value in eax3 at the end of main, in decimal, as academy{n}.
Type: stated.
// Recon
cat debugger0_a — Unreadable bytes. The file is compiled machine code4, not text.gdb ./debugger0_a → disassemble5 main — Assembly6 listing of main. The last write to eax before ret7: mov $0x86342,%eax.
// Deduction
catoutput is unreadable → the file is a compiled binary → it has to be disassembled, not read as text.- A function's return value is left in
eaxby convention → "eax at the end of main" means main's return value → find the last write toeaxbeforeret. - The instruction moves a constant (
$0x86342) → no runtime calculation affects it → read it directly, no need to run the program. - The flag requires decimal and the constant is hex8 → convert.
// Solve
gdb ./debugger0_a
Result:(gdb)prompt.disassemble main(at the(gdb)prompt)
Result:mov $0x86342,%eaxbeforeret.python3 -c "print(0x86342)"
Result: the decimal value.- Wrap the decimal value as
academy{n}.
Result: the flag.
// Answer
Plain: the flag is the number the program hands back when it finishes. The instructions write it in base 16 (the digits 0–9 plus a–f); the flag is the same number in ordinary base 10.
Technical: under the x86-64 calling convention, main's return value is in eax at ret. The only write to eax before ret is the immediate 0x86342, so the return value is that constant. The flag is its decimal form.
// Dead ends
gdb commands typed at the bash prompt — gdb commands only run at the (gdb) prompt.
// Root cause
Skill tested: reading a function's return value from disassembly. AT&T syntax9: mov $<value>,%<register10> puts the value into the register.
Real-world use: malware analysts read compiled programs the same way, to learn what a program does without running it.
// Transfer
- "Value of register X at point Y" → disassemble, find the last write to X before Y.
- If that write comes from a calculation rather than a constant → set a breakpoint before
ret,run,info registers eax.
// Index
- 1Debugger (gdb)A tool that pauses, inspects, and translates a running or stored program.
- 2Binary / ELFA program file in the processor's own format. ELF is the standard format on Linux.
- 3
eaxThe register that holds a function's result when it finishes. - 4Machine codeThe numeric instructions a processor runs directly. Not human-readable.
- 5DisassembleTranslate machine code into assembly.
- 6AssemblyA readable, one-line-per-instruction form of machine code.
- 7
retThe instruction that ends a function and returns to its caller. - 8Hexadecimal (hex)Base 16: digits 0–9 then a–f. Written with a
0xprefix. - 9AT&T syntaxOne of two ways to write assembly. Puts the source first, the destination second, and marks values with
$and registers with%. - 10RegisterA small storage slot inside the processor.