C:\Seyi\Portfolio\writeups\gdb_baby_step_1_ Y:0000PX
...\writeups\gdb_baby_step_1 Y:0000PX

< back to write-ups

CTF // EASY gdb_baby_step_1.md

// 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 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 binary.
Asked: the value in at the end of main, in decimal, as academy{n}.
Type: stated.

// Recon

cat debugger0_a — Unreadable bytes. The file is compiled , not text.
gdb ./debugger0_a → main — listing of main. The last write to eax before : mov $0x86342,%eax.

// Deduction

  1. cat output is unreadable → the file is a compiled binary → it has to be disassembled, not read as text.
  2. A function's return value is left in eax by convention → "eax at the end of main" means main's return value → find the last write to eax before ret.
  3. The instruction moves a constant ($0x86342) → no runtime calculation affects it → read it directly, no need to run the program.
  4. The flag requires decimal and the constant is → convert.

// Solve

  1. gdb ./debugger0_a
    Result: (gdb) prompt.
  2. disassemble main (at the (gdb) prompt)
    Result: mov $0x86342,%eax before ret.
  3. python3 -c "print(0x86342)"
    Result: the decimal value.
  4. 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. : mov $<value>,%<> 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

  1. 1Debugger (gdb)A tool that pauses, inspects, and translates a running or stored program.
  2. 2Binary / ELFA program file in the processor's own format. ELF is the standard format on Linux.
  3. 3eaxThe register that holds a function's result when it finishes.
  4. 4Machine codeThe numeric instructions a processor runs directly. Not human-readable.
  5. 5DisassembleTranslate machine code into assembly.
  6. 6AssemblyA readable, one-line-per-instruction form of machine code.
  7. 7retThe instruction that ends a function and returns to its caller.
  8. 8Hexadecimal (hex)Base 16: digits 0–9 then a–f. Written with a 0x prefix.
  9. 9AT&T syntaxOne of two ways to write assembly. Puts the source first, the destination second, and marks values with $ and registers with %.
  10. 10RegisterA small storage slot inside the processor.