Lion Cipher Lab
Automate a gdb session: log every call of a function with breakpoint commands and the Python API
- Cyber / Security Engineer
- Advanced
- ~60 min
- Free · no account required
Why it matters
Stepping through a program by hand is how you learn it, but it does not scale. An analyst facing an unfamiliar validation routine, a decoder, or a function called hundreds of times wants a log, not a hundred keystrokes: every call, every argument, in order. gdb can be scripted, from simple breakpoint commands up to a full Python API, so one script can run the program and write that log for you while you do something else. Scripted tracing is also repeatable: you can hand the script to a colleague, rerun it on the next version, and diff the logs. This lab teaches the technique on a toy license…
What you'll learn
- writing a gdb command file and running it with -x and -batch
- attaching commands to a breakpoint, with silent and continue, so it logs without stopping
- using dprintf, conditional breakpoints and convenience variables for quick tracing
- subclassing gdb.Breakpoint in Python and writing a stop() method that returns False to keep going
- reading arguments by name, from registers and from raw inferior memory in a script
- judging when scripted tracing beats an interactive session, and when it does not
Steps in this lab
- The problem: a function you want a log of
- Build the toy license check
- The slow way, so you feel why scripting helps
- Breakpoint commands: log and keep going
- Filter without code: a conditional breakpoint
- A first taste of the Python API
- Write the trace as a Python Breakpoint subclass
- Check the log against the source, then make it stop on purpose
- When NOT to script gdb, what it cannot do, and how a pro does it better
Open the full interactive lab →