Skip to content

pwndbg - GDB/LLDB Exploit Development Cheatsheet

pwndbg - GDB/LLDB Exploit Development Cheatsheet

pwndbg (pronounced “pwn-dee-bee-gee”) is a Python plugin that loads into GDB — and now LLDB — to make exploit development and reverse engineering far less painful. It adds heap inspection, ROP gadget search, register/stack/pointer “telescoping,” a smart context display on every stop, and dozens of commands that core debuggers never provided. It is a successor in spirit to PEDA and a sibling to GEF.

Installation

MethodCommand
Setup script (recommended)git clone https://github.com/pwndbg/pwndbg && cd pwndbg && ./setup.sh
Nixnix profile install github:pwndbg/pwndbg
Arch (AUR)yay -S pwndbg
Manual GDB loadadd source /path/to/pwndbg/gdbinit.py to ~/.gdbinit
LLDBadd command script import /path/to/pwndbg/lldbinit.py to ~/.lldbinit
Verifystart gdb — you should see the pwndbg> prompt

Starting a Session

CommandDescription
gdb ./binaryLoad a binary under pwndbg
gdb -p PIDAttach to a running process
gdb ./binary coreOpen a core dump for post-mortem analysis
startRun and break at main
entryRun and break at the ELF entry point
r ARGSRun with arguments
startiStop at the very first instruction

Context & Navigation

CommandDescription
contextRedraw the full context (regs, disasm, stack, backtrace)
context regShow only the registers pane
ctx-watch EXPRAdd an expression to the context watch pane
nextcallStep until the next call instruction
nextretStep until the next ret
stepuntilasm movStep until a given mnemonic
xinfo ADDRExplain what an address maps to (which mapping/section)

Memory Inspection

CommandDescription
telescope ADDRDereference and “telescope” a chain of pointers
telescope $sp 20Telescope 20 entries from the stack pointer
hexdump ADDRHex+ASCII dump (the command GDB never had)
vmmapShow the process virtual memory map
vmmap libcFilter the memory map by name
search -t string "PASS"Search memory for a string
search -t bytes 0xdeadbeefSearch memory for a byte pattern
distance ADDR1 ADDR2Byte distance between two addresses
p2p MAP1 MAP2Find pointer chains between two mappings

Heap Analysis (glibc)

CommandDescription
heapList heap chunks
binsShow all free bins (fast, tcache, small, large, unsorted)
tcacheInspect the tcache
fastbinsShow fastbin contents
malloc_chunk ADDRDecode a chunk header at an address
top_chunkShow the top (wilderness) chunk
vis_heap_chunksVisualize heap layout with colors
find_fake_fast ADDRHunt for fastbin fake-chunk targets

Exploit Development

CommandDescription
cyclic 200Generate a De Bruijn pattern (offset finder)
cyclic -l 0x6161616cLook up the offset of a value in the pattern
rop --grep "pop rdi"Search ROP gadgets
ropgadgetDump gadgets (ROPgadget integration)
checksecShow binary mitigations (NX, PIE, RELRO, canary)
gotShow the GOT and resolved addresses
pltShow the PLT
aslrShow/toggle ASLR for the debugee
canaryShow the current stack canary value

Breakpoints & Watchpoints

CommandDescription
b *0x401136Break at an absolute address
b mainBreak at a symbol
breakrva 0x1136Break at an RVA (handy with PIE)
watch GLOBALBreak when a value changes
rwatch ADDRBreak on read access
ignore N COUNTIgnore a breakpoint N times

Common Workflows

# Find the exact offset to overwrite a saved return address
pwndbg> cyclic 200
pwndbg> r            # paste the pattern, crash
pwndbg> cyclic -l $rsp   # report the offset

# Inspect mitigations, then look for a one-gadget-friendly ROP chain
pwndbg> checksec
pwndbg> rop --grep "pop rdi"

# Walk a heap use-after-free
pwndbg> vis_heap_chunks
pwndbg> bins

pwndbg vs GEF vs PEDA

FeaturepwndbgGEFPEDA
GDB supportYesYesYes
LLDB supportYesNoNo
Heap analysisDeep (glibc)GoodLimited
ROP toolingBuilt-inBuilt-inBuilt-in
Active developmentYesYesMinimal

Resources