Reverse Engineering
Learn how to use GDB, the GNU Debugger, by building a small C program with debug symbols and following it from the first breakpoint to a crash. Use the same steps to inspect variables, read a backtrace, and tell when a core dump or a look at the assembly would help.
sudo apt update && sudo apt install gdb -y
gdb [options] <binary>
To use GDB, compile your program with `-g` to include debugging symbols, then open it with `gdb ./program`. Enter `break main` and `run` to pause at the start of your code. Use `step` to move through it and `print` to inspect variables. If it crashes, use `backtrace` to see the calls that led there.
Start in your terminal: install GDB, compile your program with `-g`, and open the executable you just built. The name after `gdb` is the executable, not the source file. Once it loads, type debugging commands at the GDB prompt rather than in your shell. Set a breakpoint somewhere you recognize, such as `main`, and run to that point. When GDB shows a source line at a breakpoint, read it as the line about to run, not as proof that the assignment on that line has happened. Predict what the next statement will do, step once, and check the result with `print`. Use `next` to run a call without stepping into it, or `step` when you need to follow the call. If the program crashes, read the backtrace before restarting so you know where it stopped. Fix the cause in the source, rebuild with `-g`, and test the same case again. In the lab below, the write needs a pointer to a valid, writable `int`; restarting with the same code will not fix it.
Save these eight lines as `crash.c`, with the include on line 1 so the recorded line numbers match: #include <stdio.h> int main() { int *p = NULL; printf("Before crash\n"); *p = 42; printf("After crash\n"); return 0; } Build it with `gcc -g -o crash crash.c`, then open `gdb ./crash`. To watch the crash develop, enter `break main` before `run`, then use `continue` after the breakpoint hits. At the fault, enter `bt`. These are the relevant lines from the recorded run, including the backtrace frame: Program received signal SIGSEGV, Segmentation fault. 0x0000555555555170 in main () at crash.c:5 5 *p = 42; #0 0x0000555555555170 in main () at crash.c:5 Read from the top: `SIGSEGV` tells you the program attempted an invalid memory access. The next line puts the stopped instruction in `main` at line 5 of `crash.c`, and the displayed source line shows the write it tried to perform. `#0` is the innermost stack frame, where execution stopped, not a second crash. Now check the destination: `print p` gave `$1 = (int *) 0x0`. The pointer is null, so there is no `int` at the destination that this program can write to. The program never reaches the line that prints `After crash`. Use `list` to see the surrounding source. The instruction address may differ in your run; compare the function, line, and pointer value rather than the exact address.
On Kali Linux, install GDB with `sudo apt update && sudo apt install gdb -y`. The first part refreshes the package index; the second installs the debugger. Ubuntu and Debian use the same APT command. Run `gdb --version` in the shell to check that GDB starts. The Ubuntu 24.04 test machine reported `GNU gdb (Ubuntu 15.1-1ubuntu1~24.04.1) 15.1`; your version does not need to match that output for this lab. On macOS, use `brew install gdb`. GDB needs code-signing for full use on macOS, so a successful install does not by itself mean it can control a process. On Windows, use MinGW/MSYS2 or work inside a Linux distribution under WSL. Build and debug the example in the same environment so you open the executable you meant to test. On Kali, `sudo apt install gdb-multiarch` adds a debugger that supports multiple architectures. It is not an emulator and does not make a binary for another architecture runnable on your machine. The native crash lab only needs ordinary GDB.
Choose a stop based on what you need to learn. A breakpoint such as `break main` stops when execution reaches a location. Use `info breakpoints` to check each stop's number, location, and enabled state. A watchpoint such as `watch p` stops when the watched value changes. Set it while `p` is in scope, and do not expect it to stop just because another statement reads or dereferences `p`. In the lab, nothing changes the pointer after it is initialized to null. A conditional breakpoint checks a test at a particular location: `break crash.c:5 if p == 0` stops before the write on line 5 only if `p` is null. Set it before reaching line 5 on the run you want to check. If you go back to the beginning, remember that a watchpoint on a local variable can go away when that variable leaves scope. A catchpoint stops for an event rather than a source location or a value change. On a supported Linux target, `catch syscall open` catches entry to and return from that named system call, not every way a program can open a file. You do not need a catchpoint for the null-pointer crash.
Start with plain GDB for the crash lab, then try one plugin if you want to see more of the program's state at each stop. GEF is a good first choice if you want to see the registers, stack, and current instructions together. It needs GDB 7.7 or newer with Python support; its installer is `bash -c "$(curl -fsSL https://gef.blah.cat/sh)"`. PEDA is an older extension with a compact register, stack, and disassembly display. It is useful when following a lab that already uses PEDA. Set it up with `git clone https://github.com/longld/peda.git ~/peda` followed by `echo "source ~/peda/peda.py" >> ~/.gdbinit`. PwnDbg also shows context at each stop and offers more ways to inspect memory. It needs GDB 12.1 or newer and Python 3.10 or newer; its installer is `curl --proto '=https' --tlsv1.2 -LsSf 'https://install.pwndbg.re' | sh -s -- -t pwndbg-gdb`. Load only one plugin at a time so you know which one provides a given view or command. Review third-party code before running an installer or adding it to your GDB startup file.
When you have authorization to reverse engineer a binary but do not have its source, ask the same questions: where did execution stop, and what was the program doing there? If GDB recognizes the function name, `disassemble main` shows its machine instructions. At a stop, `x/10i $pc` shows ten instructions starting at the program counter, while `x/4xw $sp` shows four words at the stack pointer in hexadecimal. One decodes instructions; the other shows raw data. To keep a code pane visible in the terminal, start with `gdb -tui ./program` or toggle TUI with Ctrl-X A. Use `layout asm` for instructions or `layout src` when source is available. In an authorized CTF practice lab, you can take a function you identified at a GDB stop into Ghidra to read the surrounding code. If you already use pwntools as a local test harness, keep the normal test input the same and use GDB to see where that run stops. Only debug programs you own or have explicit permission to analyze. Keep unfamiliar binaries in an isolated VM, and never debug an untrusted binary on a host you care about.
If the operating system saved a core dump, open it with `gdb ./program core` using the exact executable build that crashed, then run `bt` inside GDB. This is post-mortem debugging: you can inspect the saved state, but you cannot step forward through that run. Where permitted, the standard setup is `ulimit -c unlimited` in the shell before running the crashing program from that shell. The test VM blocked that limit change and did not produce a local core file. If no dump was saved, reproduce the crash in a live GDB session instead. To inspect a running local process you control, use `gdb -p 1234` with its actual PID; attaching pauses the process. For remote debugging on systems you control, start the separate program `gdbserver :1234 ./program` on the target, then connect from GDB with `target remote <target-ip>:1234`. Keep the connection inside your isolated lab. Once you find the function or instruction that explains the stop, take it to Ghidra, Radare2, or Objdump to study that part of the binary without running it again.
Start with one question: which line is about to run, and what value will it use? If the lab stops at line 3, check the reason before you assume it failed. That first stop is the breakpoint you set, not a segmentation fault. Use `next` to get past the pointer initialization before you inspect `p`. A null pointer can exist without crashing the program; the attempted write on line 5 is what causes the fault. In a larger program, follow the bad value back to where it was assigned or passed into the function. If you do not have the source, use Ghidra for static analysis to see where a function is called, then return to GDB to check which path your test run took.
If GDB cannot show a source line or `print p` cannot find the variable, check the build and the selected frame before changing tools. Make sure you compiled with `-g` and loaded that executable, not a copy from an older build. Try `list` when you expect source: even if the binary contains line information, GDB still needs the source file to show its contents. If the source is visible but `p` is missing, confirm that the selected frame is in `main`. Use `info locals` to inspect the locals in that frame, or `info args` to check the function arguments. For terminal-based static work, use Radare2 for CLI analysis to read the code separately, then use GDB to confirm what happened during the run.
Keep a short record of the executable build, the input, the reason GDB stopped, and the values you found. If there is no source, note the instruction and the function when GDB can name it. Use Objdump for static disassembly to see which instructions are in the file. If the file and the live session show different absolute addresses, compare the function offset or the surrounding instructions rather than assuming the address numbers must agree. After fixing a source bug, rebuild and retry the same case. Check that the program reaches the code it missed before, not just that the original error message went away. For `crash.c`, that means checking that execution gets past the write to the statement that prints `After crash`.
| Command | Purpose |
|---|---|
gdb <program> | Load executable symbols without starting the program. |
gdb <program> <core-file> | Perform post-mortem debugging. |
break <function> | Set a breakpoint at a function. |
backtrace | Print the current stack trace. |
gdb ./programLoad an executable into GDB for debugginggdb --args ./program arg1 arg2Load a program together with its command-line argumentsgdb -p 1234Attach GDB to an already running process by PIDgdb ./program coreDebug a program using a saved core dump filegdb -q ./programStart GDB quietly, suppressing the banner textgdb -batch -ex run -ex bt ./programRun scripted commands non-interactively then exitrunStart execution of the loaded program (alias: r)break mainSet a breakpoint at the function main (alias: b)break file.c:42Set a breakpoint at a specific source file and linecontinueResume execution until the next breakpoint (alias: c)nextStep over the next source line without entering calls (alias: n)stepStep into the next source line, entering function calls (alias: s)stepiStep a single machine instruction (alias: si)finishRun until the current function returnsbacktracePrint the current call stack (alias: bt)info registersDisplay the contents of all CPU registersprint variableEvaluate and print an expression or variable (alias: p)x/16xw $spExamine 16 words of memory in hex starting at the stack pointerdisassemble mainShow the assembly for a function (alias: disas)watch variableSet a hardware watchpoint that stops when a value changesset var x = 5Modify the value of a variable during executioninfo breakpointsList all defined breakpoints and their hit countslayout asmOpen the TUI assembly view alongside the command windowquitExit GDB, detaching from any attached process (alias: q)info argsShow the arguments of the function in the selected stack frame.info localsShow the local variables in the selected stack frame.x/10i $pcDisplay ten instructions starting at the current program counter.catch syscall openStop on entry to and return from the open system call on supported targets.tbreak mainSet a breakpoint at main that GDB removes after the first hit.disable 1Turn off breakpoint number 1 without deleting it.attach 1234Attach the current GDB session to the running local process with PID 1234 and pause it.target remote :1234Connect GDB to a remote debugging stub reachable on local TCP port 1234.Debug segmentation faults and crashes.
Analyze malware behavior at runtime.
Develop and test exploits with PEDA/GEF.
Step through compiled code to understand logic.
Find the crashing line in minutes with a backtrace, then inspect the values used on that line to check the cause.
For the debugging part of an authorized CTF exercise, pause a practice binary at a breakpoint and use GEF or PwnDbg to inspect memory and diagnose a crash.
Reverse Engineering
This hands-on guide shows how to use Ghidra to inspect a program you compile yourself. You'll compare decompiled code with the underlying assembly, follow cross-references, and document what the binary does without executing it.
Reverse Engineering
Radare2 (r2) is a complete open-source framework for reverse engineering and binary analysis. It bundles a disassembler, debugger, hex editor, and scripting engine into a single lightweight command-line toolkit that supports dozens of architectures and executable formats.
Reverse Engineering
objdump displays information about object files. It can disassemble executables, show headers, symbols, and more.
Reverse Engineering
Objection is a runtime mobile exploration toolkit, powered by Frida, built to help you assess the security of your mobile applications without needing a jailbroken or rooted device.
Reverse Engineering
Frida is a dynamic instrumentation toolkit for developers, reverse-engineers, and security researchers. It allows you to inject snippets of JavaScript or your own library into native apps on various platforms — making it the industry standard for runtime analysis and mobile app security testing.
Reverse Engineering
strings prints the sequences of printable characters in files. Useful for finding hidden text, URLs, and clues in binaries.
Learn reverse engineering from scratch: analyze binaries with Ghidra and GDB, read assembly, crack a practice binary, and build a starter toolkit.
Security Operations · AdvancedLearn detection engineering principles including rule development, Sigma rules, testing methodologies, false positive management, and building a detection program for security operations.
Tools · BeginnerLearn how to use Dirb in Kali Linux: run your first directory scan, pick the right wordlist, and read the results — with a worked example and cheat sheet.
OSINT · BeginnerLearn how to use whois in Kali Linux: look up any domain, IP or AS number, read the record, and spot red flags — with a worked example and cheat sheet.
`Program received signal SIGSEGV, Segmentation fault.` tells you the program attempted an invalid memory access, but not which value caused it. The next line, `0x0000555555555170 in main () at crash.c:5`, maps the stopped instruction to line 5 of `crash.c`, where the code tries to execute `*p = 42;`. The number at the front is the instruction's address, not the address it tried to write to. In `bt`, `#0 0x0000555555555170 in main () at crash.c:5` is the innermost stack frame. It repeats where execution stopped rather than reporting a second fault. `print p` returns `$1 = (int *) 0x0`: `$1` labels the printed result, `(int *)` is the pointer type, and `0x0` tells you the pointer is null. In `info registers`, `rip` is `0x555555555170 <main+39>`, the same instruction address without the leading zeros, 39 bytes from the start of `main`. Read the two values separately: `rip` tells you where the processor stopped, while `p` tells you why the write on that line could not succeed.
This tool is designed for authorized security testing, educational purposes, and legitimate network administration only. Unauthorized access to computer systems is illegal.