---
title: GDB
description: "Debugger un binaire, inspecter la mémoire et automatiser l'analyse avec pwndbg, gef et GEF."
category: reverse
kind: tool
tags: [debugger, memory, breakpoints, pwndbg, elf]
level: intermediate
updated: 2026-11-03
order: 3
aliases: ["gdb", "pwndbg", "gef"]
---

## Lancer et inspecter

```bash
gdb ./binary
gdb -q ./binary
gdb --args ./binary input.txt
gdb -p $(pidof target)
```

```text
(gdb) start              # break à main
(gdb) run
(gdb) info functions
(gdb) info registers
(gdb) info proc mappings
(gdb) disassemble main
(gdb) x/20i $pc
(gdb) x/32gx $rsp
(gdb) x/s 0x402000
```

| Commande | Effet |
| --- | --- |
| `b *0x401234` | Breakpoint à une adresse |
| `b main` | Breakpoint sur une fonction |
| `c` | Continuer |
| `ni` / `si` | Step over / into |
| `finish` | Terminer la fonction |
| `bt` | Backtrace |
| `frame 1` | Changer de frame |
| `p $rax` | Afficher un registre |
| `set $rax=0` | Modifier un registre |
| `vmmap` | Mappings (gef/pwndbg) |

## pwndbg / gef

```bash
# pwndbg
git clone https://github.com/pwndbg/pwndbg && cd pwndbg && ./setup.sh
# ou gef
bash -c "$(curl -fsSL https://gef.blah.cat/sh)"
```

```text
pwndbg> checksec
pwndbg> vmmap
pwndbg> heap
pwndbg> bins
pwndbg> telescope $rsp 20
pwndbg> cyclic 200
pwndbg> cyclic -l 0x6161616c
pwndbg> rop --grep "pop rdi"
pwndbg> got
pwndbg> stack 30
```

## Breakpoints conditionnels

```text
(gdb) b *main+42 if *(int*)$rsp == 0
(gdb) command 1
> silent
> printf "arg: %s\n", $rdi
> continue
> end
```

```text
# Watchpoint : casser quand une valeur change
(gdb) watch *(int*)0x404060
(gdb) rwatch *(int*)0x404060
```

## Core dumps

```bash
# Autoriser les cores
ulimit -c unlimited
cat /proc/sys/kernel/core_pattern

# Analyser
gdb ./binary core
```

```text
(gdb) bt
(gdb) info registers
(gdb) x/40gx $rsp
(gdb) info proc mappings
```

## Debug distant

```bash
# Cible
gdbserver :1234 ./binary

# Attaquant
gdb -q
(gdb) target remote 10.10.10.10:1234
(gdb) continue
```

```bash
# Avec pwndbg et un binaire local pour les symboles
gdb ./binary
(gdb) target remote 10.10.10.10:1234
(gdb) set sysroot ./libs
```

## Scripting

```gdb
# commands.gdb
set pagination off
set disassembly-flavor intel
b main
run
x/10i $pc
info registers
quit
```

```bash
gdb -q -x commands.gdb ./binary
```

> [!TIP]
> Pour un binaire PIE, `b main` fonctionne avant `run` si les symboles sont présents. Sinon, casse sur l'entrée (`starti`) puis calcule la base avec `info proc mappings`.

> [!WARNING]
> `gdb` peut modifier la mémoire et les registres. Sur un binaire de production ou un malware, utilise une VM isolée et un snapshot. Ne lance jamais un échantillon inconnu directement sur ton host.
