gdb-peda

PEDA - Python Exploit Development Assistance pour GDB. Enrichit GDB avec une sortie colorisée, du contexte de désassemblage, la génération de patterns, la recherche de gadgets ROP, et des aides à l'exploitation. PEDA — Python Exploit Development Assistance for GDB. Enhances GDB with colorized output, disassembly context, pattern generation, ROP gadget search, and exploit helpers.

↗ https://github.com/longld/peda

Overview

PEDA (Python Exploit Development Assistance) is a GDB extension that makes exploit development significantly easier. It adds colorized context display, pattern generation for offset finding, ROP gadget search, memory analysis, and many helper commands on top of standard GDB.

Installation

# Install PEDA
git clone https://github.com/longld/peda ~/peda
echo "source ~/peda/peda.py" >> ~/.gdbinit

Or use GEF (alternative, more actively maintained)

bash -c "$(curl -fsSL https://gef.blah.cat/sh)"
# Or use pwndbg (another popular alternative)
git clone https://github.com/pwndbg/pwndbg
cd pwndbg && ./setup.sh

Basic Usage

Start GDB with PEDA

gdb ./vulnerable_binary

Attach to running process

gdb -p <PID>

Run with arguments

gdb --args ./binary arg1 arg2

Key PEDA Commands

# Run the binary
(gdb) r
(gdb) run arg1 arg2

Display context (registers, stack, disassembly)

(gdb) context
# Set breakpoint
(gdb) b main
(gdb) b *0x401234    # break at address
(gdb) s    # step into
(gdb) n    # step over
(gdb) c    # continue
(gdb) ni   # next instruction
(gdb) si   # step instruction

Pattern Generation (Offset Finding)

Generate unique pattern (De Bruijn sequence)

(gdb) pattern create 200

→ → Aa0Aa1Aa2Aa3Aa4Aa5…

Copy pattern as input to binary

(gdb) r <<< $(python -c "print('Aa0Aa1Aa2...')")

When crash occurs, find offset:

(gdb) pattern offset 0x41336141

→ → 76 found at offset: 76

Or use the EIP/RIP value

(gdb) pattern offset $rip

Memory Analysis

# Search for string in memory
(gdb) find "/bin/sh"
(gdb) searchmem "/bin/sh"

Search for pattern

(gdb) searchmem "AAAA" all
(gdb) x/20xg $rsp    # 20 qwords from RSP
(gdb) x/s 0x601080   # string at address
(gdb) x/i 0x401234   # instruction at address
# Print registers
(gdb) info registers
(gdb) i r rip rsp rbp rdi

ROP Gadgets

Find ROP gadgets in binary

(gdb) ropgadget
# Search for specific gadgets
(gdb) ropsearch "pop rdi"
(gdb) ropsearch "pop rdi; ret" binary

Find /bin/sh location

(gdb) find "/bin/sh"

Checksec — Binary Protections

Check binary security features

(gdb) checksec
# Output example:
# CANARY   : ENABLED    → stack canary present
# FORTIFY  : disabled
# NX       : ENABLED    → non-executable stack (DEP)
# PIE      : disabled   → fixed base address (no ASLR)
# RELRO    : Partial    → partial RELRO

Useful Shortcuts

# Show PLT/GOT entries
(gdb) plt
(gdb) got

Show shared libraries

(gdb) libs
# Disassemble a function
(gdb) disas main
(gdb) pd main

View stack

(gdb) telescope $rsp 20   # GEF command (similar in PEDA)

Show vmmap (memory layout)

(gdb) vmmap

Tips

  • Use context command after each step to see the full CPU state
  • Pattern create/offset is the fastest way to find buffer overflow offsets
  • checksec is the first thing to run on any new binary
  • GEF is a modern alternative to PEDA with more active development
GEF Alternative

GEF (GDB Enhanced Features) — modern PEDA alternative

bash -c "$(curl -fsSL https://gef.blah.cat/sh)"
gef> heap      # Heap analysis
gef> telescope # Show memory at address
gef> xinfo     # Detailed info about address
gef> format-string-helper  # Format string vuln helper
gef> got       # Global offset table
gef> elf-info  # ELF headers and sections

Vue d’ensemble

PEDA (Python Exploit Development Assistance) est une extension GDB qui rend le développement d’exploits nettement plus facile. Elle ajoute un affichage de contexte colorisé, la génération de patterns pour trouver des offsets, la recherche de gadgets ROP, l’analyse mémoire, et de nombreuses commandes d’aide par-dessus le GDB standard.

Installation

# Installer PEDA
git clone https://github.com/longld/peda ~/peda
echo "source ~/peda/peda.py" >> ~/.gdbinit

Ou utiliser GEF (alternative plus activement maintenue)

bash -c "$(curl -fsSL https://gef.blah.cat/sh)"
# Ou utiliser pwndbg (une autre alternative populaire)
git clone https://github.com/pwndbg/pwndbg
cd pwndbg && ./setup.sh

Utilisation de base

# Démarrer GDB avec PEDA
gdb ./vulnerable_binary

# S'attacher à un processus en cours
gdb -p <PID>

# Lancer avec des arguments
gdb --args ./binary arg1 arg2

Commandes PEDA clés

# Lancer le binaire
(gdb) r
(gdb) run arg1 arg2
# Afficher le contexte (registres, pile, désassemblage)
(gdb) context
# Poser un breakpoint
(gdb) b main
(gdb) b *0x401234    # break à une adresse
(gdb) s    # step into
(gdb) n    # step over
(gdb) c    # continue
(gdb) ni   # instruction suivante
(gdb) si   # step instruction

Génération de patterns (recherche d’offset)

# Générer un pattern unique (séquence de De Bruijn)
(gdb) pattern create 200

→ Aa0Aa1Aa2Aa3Aa4Aa5…

# Copier le pattern comme entrée du binaire
(gdb) r <<< $(python -c "print('Aa0Aa1Aa2...')")

Quand un crash survient, trouver l’offset :

(gdb) pattern offset 0x41336141

→ 76 found at offset: 76

Ou utiliser la valeur EIP/RIP

(gdb) pattern offset $rip

Analyse mémoire

# Rechercher une chaîne en mémoire
(gdb) find "/bin/sh"
(gdb) searchmem "/bin/sh"
# Rechercher un pattern
(gdb) searchmem "AAAA" all
(gdb) x/20xg $rsp    # 20 qwords à partir de RSP
(gdb) x/s 0x601080   # chaîne à l'adresse
(gdb) x/i 0x401234   # instruction à l'adresse
# Afficher les registres
(gdb) info registers
(gdb) i r rip rsp rbp rdi

Gadgets ROP

# Trouver des gadgets ROP dans le binaire
(gdb) ropgadget
# Rechercher des gadgets spécifiques
(gdb) ropsearch "pop rdi"
(gdb) ropsearch "pop rdi; ret" binary

Trouver l’emplacement de /bin/sh

(gdb) find "/bin/sh"

Checksec - protections binaires

Vérifier les fonctionnalités de sécurité du binaire

(gdb) checksec
# Exemple de sortie :
# CANARY   : ENABLED    → canari de pile présent
# FORTIFY  : disabled
# NX       : ENABLED    → pile non exécutable (DEP)
# PIE      : disabled   → adresse de base fixe (pas d'ASLR)
# RELRO    : Partial    → RELRO partiel

Raccourcis utiles

# Afficher les entrées PLT/GOT
(gdb) plt
(gdb) got

Afficher les bibliothèques partagées

(gdb) libs
# Désassembler une fonction
(gdb) disas main
(gdb) pd main

Voir la pile

(gdb) telescope $rsp 20   # commande GEF (similaire dans PEDA)

Afficher la vmmap (disposition mémoire)

(gdb) vmmap

Conseils

  • Utiliser la commande context après chaque pas pour voir l’état complet du CPU
  • Pattern create/offset est le moyen le plus rapide de trouver les offsets de buffer overflow
  • checksec est la première chose à lancer sur tout nouveau binaire
  • GEF est une alternative moderne à PEDA avec un développement plus actif
GEF Alternative

GEF (GDB Enhanced Features) — modern PEDA alternative

bash -c "$(curl -fsSL https://gef.blah.cat/sh)"
gef> heap      # Heap analysis
gef> telescope # Show memory at address
gef> xinfo     # Detailed info about address
gef> format-string-helper  # Format string vuln helper
gef> got       # Global offset table
gef> elf-info  # ELF headers and sections