Skip to content

Lesson 3 of 9 · 27m

Debugger-Driven Vulnerability Analysis

Use gdb workflows, breakpoints, watchpoints, and memory inspection to reconstruct corruption instead of reacting to crashes.

A debugger is not merely a place where segmentation faults happen. It is a microscope for causality. The difference between an average exploit writeup and a professional analysis is usually one skill: stopping execution at the moment memory becomes wrong, not ten thousand instructions later when the damage finally trips over itself.

Break before corruption, not after impact

Suppose input is copied into a fixed buffer:

struct req {
    char name[64];
    void (*logfn)(struct req *);
    int verbose;
};

Do not break only at main. Break near the parser or copy operation, inspect object layout, then step over the write:

break vulnerable_copy
run < input
print sizeof(struct req)
print &req.name
print &req.logfn
x/12gx &req

Now you know the distance between influence and consequence. That number is more important than whether a cyclic pattern says the crash occurs at offset 88.

Watchpoints expose hidden writes

When corruption seems impossible, a watchpoint often reveals the real writer:

watch *(long *)0x555555559080
run < input
bt
info registers

Hardware watchpoints stop when memory changes. Use them on canary locations, saved return addresses, function pointers, allocator metadata, and application objects. If the watchpoint fires in a parser utility instead of the obvious copy routine, your source-level model was wrong.

Automate repeatable state capture

Exploit work involves too many details to hold in your head. Script gdb for consistent context:

define state
  printf "rip=%p rsp=%p rdi=%p rsi=%p
", $rip, $rsp, $rdi, $rsi
  x/6gx $rsp
  bt 5
end

pwndbg and GEF provide similar convenience, but do not let the UI become a substitute for understanding. Know which register is argument one under the amd64 SysV ABI, how return addresses are consumed, and why rsp alignment matters for some libc calls.

Compare good input with corrupting input

Diff behavior deliberately. Capture memory before and after both cases:

control input: length 64, accepted
boundary input: length 65, accepted/rejected?
corruption input: length 96, logfn overwritten?

This catches validation that only runs on some paths, integer truncation before allocation, null-byte limitations, newline transformations, and encoding behavior. Real exploit constraints often come from input plumbing rather than the memory-corruption primitive itself.

Production analysis is gentler

On a real target you may have a core dump rather than interactive control. The discipline is identical: reconstruct object ownership, map corrupted bytes back to attacker input, and distinguish root cause from secondary damage. Do not claim remote code execution because you saw rip equal 0x41414141; prove controlled execution or state precisely what remains unproven.

Field notes

  • Optimized binaries reuse registers and inline functions; source lines may jump or disappear in gdb.
  • Watchpoints can dramatically slow execution, especially in loops. Set them after narrowing the corruption window.
  • Debugger startup can alter environment layout. Test exploit reliability outside the debugger too.
  • Forking servers need follow-fork-mode and possibly detach-on-fork configuration before useful analysis.

Was this lesson helpful?

Sign in to rate