pwndbg - GDB/LLDB Exploit Development Cheatsheet
pwndbg (“pwn-dee-bee-gee”로 발음)는 GDB에 로드되는 Python 플러그인이며 이제 LLDB도 지원합니다. 이 도구는 exploit 개발과 역분석을 훨씬 더 쉽게 만들어줍니다. 힙 검사, ROP 가젯 검색, 레지스터/스택/포인터 “telescoping”, 스마트 컨텍스트 표시, 그리고 핵심 디버거가 제공하지 않았던 수십 가지 명령을 제공합니다. PEDA의 정신적 후계자이며 GEF의 형제입니다.
Installation
| Method | Command |
|---|
| Setup script (권장) | git clone https://github.com/pwndbg/pwndbg && cd pwndbg && ./setup.sh |
| Nix | nix profile install github:pwndbg/pwndbg |
| Arch (AUR) | yay -S pwndbg |
| Manual GDB load | ~/.gdbinit에 source /path/to/pwndbg/gdbinit.py 추가 |
| LLDB | ~/.lldbinit에 command script import /path/to/pwndbg/lldbinit.py 추가 |
| Verify | gdb 시작 — pwndbg> 프롬프트가 표시되어야 함 |
Starting a Session
| Command | Description |
|---|
gdb ./binary | pwndbg 아래에서 바이너리 로드 |
gdb -p PID | 실행 중인 프로세스에 연결 |
gdb ./binary core | 사후 분석을 위해 core dump 열기 |
start | 실행하고 main에서 중단 |
entry | 실행하고 ELF 진입점에서 중단 |
r ARGS | 인자와 함께 실행 |
starti | 가장 첫 번째 명령에서 중지 |
Context & Navigation
| Command | Description |
|---|
context | 전체 컨텍스트 다시 그리기 (레지스터, disasm, 스택, backtrace) |
context reg | 레지스터 패널만 표시 |
ctx-watch EXPR | 컨텍스트 watch 패널에 표현식 추가 |
nextcall | 다음 call 명령까지 단계 실행 |
nextret | 다음 ret 명령까지 단계 실행 |
stepuntilasm mov | 주어진 mnemonic까지 단계 실행 |
xinfo ADDR | 주소가 무엇을 나타내는지 설명 (매핑/섹션) |
Memory Inspection
| Command | Description |
|---|
telescope ADDR | 포인터 체인을 역참조하고 “telescope” |
telescope $sp 20 | 스택 포인터에서 20개 항목 telescope |
hexdump ADDR | Hex+ASCII dump (GDB가 제공하지 않은 명령) |
vmmap | 프로세스 가상 메모리 맵 표시 |
vmmap libc | 이름으로 메모리 맵 필터링 |
search -t string "PASS" | 메모리에서 문자열 검색 |
search -t bytes 0xdeadbeef | 메모리에서 바이트 패턴 검색 |
distance ADDR1 ADDR2 | 두 주소 사이의 바이트 거리 |
p2p MAP1 MAP2 | 두 매핑 사이의 포인터 체인 찾기 |
Heap Analysis (glibc)
| Command | Description |
|---|
heap | 힙 청크 나열 |
bins | 모든 free bins 표시 (fast, tcache, small, large, unsorted) |
tcache | tcache 검사 |
fastbins | fastbin 내용 표시 |
malloc_chunk ADDR | 주소의 청크 헤더 디코드 |
top_chunk | top (wilderness) 청크 표시 |
vis_heap_chunks | 힙 레이아웃을 색상으로 시각화 |
find_fake_fast ADDR | fastbin fake-chunk 대상 찾기 |
Exploit Development
| Command | Description |
|---|
cyclic 200 | De Bruijn 패턴 생성 (오프셋 찾기) |
cyclic -l 0x6161616c | 패턴에서 값의 오프셋 조회 |
rop --grep "pop rdi" | ROP 가젯 검색 |
ropgadget | 가젯 덤프 (ROPgadget 통합) |
checksec | 바이너리 완화 표시 (NX, PIE, RELRO, canary) |
got | GOT 및 resolved 주소 표시 |
plt | PLT 표시 |
aslr | debugee에 대한 ASLR 표시/토글 |
canary | 현재 스택 canary 값 표시 |
Breakpoints & Watchpoints
| Command | Description |
|---|
b *0x401136 | 절대 주소에서 중단 설정 |
b main | 기호에서 중단 설정 |
breakrva 0x1136 | RVA에서 중단 설정 (PIE에서 유용) |
watch GLOBAL | 값이 변경될 때 중단 |
rwatch ADDR | 읽기 액세스에서 중단 |
ignore N COUNT | breakpoint를 N번 무시 |
Common Workflows
# 저장된 반환 주소를 덮어쓰기 위한 정확한 오프셋 찾기
pwndbg> cyclic 200
pwndbg> r # 패턴 붙여넣기, 크래시
pwndbg> cyclic -l $rsp # 오프셋 보고
# 완화 검사 후 one-gadget 친화적 ROP 체인 찾기
pwndbg> checksec
pwndbg> rop --grep "pop rdi"
# 힙 use-after-free 추적
pwndbg> vis_heap_chunks
pwndbg> bins
pwndbg vs GEF vs PEDA
| Feature | pwndbg | GEF | PEDA |
|---|
| GDB support | Yes | Yes | Yes |
| LLDB support | Yes | No | No |
| Heap analysis | Deep (glibc) | Good | Limited |
| ROP tooling | Built-in | Built-in | Built-in |
| Active development | Yes | Yes | Minimal |
Resources