Reverse Engineering for Beginners: Learn to Analyze Binaries with Ghidra & GDB
Learn reverse engineering from scratch: analyze binaries with Ghidra and GDB, read assembly, crack a practice binary, and build a starter toolkit.
What Is Reverse Engineering?
Reverse engineering is the process of examining a finished program to understand how it works without relying on its original design documents or source code. Beginners usually inspect binary structure, strings, assembly, and runtime behavior with tools such as Ghidra and GDB, using only software they own or are authorized to analyze.
A compiler converts source code into machine instructions, metadata, and data that a processor can execute. Reverse engineering works in the opposite direction: you study those artifacts and infer the program's logic, inputs, outputs, and internal decisions. A decompiler can make this easier, but it cannot restore the exact original source code, comments, or variable names.
Common authorized uses include:
Reverse engineering is not automatic source-code recovery, permission to bypass access controls, or authorization to inspect any program you can download. It also does not guarantee that a decompiler's output is correct.
Is Reverse Engineering Legal?
Reverse engineering laws vary by country and purpose. The safest beginner projects are binaries you compiled yourself, CTF challenges, and crackmes whose authors explicitly permit analysis.
Before analyzing someone else's software, check:
A clean-room project normally separates the team documenting observable behavior from the team implementing a compatible replacement. This can reduce the risk of copying protected expression, but it does not automatically override contracts, patents, or local law.
This guide is educational, not legal advice. Do not use it against commercial software, production systems, or binaries you do not own unless you have explicit permission.
How Reverse Engineering Works: Static vs Dynamic Analysis
Static analysis examines a file without running it. Dynamic analysis observes the program while it executes. Effective reverse engineering usually alternates between both.
| Question | Static analysis | Dynamic analysis |
|---|---|---|
| Is the program executed? | No | Yes |
| Typical evidence | Headers, strings, imports, functions, assembly, decompiled code | Registers, memory, function arguments, files, system calls, network activity |
| Main tools | Ghidra, objdump, strings, readelf, nm, radare2 | GDB, strace, ltrace |
| Strength | Broad overview of possible behavior | Confirms what happens on a specific execution path |
| Limitation | A code path may never run | One run may miss other paths |
| Main risk | Parsing a malicious file can still expose tool flaws | Running untrusted code can affect the system |
Start with static analysis to identify the architecture, file type, strings, imports, and likely functions. Use dynamic analysis to test specific hypotheses, such as whether a comparison controls an "Access granted" branch.
Only execute self-compiled or explicitly authorized binaries. Unknown binaries should be treated as untrusted and handled in an isolated lab by someone prepared to contain them.
The Skills You Need First
You do not need to master every prerequisite before beginning, but four foundations make reverse engineering for beginners much easier.
C basics
Learn how C represents:
if, else, and loop control flowstrcmp, puts, and mallocCompiling your own short C programs is one of the fastest ways to connect source constructs to assembly.
x86-64 assembly essentials
For this tutorial, focus on Linux's x86-64 System V calling convention:
rdi, rsi, rdx, rcx, r8, and r9.rax.rsp tracks the top of the stack.rip identifies the next instruction.call transfers control to a function and records a return address.ret returns to the caller.You do not need to memorize every instruction. Learn to recognize data movement, comparisons, branches, function calls, and returns.
Linux command-line skills
Be comfortable with paths, permissions, pipes, redirection, grep, less, and basic process control. You should understand commands such as:
file ./practice
strings ./practice | less
objdump -d ./practice | less
printf 'wrong\n' | ./practice
ELF binary structure
Most native Linux programs use the Executable and Linkable Format, or ELF. Important components include:
.text: executable machine instructions.rodata: read-only constants such as string literals.data: initialized writable global data.bss: zero-initialized global data.symtab: a full symbol table when it has not been stripped.dynsym: symbols needed for dynamic linkingSymbols help tools display names such as main, but the processor does not need those names. Stripping symbols removes useful labels, not the underlying instructions.
Your Reverse Engineering Toolkit
| Tool | Primary purpose |
|---|---|
| Ghidra | Disassembly, decompilation, function analysis, cross-references, data types, and annotations |
| GDB | Breakpoints, instruction stepping, registers, memory inspection, and temporary runtime modification |
| objdump | Terminal-based disassembly and section inspection |
| strings | Extracts printable character sequences from a file |
| readelf | Displays ELF headers, sections, symbols, relocations, and program headers |
| nm | Lists symbols, including undefined imported functions |
| strace | Traces Linux system calls such as openat, read, execve, and connect |
| ltrace | Traces many dynamically linked library calls |
| radare2 | Terminal-based analysis, disassembly, graphing, and debugging |
| checksec | Reports common hardening properties such as PIE, NX, canaries, and RELRO |
| xxd | Displays raw file bytes in hexadecimal |
GEF and Pwndbg are optional GDB enhancements that add context views and convenience commands. Plain GDB is enough for this guide. Install extensions only from their official projects and only in your isolated lab.
Tools do not create legal authorization. Use them only on your own binaries, authorized exercises, and explicitly permitted targets.
Setting Up Your Lab in Kali Linux
Use a Kali Linux virtual machine with no sensitive credentials or personal files. Take a snapshot before working with downloaded crackmes, and keep networking disabled unless a specific authorized exercise requires it.
This tutorial assumes an x86-64 system. Confirm the architecture:
uname -m
Install the required packages:
sudo apt update
sudo apt install -y ghidra gdb binutils gcc libc6-dev file strace ltrace checksec xxd
Verify the installed packages and versions:
apt-cache policy ghidra | grep -E 'Installed|Candidate'
gdb --version | head -n 1
gcc --version | head -n 1
objdump --version | head -n 1
Create a dedicated directory:
mkdir -p ~/re-lab
cd ~/re-lab
Create the practice program:
cat > practice.c <<'EOF'
#include <stdio.h>
#include <string.h>
int check_password(const char *input)
{
const char *secret = "orbit-lemur-42";
return strcmp(input, secret) == 0;
}
int main(void)
{
char input[64];
printf("Enter password: ");
if (scanf("%63s", input) != 1) {
puts("Input error.");
return 1;
}
if (check_password(input)) {
puts("Access granted.");
} else {
puts("Access denied.");
}
return 0;
}
EOF
Compile it:
gcc -g -O0 -fno-stack-protector -no-pie -Wall -Wextra -o practice practice.c
The flags deliberately make this educational binary easier to inspect:
-g includes debugging information.-O0 minimizes compiler optimization.-fno-stack-protector disables the stack canary.-no-pie gives the executable a non-PIE layout.Do not copy these weakened settings into production software. The bounded scanf prevents this example from becoming a buffer-overflow exercise.
Confirm the result:
file ./practice
checksec --file=./practice
./practice
Launch Ghidra when needed:
ghidra
Reading Assembly: A 10-Minute Crash Course
Assembly represents the instructions executed by the processor. GDB and objdump can display Intel syntax, where the destination usually appears before the source.
Core registers
| Register | Common role |
|---|---|
rax | Return value and general calculations |
rbx | General-purpose, callee-saved register |
rcx | Fourth function argument and general-purpose register |
rdx | Third function argument and arithmetic data |
rsi | Second function argument |
rdi | First function argument |
rsp | Stack pointer |
rbp | Optional stack-frame base pointer |
rip | Instruction pointer |
The 32-bit lower part of rax is eax. Writing to eax also clears the upper half of rax.
Instructions to recognize
mov destination, source: copies datalea destination, source: calculates an addresscmp left, right: compares values by setting flagstest left, right: performs a bitwise test and sets flagsjmp address: unconditional branchje or jz: jump when equal or zerojne or jnz: jump when not equal or not zerocall function: calls another functionret: returns to the saved addresspush and pop: add or remove values from the stackA simplified control-flow fragment might look like this:
; Illustrative Intel syntax
push rbp
mov rbp, rsp
call check_password
cmp eax, 0
je denied
lea rdi, [rip + granted_message]
call puts
jmp done
denied:
lea rdi, [rip + denied_message]
call puts
done:
pop rbp
ret
check_password returns its result in eax. The comparison sets processor flags. je denied follows the failure branch when the return value is zero.
A traditional stack frame begins with:
push rbp
mov rbp, rsp
sub rsp, 0x40
That reserves local stack space. Modern optimized programs may omit rbp, keep variables in registers, combine operations, or inline entire functions. That is why beginner labs should start with -O0.
Worked Example: Cracking a Practice Binary
This walkthrough applies only to the self-compiled practice binary. "Cracking" here means solving an intentionally weak lab challenge, not bypassing a real product's licensing or authentication.
Addresses and displayed disassembly vary by GCC, library, and Kali version. Outputs below are labeled illustrative; use the addresses and instructions shown on your own system.
1. Observe normal behavior
Run the program and enter an incorrect value:
$ ./practice
Enter password: wrong
Access denied.
This establishes the behavior you want to explain.
2. Perform quick static triage
Inspect the file and ELF header:
file ./practice
readelf -h ./practice
checksec --file=./practice
Search its printable strings:
strings -a -n 5 ./practice | grep -E 'password|Access|orbit'
Illustrative output:
orbit-lemur-42
Enter password:
Access granted.
Access denied.
The password is visible because the program stores it as an ordinary string literal. Finding a string is a clue, not proof of how it is used. You still need to locate its references and the controlling comparison.
3. Inspect the disassembly
List the function symbol:
nm ./practice | grep check_password
Disassemble that function using Intel syntax:
objdump -d -M intel --disassemble=check_password ./practice
An illustrative sequence will resemble:
mov rax, QWORD PTR [rbp-0x18] ; the entered string (first argument)
lea rdx, [rip+...] ; address of "orbit-lemur-42"
mov rsi, rdx ; second argument: expected string
mov rdi, rax ; first argument: entered string
call strcmp@plt
test eax, eax
sete al
movzx eax, al
ret
strcmp returns zero when two strings match. The compiler converts that result into the Boolean value returned by check_password.
Review the wider program when needed:
objdump -d -M intel ./practice | less
4. Confirm the logic in Ghidra
Start Ghidra:
ghidra
Create a non-shared project, import ~/re-lab/practice, accept the detected ELF format, and run the default analysis. Open check_password from Symbol Tree > Functions.
The decompiler should show logic similar to this illustrative pseudocode:
int check_password(char *input)
{
return strcmp(input, "orbit-lemur-42") == 0;
}
Select the password string and display its references. One reference should lead back to check_password. Then inspect main and follow the call to see how its return value selects the granted or denied message.
5. Override the return value in GDB
Start GDB:
gdb ./practice
Use the following commands:
(gdb) set disassembly-flavor intel
(gdb) info functions
(gdb) break main
(gdb) break check_password
(gdb) run
GDB first stops at main. Continue, then enter an incorrect password:
(gdb) continue
Enter password: wrong
Breakpoint 2, check_password (...)
On x86-64 Linux, the first pointer argument is in rdi:
(gdb) x/s $rdi
Illustrative output:
0x7fffffffe000: "wrong"
You can inspect instructions or execute one instruction at a time:
(gdb) disassemble check_password
(gdb) x/10i $rip
(gdb) stepi
Restart the session if needed, stop at check_password, and let the function finish:
(gdb) finish
GDB should stop in main immediately after the call. The incorrect comparison normally returned zero in rax. Change that transient return value:
(gdb) set $rax = 1
(gdb) continue
Illustrative result:
Access granted.
This is a runtime state patch. It changes only the current process; it does not modify practice on disk.
An alternative is to run disassemble main, identify the first instruction of the granted block, stop at the conditional branch, and use:
(gdb) jump *ADDRESS_OF_GRANTED_BLOCK
Replace the placeholder with the address from your current GDB session. Never copy an address from another build. Jumping into the middle of a block can corrupt stack or register state, so use this only in your disposable practice program.
Static Analysis with Ghidra
This section provides a compact Ghidra tutorial for repeating the workflow on your own binaries.
ghidra and create a non-shared project.For an unstripped practice binary, find main and check_password under Symbol Tree > Functions. Selecting a function synchronizes the Listing and Decompiler windows.
Useful analysis habits include:
Access granted or the password through Search > For Strings.X to view cross-references.Decompiler output is an informed reconstruction, not original source. If the C-like output appears suspicious, trust the instructions and observed runtime behavior over an attractive pseudocode guess.
Dynamic Analysis with GDB
GDB lets you stop a process at a specific instruction and inspect its live state.
A useful session for the practice program is:
$ gdb ./practice
(gdb) set disassembly-flavor intel
(gdb) set pagination off
(gdb) break check_password
(gdb) run
Enter password: wrong
(gdb) info registers
(gdb) x/10i $rip
(gdb) x/s $rdi
To watch the two strings reach strcmp, set another breakpoint while stopped in check_password:
(gdb) break strcmp
(gdb) continue
(gdb) x/s $rdi
(gdb) x/s $rsi
The first string should be the entered input and the second should be the expected password. Exact breakpoint names and addresses can differ because system libraries may use optimized strcmp implementations.
Important stepping commands are:
step: enter the next source-level operation when debug information existsnext: execute the next source line without entering called functionsstepi: execute one machine instructionnexti: execute one machine instruction while stepping over callsfinish: continue until the current function returnscontinue: resume until another breakpoint or signalWhen a program crashes, use info registers, x/i $rip, and backtrace before changing anything. Record the input, arguments, environment, and last successful instruction so the result can be reproduced.
Finding Hidden Behavior: Strings, Imports and Network Calls
Begin with a focused strings search:
strings -a -n 5 ./practice | grep -Ei 'http|socket|token|password|/etc/|\.so'
Strings can reveal paths, domains, commands, error messages, and configuration keys. They can also be unused, encoded, constructed at runtime, or deliberately misleading.
Inspect relocations and dynamic symbols:
readelf -r ./practice
nm -D ./practice
Search for functions associated with files, processes, or networking:
nm -D ./practice | grep -E 'open|fopen|exec|system|socket|connect|getaddrinfo|send|recv'
An imported function indicates capability, not confirmed behavior. Observe execution to determine whether a path actually calls it.
Trace the authorized practice binary:
printf 'wrong\n' | ltrace -f -o ltrace.log ./practice
printf 'wrong\n' | strace -f -o strace.log ./practice
Review potentially significant system calls:
grep -E 'openat|execve|socket|connect|sendto|recvfrom' strace.log
ltrace focuses on many library calls, while strace records system calls crossing into the kernel. Neither tool reveals every possible path from one execution.
Common Binary Protections and How to Recognize Them
Use file, checksec, readelf, Ghidra, and controlled execution to identify likely complications.
| Protection or complication | Recognition | Beginner response |
|---|---|---|
| Stripped symbols | file reports "stripped", or nm reports no symbols | Use strings, imports, cross-references, and control flow; obtain an authorized debug build when possible |
| PIE and ASLR | checksec reports PIE; runtime addresses move | Use symbolic breakpoints, module-relative offsets, and addresses from the current run |
| NX, canaries, and RELRO | Reported by checksec | Treat them as hardening context; they do not prevent ordinary reading or debugging |
| Compiler optimization | Variables disappear, functions are inlined, and control flow changes | Compare an -O0 build with an -O2 build of your own source |
| UPX packing | UPX markers, unusual sections, or successful upx -t test | Work on a copy and use upx -d only when authorized |
| Anti-debugging | Checks involving ptrace, timing, signals, or /proc/self/status | Document the check first; practice on purpose-built labs rather than real software |
| Obfuscation | Excessive indirect branches, opaque conditions, encoded strings, or confusing dispatch loops | Isolate one function at a time and combine static and dynamic evidence |
For an authorized UPX sample, preserve the original and unpack a copy:
cp authorized-sample authorized-sample.work
upx -t authorized-sample.work
upx -d authorized-sample.work
A beginner should not expect to defeat custom packers, advanced virtualization, kernel anti-debugging, or sophisticated obfuscation immediately. Build fluency on simple, self-compiled programs first.
Reverse Engineering vs Malware Analysis vs Debugging
| Discipline | Primary goal | Typical starting point | Typical tools |
|---|---|---|---|
| Reverse engineering | Understand a finished program's design and logic | A binary, firmware image, or file format | Ghidra, GDB, objdump, radare2 |
| Malware analysis | Determine the capabilities and impact of suspected malicious code | An untrusted sample handled under strict containment | Static tools, debuggers, tracers, sandboxes |
| Debugging | Find why a program behaves incorrectly | A reproducible defect, often with source code | GDB, logs, sanitizers, source-level debuggers |
The activities overlap. Malware analysis uses reverse engineering, while reverse engineering often uses debugging techniques. The main differences are the objective, authorization, and risk of execution.
Practice Path: Crackmes and CTFs
After mastering your own program, use purpose-built challenges from crackmes.one. Select beginner-level entries, read each author's terms, and treat every downloaded file as untrusted even when it is presented as a challenge.
TryHackMe and Hack The Box also provide authorized training environments. Stay inside each platform's stated scope and do not transfer techniques to unrelated systems.
| Week | Focus | Practice |
|---|---|---|
| 1 | C and ELF fundamentals | Compile small programs with conditions, loops, and string comparisons; inspect them with file, readelf, strings, and objdump |
| 2 | Ghidra workflow | Find main, rename functions, follow string references, and compare decompiled output with source you wrote |
| 3 | GDB workflow | Break on functions, inspect arguments, step through branches, and compare registers before and after calls |
| 4 | Authorized challenges | Solve simple crackmes without reading solutions first; document every conclusion and verify it dynamically |
Compile both optimized and unoptimized versions of your own code:
gcc -g -O0 -o example-O0 example.c
gcc -g -O2 -o example-O2 example.c
Comparing them demonstrates why real binaries rarely resemble their original source exactly.
Reverse Engineering Cheat Sheet
Tool commands
| Tool | Command | What it shows |
|---|---|---|
| file | file ./practice | File type, architecture, linking, and stripped status |
| readelf | readelf -h ./practice | ELF header and entry-point information |
| strings | strings -a -n 5 ./practice | Printable sequences of at least five characters |
| objdump | objdump -d -M intel ./practice | Intel-syntax disassembly |
| nm | nm ./practice | Symbols from an unstripped binary |
| nm | nm -D ./practice | Dynamic symbols and imports |
| xxd | xxd -g 1 -l 64 ./practice | First 64 bytes in hexadecimal |
| checksec | checksec --file=./practice | Common binary hardening properties |
| ltrace | ltrace ./practice | Many dynamic library calls |
| strace | strace -f ./practice | System calls, signals, and child processes |
| Ghidra | ghidra | Launches the graphical analysis suite |
| GDB | gdb ./practice | Starts a debugging session |
| radare2 | r2 -A ./practice | Opens the binary and runs automatic analysis |
GDB commands
| Command | Purpose |
|---|---|
info functions | Lists known functions |
break main | Sets a breakpoint at main |
break *0xADDRESS | Breaks at a specific current-session address |
run | Starts the program |
continue | Resumes execution |
step / next | Source-level step into or over |
stepi / nexti | Instruction-level step into or over |
disassemble main | Displays a function's instructions |
info registers | Displays register values |
x/10i $rip | Shows ten instructions at the instruction pointer |
x/s $rdi | Treats the address in rdi as a C string |
x/32bx ADDRESS | Displays 32 individual bytes |
backtrace | Displays the current call stack |
finish | Runs until the current function returns |
set $rax = 1 | Changes the x86-64 return register for the current process |
quit | Ends the debugging session |
Troubleshooting Reverse Engineering Problems
| Problem | Likely cause and response |
|---|---|
| Ghidra won't start or reports a Java error | Run it from a terminal to read the error, check java -version, and reinstall the packaged dependencies with sudo apt install --reinstall ghidra. Use the Java version required by the installed Ghidra package. |
| The binary is stripped | Function names and debug metadata were removed. Start from imports, strings, entry points, cross-references, and recognizable library-call patterns. |
nm reports no symbols | Try nm -D for dynamic symbols. A fully static stripped binary may expose very few names, so use Ghidra's function discovery and control-flow analysis. |
| GDB says "no debugging symbols found" | Assembly debugging still works. For your own program, rebuild with -g -O0 to restore source lines, types, and local-variable information. |
| PIE or ASLR makes addresses change | Use function names and addresses from the current run. For your own lab, set disable-randomization on can help, but symbolic breakpoints are more portable. |
| The program crashes under GDB | Confirm arguments, input, working directory, environment, and signals. Use backtrace, info registers, and x/i $rip before applying patches. |
| Ghidra's decompiler output is unreadable | Confirm the architecture, rerun analysis, inspect assembly, apply accurate types, rename proven concepts, and analyze smaller functions first. |
| The binary appears UPX-packed | Test only an authorized copy with upx -t, preserve the original, and use upx -d if the format is supported. Custom packers require more advanced analysis. |
Common Mistakes Beginners Make
-O0 programs and authorized crackmes.Best Practices
sha256sum before modifying copies.Summary
Reverse engineering combines binary structure, C concepts, assembly, static analysis, and runtime observation. Start with a program you compiled yourself, use strings and imports to form hypotheses, inspect the logic in Ghidra, and confirm it with GDB.
The essential learning loop is simple: observe, hypothesize, test, document, and repeat. Once that workflow is comfortable, progress to beginner crackmes and authorized CTF environments instead of real commercial software.
Knowledge Check
-g and -O0 do when compiling a practice binary?rax to 1 change the result in the practice program?Answers: 1. Static analysis does not run the binary; dynamic analysis observes an execution. 2. rdi. 3. .text. 4. It may be unused, unreachable, or misleading. 5. -g adds debug information and -O0 minimizes optimization. 6. nm -D ./binary. 7. rax held the x86-64 integer return value tested by main. 8. Explicit permission that covers the planned analysis.
Keep Learning
Frequently Asked Questions
Continue Learning
Malware Analysis: Beginner's Guide to Static & Dynamic Analysis in Kali Linux
Learn malware analysis from scratch: build a safe isolated lab, triage samples with static and dynamic analysis, write YARA rules, and report IOCs.
Ethical Hacking · BeginnerSteganography Tools: Best Free Tools to Hide & Detect Hidden Data in Kali Linux
Learn the best free steganography tools for Kali Linux: hide files in images with Steghide and OpenStego, then detect hidden data with zsteg.
Ethical Hacking · IntermediateCloud Penetration Testing: Complete Guide to AWS, Azure and GCP Security Testing
Cloud penetration testing for AWS, Azure, and GCP: the 6-phase methodology, IAM analysis, chained attack paths, and tools — with a worked lab example.
Ethical Hacking · BeginnerEthical Hacking Fundamentals: Principles, Methodology, and Best Practices
Learn the core principles of ethical hacking, the five-phase penetration testing methodology, types of security testing, and how to build your own hacking lab.
Related Security Tools
GDB
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.
Reverse EngineeringGhidra
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 EngineeringFrida
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 EngineeringObjection
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.