Reverse Engineering Cheat Sheet
Goal: understand what a binary does without source. Start with strings/analysis → static disassembly → dynamic debugging.
First Look (quick triage)
- File type & protections
file ./bin,checksec ./bin(orreadelf) - Interesting strings
strings -n 8 ./bin | grep -iE "flag|pass|secret|key|/bin/sh" - Imports & sym
objdump -T ./bin,nm -D ./bin(dynamic symbols) - Sections
readelf -h -l -S ./bin
Static Analysis (disassembly)
- objdump text + source interleave
objdump -d -M intel ./bin - Symbol table (if not stripped)
nm ./bin - Full graph visual: Ghidra (free, GUI) — decompile: open, auto-analysis, Functions → main → “Decompile”
- IDA (paid) same workflow in C decompiler
- radare2 / rizin CLI:
r2 -A ./bin→aaa; afl; s main; pdf
Dynamic Analysis (debugger)
- GDB quick: run with input, break at cmp after user input, read stack/registers
- pwndbg/GEF helpers:
checksec,context,ropper - Trace interesting calls: break at
system,strcmp,write—b system, thencontinue - Patch & re-run quickly: change
jztonop/jnztojnein gdb (set writes onnot built-in — use binary patch with radare2wx eb 00 @ 0x401234)
Deobfuscation / unpacking
- Detect packer:
upx -d ./binif UPX;stringsstill junk → likely packed - Unpacking with gdb
caveat: break at OEP (Original Entry Point) — run, watch forpopad; jmp(upx), Dump + fix imports - PowerShell/JS/obfuscated Python: decode iteratively (base64 layers,
exec/evalscan, de4py for python)
Android/Java
- APK:
unzip,jadx-gui app.apk→ decompile dex to Java, search strings for flags/keys - Native lib: same GDB/IDA on
.so
ELF/PE essentials
- ELF header magic
7f 45 4c 46; PE4d 5a(MZ) - Entry point: ELF
.entry, PEAddressOfEntryPoint - Sections to inspect:
.textcode,.rodatastrings,.bsszero-init data stringsoffset then find in disasm:info functions+x/20i <addr>
Ghidra quick-start commands (headless / script)
# GUI
File → Import File → OK → double-click → Analyze → Yes
# decompile: click function → press F5 (or Window → Decompile)
- Scripting:
analyzeHeadless <proj> <tmp> -import ./bin -scriptPath . -postScript ExportFuncs.java
Basic Rev-of-CTF checklist
- Strings → the flag/secret is usually there
- If encoded: base64/hex/xor — detect via look,
xxd, orradare2rar-ish enc - If function checks: load in GDB, run, feed input, single-step to cmp/jne, read compare value (often plaintext or adjacent in memory)
- If packed: packer detect → unpack → repeat
- If encrypted: find key material in data section and the crypto used (AES/RSA detect via imports)
Tools
- Free: Ghidra, rizin/radare2, gdb+pwndbg, objdump, readelf, hopper (trial), retdec (decompiler), cyberchef (decode kit)
- Paid: IDA Pro, Binary Ninja, Hopper, JEB (Android)
Tips
- Always
checksecbefore exploit-writing (NX/PIE/Canary/RELRO) - Note base address for PIE:
vmmap(GEF) orpwndbg— read adds base+offset - For 64-bit passes:
ROP,pop rdi; ret, ret2libc — craft withropper --search "pop rdi" - Cross-compile test objects with same libc:
pwninitorlibc-database find