Lesson 5 of 13 · 22m
A First Session in Ghidra
Import, auto-analyze, find main through __libc_start_main, rename and retype relentlessly, and script batch work through analyzeHeadless.
Ghidra won the tooling war by being free, scriptable, and within a few percent of the five-figure alternative on real work. The NSA released it at RSA in March 2019, and it's been the default first tool ever since — current releases (11.x) run on a bundled-or-system JDK 21. The learning curve is the interface, not the analysis. A working session has a rhythm; this is the one I teach new hires on day one.
Import and analyze
File → Import File, accept the detected format, run auto-analysis. The defaults are right for ordinary ELF and PE. Two options worth knowing up front: Decompiler Parameter ID (better argument recovery in pseudocode — turn it on) and the Function ID analyzer for statically-linked binaries (fingerprints known library functions so you stop reading libc). One thing to verify before spending an hour: the detected architecture. If Ghidra guessed ARM and file says MIPS, everything downstream is confident garbage.
The three views that matter
- Listing — the disassembly. Navigation lives here:
Gjumps to an address, double-click any label or function name to follow it, Alt+Left walks you back. - Decompiler — synchronized to the cursor. Click a line in the listing and the pseudocode for that region appears. You'll spend most of your time here — keep the listing open anyway, because the decompiler lies fluently (next lesson).
- Symbol Tree → Functions — every function Ghidra found:
entry,FUN_00001139, and occasionally real names it recovered.
The wrong mental model is "the GUI is the tool." The GUI is a viewer over a database — the program database — and every rename, retype, and comment you make is the analysis being saved. Work in it like a notebook, not a read-only window.
Finding main
In a dynamically-linked ELF, entry is _start — C runtime plumbing, not your code. It calls __libc_start_main, and the first argument is main:
lea rdi, [FUN_00001160] ; <- this is main, passed to libc
call __libc_start_mainDouble-click into FUN_00001160, read the decompilation, rename it main (L on the name). On Windows the same pattern applies — entry runs MSVC CRT startup (__scrt_common_main_seh → invoke_main), and main or WinMain is the function at the bottom of that chain. In a statically-linked ELF there's no __libc_start_main — the call site still exists, you just lose the import name; find the first call that takes a function pointer argument.
Rename and retype relentlessly
L renames, Ctrl+L retypes. This is not cosmetics — it is the analysis. FUN_00001139 renamed to parse_header makes every call site self-documenting; a parameter retyped from undefined8 to char * cleans up every dereference of it at once, everywhere it's referenced. Name by hypothesis — maybe_check_license is a perfectly good name — and rename when the hypothesis dies.
Script the boring parts
Batch triage across fifty samples doesn't happen in the GUI. The headless analyzer ships with every install:
$ ./support/analyzeHeadless ~/ghidra-projects triage \
-import ./samples/*.elf \
-scriptPath ./scripts -postScript DumpFunctions.java \
-deleteProjectSame analysis, no window, and your own script — here a twenty-line DumpFunctions.java that writes every function name and size to CSV — runs after each import. The Script Manager (Window → Script Manager) has hundreds of bundled examples to crib from, and the flat API (currentProgram.getFunctionManager(), getListing()) is the same one the GUI uses.
Field notes
- Ghidra projects are directories on disk. Save early; an unsaved session plus a JVM crash is a painful combination.
- The decompiler and the listing will occasionally disagree. The listing is the program; the decompiler is a translation (the next lesson covers when it misleads).
- Defined Strings (
Search → For Strings) is usually the real front door — the anchor loop in the lesson after that starts there, not atentry. - Ghidra's decompiler runs on an intermediate language (P-code), which is why one tool covers MIPS router firmware and x64 equally — the front end differs, the decompiler doesn't.
- Re-import beats re-analyze: auto-analysis results attach to the import. After you patch a file on disk, import it fresh rather than trusting a program database built from bytes that no longer exist.
Keep reading
Related articles from the SudoSecurity blog.
A Fake GTA 6 ISO Didn’t Install a Game. It Installed a Wiper.
A fake GTA 6 ISO used a believable installer error to cover remote-access malware, browser-data theft, and destructive file wiping. The “License not found” message wasn’t the crack failing. It was there so the victim would stop looking.
CVE-2025-62718: Critical Axios SSRF Vulnerability Explained
A critical SSRF flaw in Axios was used in a North Korean supply chain attack. Here's what it does and how to patch it today.
Hacktivism, 2021 to Today: From Steel Mills to Power Grids
Part 1 ended on a 70-gigabyte breach in 2021. Since then, hacktivists derailed trains, dumped molten steel on camera, and reached grids in three countries.
What is an Infostealer?
Infostealers are commodity malware that silently harvest credentials, session tokens, and crypto wallets from infected machines. The Lumma Stealer infection that triggered the Vercel breach started with one. Here is how they work and why they are so effective.