Firmware reverse engineering with AI: extraction, Ghidra and QEMU
A practical firmware workflow with an AI agent — binwalk and unblob extraction, identifying the architecture and filesystem, finding the binaries and configs worth reading, loading them into Ghidra with the right processor, and running one binary under QEMU user mode.
· 8 min read

Firmware reverse engineering is mostly unglamorous work before the interesting part: carve the image apart, figure out what CPU it's for, find the one web server or update daemon that matters among hundreds of BusyBox symlinks, and get a disassembler to agree on the instruction set. An AI agent is genuinely good at that part. It runs the extraction tools, reads their noisy output, walks a filesystem faster than you can, and writes the small scripts every image seems to need. It's worse at the last mile — trusting a decompiler on an unfamiliar architecture — and that's where you stay in charge.
This guide walks the workflow with standard open tools. Use firmware you own (your router, your camera, a dev board) or a public image downloaded from the vendor's support site. Analysing a device you own is one thing; testing anyone else's deployed device or service is not, without their permission.
The short version: let the agent run the tools and keep notes, and make it prove each claim from the bytes. Firmware is where confident guesses are most expensive, because the architecture, endianness and load address all have to be right before anything downstream means anything.
What the agent is good at here
- Driving extraction. Running binwalk or unblob, reading the signature output, and retrying when a nested archive or an odd compression gets in the way.
- Walking the filesystem. Listing init scripts, finding which daemons start at boot, spotting hard-coded credentials files, certificates and keys, and noticing the vendor's own binaries among stock BusyBox.
- Writing glue. A script to carve a section at an offset, decompress a vendor-specific container, or batch-run
fileandstringsover a whole tree. - Annotating decompiled code. Naming functions in a stripped binary from the strings they reference, and recognizing library code (OpenSSL, a JSON parser, CGI handling).
Where it misleads
- Architecture and endianness. A model will happily read MIPS big-endian as little-endian if nobody checks. Everything after that is noise.
- Load addresses. For a raw bootloader or RTOS blob there's no ELF header to tell Ghidra where the code lives. A guessed base address produces plausible-looking but wrong cross-references.
- Over-reading names. A function that touches a string with "auth" in it isn't necessarily the authentication check.
The fix is a notes file and a rule: every claim about the image carries the offset, path or address it came from, and is marked confirmed or inferred.
Step 1: triage the raw image
Work on a copy and record its hash. Then look at it before extracting anything:
sha256sum firmware.bin
file firmware.bin
binwalk firmware.bin # signature scan: headers, filesystems, compression
binwalk -E firmware.bin # entropy: flat-high means compressed or encrypted
strings -n 8 firmware.bin | head -100
The signature scan tells you what's inside and at which offsets — a uImage header, an LZMA kernel, a SquashFS filesystem, a JFFS2 partition. The entropy plot tells you whether the interesting parts are just compressed (extraction will work) or encrypted (it won't, and you'll need the decryption routine from an older image or the bootloader). A good prompt:
Triage firmware.bin. Record its hash, the binwalk signatures with offsets and the entropy picture in notes.md. Say whether it looks compressed, encrypted or plain, and why. Don't extract yet.
Step 2: extract with binwalk or unblob
binwalk is the classic, and its extraction mode is one flag:
binwalk -e firmware.bin
unblob is a newer extractor built for exactly this job, with broad format support and a report of what it couldn't identify:
unblob -e extracted/ firmware.bin
Try both if one struggles; they handle different vendor formats. For a SquashFS image you've already located, unsquashfs extracts it directly. If extraction leaves a blob unidentified, that's where the agent's scripting helps: ask it to look at the first bytes, compare against known magic numbers, and write a carve-and-decompress script — then check the result with file before believing it.
Step 3: identify the architecture and filesystem
Once you have a root filesystem, the binaries tell you the architecture:
find extracted/ -type d -name 'squashfs-root' -o -type d -name 'rootfs*'
file extracted/**/bin/busybox
readelf -h extracted/**/bin/busybox # Machine, Class, Data (endianness), Flags
readelf -h gives you the machine (ARM, MIPS, AArch64, PowerPC), 32 or 64 bit, endianness and ABI flags. Write those into the notes; every later step depends on them. The filesystem type came from step 1; note it too, along with whether the root is read-only (SquashFS usually is) and where writable config lives (often a separate JFFS2 or UBI partition).
Step 4: find the interesting binaries and configs
A router image can hold hundreds of files, most of them BusyBox applets. The agent is quickest at narrowing that down:
cd extracted/squashfs-root
ls etc/init.d etc/rc.d 2>/dev/null; cat etc/inittab 2>/dev/null
find . -type f -perm -u+x ! -name busybox -exec file {} + | grep ELF
grep -rIl -E 'passw|secret|api[_-]?key|BEGIN .*PRIVATE KEY' etc/ 2>/dev/null
find . -name '*.cgi' -o -name 'httpd*' -o -name '*.lua' | head
What you're looking for: which services start at boot and with what arguments, the web server and its CGI handlers, update and provisioning daemons, anything listening on the network, and secrets that shouldn't ship in an image. Ask the agent for a ranked list with a reason for each, and the path:
From the extracted root, list the ten binaries or scripts most worth reading — network-facing services, update logic, vendor code rather than BusyBox — with the path and why. Also list any keys, certificates or credential files, without printing their contents.
Step 5: load into Ghidra with the right processor
For an ELF binary Ghidra reads the architecture from the header, but check it picked the right variant. For anything without a header — a bootloader, a kernel image, an RTOS blob — you choose the language yourself (for example ARM:LE:32:v7 or MIPS:BE:32:default) and the base address. Headless, the language is set with -processor:
analyzeHeadless /tmp/fw-proj fw -import ./squashfs-root/usr/sbin/httpd
# a raw blob: name the processor yourself
analyzeHeadless /tmp/fw-proj fw -import ./blob.bin -processor ARM:LE:32:v7
Pair that with a decompile-everything script (shown in the Ghidra guide) so the agent can grep the output, or connect an MCP server for interactive work (setup here). On a stripped vendor binary the agent earns its keep naming functions from referenced strings and recognizing linked libraries — just insist it cites the address and the string for each name, so you can check.
For raw blobs, base address is the hard part. Ask the agent to look for absolute pointers into the image (string tables are a good anchor) and propose a base with the evidence; confirm by checking that cross-references land on real strings.
Step 6: run one binary under QEMU user mode
Static reading only goes so far. QEMU's user-mode emulation runs a single foreign-architecture Linux binary on your machine, using the extracted root as its library path:
# Debian/Ubuntu: apt install qemu-user-static
cp "$(which qemu-mipsel-static)" squashfs-root/usr/bin/ # match the arch from step 3
sudo chroot squashfs-root /usr/bin/qemu-mipsel-static /bin/busybox ls
# or without chroot, pointing at the root for libraries:
qemu-arm-static -L ./squashfs-root ./squashfs-root/usr/bin/some-tool --help
Pick the QEMU binary that matches step 3 (qemu-arm, qemu-mips, qemu-mipsel, qemu-aarch64 and so on). Expect daemons to fail on missing hardware, NVRAM or config; the agent is good at reading the error, finding the missing file or the NVRAM lookup in the decompiled code, and stubbing just enough to get further. Do this in a container or VM rather than on your workstation, and keep anything you start bound to loopback. Full-system emulation of a whole device is a much bigger project; user mode on one binary is usually enough to answer "what does this actually do with its arguments?"
Keeping it honest
Put these in your project instructions (CLAUDE.md, AGENTS.md or CAVEIRA.md):
- Record the image hash, and the architecture and endianness from
readelf, before any analysis. - Cite an offset, path or address for every claim.
- Mark findings confirmed (seen in bytes, assembly or at runtime) or inferred.
- Never print keys or credentials found in the image into chat; record their paths.
- Run extracted binaries only under emulation, in a container or VM.
Which assistant to use
Any agent that can run shell commands can do this: Claude Code, Codex, OpenCode, caveira and others. What matters is long context for big decompiled outputs, a workflow that queries rather than pastes, and an assistant that doesn't balk at routine reversing. Mainstream assistants usually handle firmware analysis of your own device fine; some get cautious around anything that looks like bypassing protections, even on hardware you own (what to do about that).
caveira is one option built for this: its backend serves uncensored, abliterated open-weight models, it ships a reverse-engineering skill that drives Ghidra headless and radare2 when installed, it speaks MCP, and its optional Docker box gives the agent a Linux container with radare2, binutils, a C toolchain and Python to work in (Ghidra can be added to the box image). It doesn't replace knowing binwalk, Ghidra and QEMU — everything above applies whichever agent you use. If the image can't leave your machine at all, run a local model instead (the trade-off).