Firmware Dynamic Analysis & Emulation
Run extracted firmware in controlled environments for dynamic analysis, debugging, and vulnerability testing. This skill provides comprehensive workflows for both automated and manual emulation approaches.
Emulation Strategy Decision Tree
Before starting emulation, determine the best approach:
Use AUTOMATED (Firmadyne/FirmAE) when:
- Analyzing multiple router/IoT firmware images quickly
- Need quick initial assessment
- Firmware is Linux-based embedded system
- You want network services automatically configured
- Time-constrained analysis
Use USER-MODE (qemu-user) when:
- Running individual binaries from extracted firmware
- Need quick testing of specific executables
- Debugging single applications
- Fuzzing specific binaries
- Full system emulation is overkill
Use SYSTEM-MODE (qemu-system) when:
- Need a guest kernel and modeled device environment
- Analyzing kernel-level behavior
- Require hardware supported by a specific QEMU board model (GPIO/MTD are not generic substitutes)
- Automated tools failed
- Advanced debugging of boot process needed
- Custom firmware with non-standard init
Examples with sudo, TAP/iptables or chroot assume a disposable Linux analysis
VM. Chroot and QEMU user-mode are not security boundaries and share the host
kernel/network. Keep debugger listeners inside that VM; QEMU's GDB stub has no
authentication. -L supplies an interpreter prefix, not an isolated rootfs.
Interactive foreign shells need suitable binfmt_misc registration for subsequent
execve calls, or each foreign executable must be launched through QEMU.
Prerequisites
Install Required Tools
# QEMU (all architectures)
sudo apt-get install qemu-system qemu-user-static qemu-user
# Cross-architecture debugging
sudo apt-get install gdb-multiarch
# Network tools
sudo apt-get install bridge-utils uml-utilities tcpdump wireshark tshark
# Filesystem tools
sudo apt-get install squashfs-tools mtd-utils
# Optional but recommended
pip3 install python-magic scapy
# See firmware-extraction for standalone Binwalk 3.1.0; automated frameworks
# may instead require the legacy Python Binwalk API in a separate environment.
# For Firmadyne/FirmAE
sudo apt-get install postgresql python3-psycopg2
Verify Installation
# Check QEMU versions
qemu-arm --version
qemu-system-arm --version
# Check GDB
gdb-multiarch --version
# List available QEMU machines
qemu-system-arm -M help
qemu-system-mips -M help
Workflow Overview
Follow this systematic approach for firmware emulation:
- Strategy Selection - Automated vs manual (use decision tree)
- Preparation - Extract firmware, identify architecture
- Initial Emulation - Try automated tools first
- Manual Emulation - If automated fails, use QEMU directly
- Debugging - GDB integration for deep analysis
- Network Analysis - Traffic capture and protocol analysis
- Vulnerability Testing - Fuzzing and exploitation
- Documentation - Record findings and techniques
Path 1: Automated Emulation (Quick Start)
Try automated tools for supported Linux firmware; success depends on the corpus, architecture, kernel and hardware assumptions.
Step 1: Prepare Firmware
# Ensure firmware is extracted
# Use firmware-extraction skill if needed
ls -la squashfs-root/
# Note firmware details
file vmlinux # Kernel if present
cat squashfs-root/etc/version # Firmware version
Step 2: Run FirmAE
FirmAE is recommended over Firmadyne (better success rate).
cd /path/to/FirmAE
# Automated analysis
sudo ./run.sh -r "Brand" /path/to/firmware.bin
# Wait for completion (5-15 minutes typically)
# FirmAE will:
# - Extract filesystem
# - Detect architecture
# - Create QEMU image
# - Boot firmware
# - Run network analysis
Step 3: Access Running Firmware
# Check FirmAE output for IP address
# Typical: 192.168.0.1 or 192.168.1.1
# Scan for open services
nmap -p- -A 192.168.0.1
# Access web interface
curl http://192.168.0.1/
# Or open in browser
# Try telnet/SSH
telnet 192.168.0.1
ssh admin@192.168.0.1
Step 4: Analyze Network Traffic
# Check scratch/<IMAGE_ID>/ for logs; capture explicitly if a pcap is needed.
# Or capture live
sudo tcpdump -i tap1_0 -w analysis.pcap
# Analyze in Wireshark
wireshark analysis.pcap
When Automated Fails
If FirmAE/Firmadyne doesn't boot the firmware:
- Check console output for errors
- Inspect FirmAE's architecture-detection script and its detected architecture;
run.sh -ameans analysis, not architecture selection - Review
/path/to/FirmAE/scratch/<ID>/for logs - Proceed to Path 2 (Manual Emulation)
Reference: See references/automated-emulation.md for complete Firmadyne/FirmAE guide.
Path 2: Manual User-Mode Emulation
Run individual binaries without full system emulation.
Step 1: Setup Chroot Environment
# Mount extracted filesystem
sudo mkdir -p /mnt/firmware
sudo mount -o loop rootfs.ext4 /mnt/firmware
# Or if directory: sudo mount --bind squashfs-root/ /mnt/firmware
# Copy qemu-static (critical!)
sudo cp /usr/bin/qemu-arm-static /mnt/firmware/usr/bin/
# Use appropriate arch: qemu-mips-static, qemu-aarch64-static, etc.
Step 2: Test Basic Execution
# Run simple command
sudo chroot /mnt/firmware /usr/bin/qemu-arm-static /bin/busybox
# Interactive shell
sudo chroot /mnt/firmware /usr/bin/qemu-arm-static /bin/sh
# Check architecture matches
file /mnt/firmware/bin/busybox
# Should match qemu-XXX-static used
Step 3: Run Target Binary
# Identify target (e.g., web server)
find /mnt/firmware -name "*httpd*"
# Run with arguments
sudo chroot /mnt/firmware /usr/bin/qemu-arm-static /usr/sbin/httpd -f -p 8080
# For BusyBox httpd, -f means foreground; flags differ between servers.
# -p 8080: port 8080
# Access from host
curl http://localhost:8080/
Step 4: Debug with GDB
# Start binary with GDB server
sudo chroot /mnt/firmware /usr/bin/qemu-arm-static -g 1234 /usr/sbin/httpd
# In another terminal
gdb-multiarch /mnt/firmware/usr/sbin/httpd
(gdb) target remote :1234
(gdb) break main
(gdb) continue
Reference: See references/qemu-user.md for comprehensive user-mode guide.
Path 3: Manual System-Mode Emulation
System emulation requires a kernel, DTB and rootfs compatible with the selected board. Matching CPU architecture alone is insufficient; vendor kernels commonly need unavailable SoC peripherals.
Step 1: Identify Components
# Locate kernel
find extracted/ -name "vmlinux" -o -name "zImage" -o -name "uImage"
# Check kernel arch
file vmlinux
# ELF 32-bit LSB executable, ARM → use qemu-system-arm
# Locate device tree (ARM/AArch64)
find extracted/ -name "*.dtb"
# Prepare rootfs
# If extracted as directory, create ext4 image
dd if=/dev/zero of=rootfs.ext4 bs=1M count=256
mkfs.ext4 rootfs.ext4
mkdir /tmp/mnt
sudo mount -o loop rootfs.ext4 /tmp/mnt
sudo cp -a squashfs-root/. /tmp/mnt/
sudo umount /tmp/mnt
Step 2: Determine QEMU Machine
# List available machines for architecture
qemu-system-arm -M help
# Common choices:
# ARM: versatilepb (requires a compatible kernel/DTB), vexpress-a9
# MIPS: malta
# AArch64: virt
# x86: pc (default)
Step 3: Boot Firmware
# ARM example
qemu-system-arm \
-M versatilepb \
-kernel zImage \
-dtb versatile-pb.dtb \
-drive file=rootfs.ext4,if=sd,format=raw \
-append "root=/dev/mmcblk0 console=ttyAMA0 rw debug" \
-nographic \
-m 256M
# MIPS example
qemu-system-mips \
-M malta \
-kernel vmlinux \
-hda rootfs.ext4 \
-append "root=/dev/sda console=ttyS0 nokaslr" \
-nographic \
-m 256M
Step 4: Configure Networking
# Create TAP interface (requires root)
sudo tunctl -t tap0 -u $USER
sudo ifconfig tap0 192.168.100.1 netmask 255.255.255.0 up
# Enable forwarding
sudo sysctl -w net.ipv4.ip_forward=1
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
# Boot with TAP networking
qemu-system-arm \
-M versatilepb \
-kernel zImage \
... \
-net nic,macaddr=52:54:00:12:34:56 \
-net tap,ifname=tap0,script=no,downscript=no
# Inside guest, configure network
ifconfig eth0 192.168.100.2 netmask 255.255.255.0 up
route add default gw 192.168.100.1
Step 5: Troubleshoot Boot Issues
Kernel panic - cannot mount root:
# Try different root devices
-append "root=/dev/sda ..." # IDE disk
-append "root=/dev/vda ..." # VirtIO disk
-append "root=/dev/mmcblk0 ..." # SD card
# Specify filesystem type
-append "root=/dev/sda rootfstype=ext4 ..."
# Boot to shell for debugging
-append "init=/bin/sh ..."
No output / black screen:
# Ensure -nographic flag
# Try different console device
-append "console=ttyS0 ..." # Serial
-append "console=ttyAMA0 ..." # ARM UART
# Enable early kernel messages
-append "earlyprintk debug loglevel=8 ..."
Wrong machine type:
# Select only a board supported by the supplied kernel/DTB
-M versatilepb # Instead of device-specific
-M virt # Generic virtual machine
Reference: See references/qemu-system.md for architecture-specific boot recipes.
Advanced Debugging with GDB
Setup GDB Session
# Start QEMU with GDB server (paused)
qemu-system-arm \
-M versatilepb \
-kernel zImage \
... \
-gdb tcp:127.0.0.1:1234 -S
# -S: Pause at startup
# Connect GDB
gdb-multiarch vmlinux
(gdb) target remote :1234
(gdb) break start_kernel
(gdb) continue
Kernel Debugging
# Set breakpoints on kernel functions
break do_fork
break sys_execve
break do_IRQ
# Step through boot
continue
step
nexti
# Examine kernel state
info registers
x/10i $pc
backtrace
Userspace Debugging
Run a target-architecture gdbserver inside the guest for process-aware debugging;
the system QEMU stub exposes CPUs and does not automatically track processes.
Use a separate guest port and connect over the isolated emulation network:
# Inside guest
gdbserver :2345 /usr/sbin/httpd -f
# On host
gdb-multiarch ./rootfs/usr/sbin/httpd
target remote 192.168.100.2:2345
break main
continue
# Examine application state
print variable
x/10x $sp
info threads
Hardware Watchpoints
# Watch memory location
watch *0x8048000
# Watch variable
watch global_var
# Conditional watchpoint
watch variable if variable > 100
Reference: See references/gdb-debugging.md for comprehensive GDB techniques.
Network Traffic Analysis
Capture Traffic
# Start capture before booting firmware
sudo tcpdump -i tap0 -w capture.pcap &
CAPTURE_PID=$!
# Boot firmware
qemu-system-arm ...
# Interact with firmware
# Traffic is being captured
# Stop capture
sudo kill -INT "$CAPTURE_PID"
Analyze with Wireshark
# Open in Wireshark
wireshark capture.pcap
# Or use tshark for CLI analysis
tshark -r capture.pcap -Y "http"
tshark -r capture.pcap -Y "tcp.port == 23" # Telnet
Extract Credentials
# HTTP POST data
tshark -r capture.pcap -Y "http.request.method == POST" -T fields -e http.file_data
# Telnet passwords (cleartext)
tshark -r capture.pcap -q -z follow,tcp,ascii,0 # Select the Telnet tcp.stream index
# FTP credentials
tshark -r capture.pcap -Y "ftp.request.command == USER || ftp.request.command == PASS"
Man-in-the-Middle Testing
# Install mitmproxy
pipx install mitmproxy
# Start transparent proxy
sudo mitmproxy --mode transparent --showhost
# Redirect firmware traffic
sudo iptables -t nat -A PREROUTING -i tap0 -p tcp --dport 80 -j REDIRECT --to-port 8080
sudo iptables -t nat -A PREROUTING -i tap0 -p tcp --dport 443 -j REDIRECT --to-port 8080
# HTTPS decryption also requires the guest to trust the proxy CA and no
# unhandled certificate pinning. Record any trust-store changes in the report.
# View and modify in real-time
Reference: See references/network-analysis.md for protocol analysis and MITM techniques.
Vulnerability Testing
Web Interface Testing
# Access web interface
curl http://192.168.100.2/
# Directory brute-force
dirb http://192.168.100.2/ /usr/share/dirb/wordlists/common.txt
# Vulnerability scanning
nikto -h http://192.168.100.2/
nmap --script vuln -p 80 192.168.100.2
# SQL injection testing
sqlmap -u "http://192.168.100.2/login.php" --forms --batch
# Command injection
curl "http://192.168.100.2/cgi-bin/test.cgi?cmd=;ls"
Binary Fuzzing
# With AFL++ in QEMU mode
export QEMU_LD_PREFIX="$PWD/rootfs"
# Build AFL++ QEMU instrumentation for the target architecture first.
afl-fuzz -Q -i input_dir -o output_dir -- \
./rootfs/usr/bin/target @@
# Custom fuzzer for network service
for i in {1..1000}; do
echo "Fuzzing iteration $i"
python3 fuzzer.py 192.168.100.2 9000
done
Exploit Development
# Develop exploit against running firmware
# 1. Identify vulnerability through fuzzing
# 2. Debug with GDB to understand crash
qemu-arm -g 1234 -L ./rootfs/ ./vulnerable_binary
gdb-multiarch ./vulnerable_binary
(gdb) target remote :1234
# 3. Craft exploit
# 4. Test against emulated firmware
python3 exploit.py 192.168.100.2
Troubleshooting Common Issues
Issue: QEMU Boot Failures
Symptom: Kernel panic, no output, or boot hang
Solutions:
- Verify architecture matches:
file vmlinuxvsqemu-system-XXX - Check a board model that matches the kernel/DTB:
-M helplists options - Adjust kernel command line: Different console, root device
- Use
-append "debug loglevel=8"for more output - Try
-append "init=/bin/sh"to bypass normal init - Check for missing DTB file (ARM/AArch64)
Issue: Network Not Working
Symptom: Can't ping or connect to emulated firmware
Solutions:
- Verify TAP interface is up:
ip addr show tap0 - Check QEMU network configuration:
-net nic -net tap,ifname=tap0 - Configure guest network manually inside QEMU
- Use user-mode networking instead:
-netdev user,id=net0 - Check firewall rules on host
Issue: GDB Won't Connect
Symptom: Connection refused or Remote 'g' packet reply is too long
Solutions:
- Ensure QEMU started with
-gdb tcp:127.0.0.1:1234 - Use
gdb-multiarchnot regulargdb - Set architecture in GDB:
set architecture arm - Load correct binary:
file vmlinuxbefore connecting
Issue: Binary Crashes Immediately (User-Mode)
Symptom: Segfault or illegal instruction
Solutions:
- Check library path: Use
-L ./rootfs/ - Verify dependencies:
lddinside chroot - Try different CPU model:
-cpu cortex-a9 - Use QEMU_STRACE for debugging:
QEMU_STRACE=1 qemu-arm ...
Issue: Services Won't Start
Symptom: Daemon fails to start or exits immediately
Solutions:
- Check this server's usage for its foreground flag (
-ffor BusyBox httpd) - Check for missing /dev nodes
- Verify permissions
- Look at error messages with
strace - Run init scripts manually to identify failure point
Integration with Other Skills
With Firmware Extraction
# 1. Extract firmware (firmware-extraction skill)
binwalk -e firmware.bin
# 2. Emulate extracted firmware (this skill)
qemu-system-arm -kernel zImage ...
With Static Analysis
# 1. Emulate and identify interesting binaries
nmap -sV 192.168.100.2
# 2. Extract those binaries
cp /mnt/firmware/usr/sbin/httpd ./
# 3. Static analysis (firmware-static-analysis skill)
readelf -h httpd
objdump -d httpd
Full Workflow Example
# Complete firmware analysis pipeline
# 1. Extract
binwalk -e firmware.bin
cd /path/to/extracted/rootfs/ # Use the actual extraction output path
# 2. Quick automated emulation attempt
cd /path/to/FirmAE
sudo ./run.sh -r Brand /path/to/firmware.bin
# 3. If automated fails, manual system emulation
qemu-system-arm -M versatilepb -kernel zImage ...
# 4. Capture network traffic
sudo tcpdump -i tap0 -w capture.pcap &
CAPTURE_PID=$!
# 5. Identify services
nmap -p- -A 192.168.100.2
# 6. Static analysis of key binaries
readelf --dyn-syms --wide ./rootfs/usr/sbin/httpd
# 7. Debug specific binary
qemu-arm -g 1234 -L ./rootfs/ ./rootfs/usr/sbin/httpd
gdb-multiarch ./rootfs/usr/sbin/httpd
(gdb) target remote :1234
# 8. Test for vulnerabilities
nikto -h http://192.168.100.2/
sqlmap -u "http://192.168.100.2/login.php"
# 9. Document findings
Best Practices
Before Starting
- Try automated first - FirmAE saves time on common firmware
- Identify architecture correctly - Prevents many issues
- Create workspace - Organized directory structure
- Backup originals - Keep untouched firmware copies
- Document everything - Record commands and findings
During Emulation
- Start simple - User-mode before system-mode when possible
- Incremental debugging - Boot to shell first, then full system
- Network isolation - Use separate network namespace or VM
- Snapshot frequently - QEMU snapshots save time
- Monitor resources - QEMU can be resource-intensive
Security Considerations
- Isolated environment - Don't run untrusted firmware on main system
- Network segmentation - Separate emulation network
- Monitor egress - Watch for unexpected network activity
- Limit privileges - Don't run as root unless necessary
- Clean up - Remove TAP interfaces and iptables rules after
Efficiency Tips
- Use screen/tmux - Multiple terminals for QEMU, GDB, tcpdump
- Script common tasks - Automate repetitive emulation setups
- Keep notes - Working configurations for different architectures
- Build kernel library - Pre-compiled kernels for common platforms
- Learn one architecture well - Master ARM before moving to MIPS
Documentation Template
Record emulation setup and findings:
# Firmware Emulation Report
**Firmware**: [filename]
**Date**: [date]
**Analyst**: [name]
## Emulation Method
- **Approach**: [Automated/User-Mode/System-Mode]
- **Tool**: [FirmAE/QEMU/Both]
- **Architecture**: [ARM/MIPS/x86/etc.]
- **Success**: [Yes/Partial/No]
## Configuration
### QEMU Command
[paste working qemu command]
### Network Configuration
- **IP Address**: [guest IP]
- **Gateway**: [gateway IP]
- **Interface**: [tap0/user-mode]
## Services Identified
| Port | Service | Version | Notes |
|------|---------|---------|-------|
| 80 | HTTP | lighttpd 1.4.x | Web interface |
| 23 | Telnet | BusyBox | Default creds: admin/admin |
## Findings
### Network Traffic
- [Key observations from packet capture]
- [Credentials found]
- [Suspicious protocols]
### Vulnerabilities
- [CVE-XXXX-XXXX: Description]
- [Command injection in cgi-bin/admin.cgi]
### Debug Notes
- [Breakpoints set]
- [Interesting memory locations]
- [Crash analysis]
## Issues Encountered
- [Problems and solutions]
- [Workarounds used]
## Next Steps
1. [Further testing needed]
2. [Exploit development targets]
3. [Code review recommendations]
Additional References
- QEMU System-Mode:
references/qemu-system.md- Architecture-specific system emulation - QEMU User-Mode:
references/qemu-user.md- Individual binary emulation - GDB Debugging:
references/gdb-debugging.md- Advanced debugging techniques - Network Analysis:
references/network-analysis.md- Traffic capture and protocol analysis - Automated Tools:
references/automated-emulation.md- Firmadyne and FirmAE complete guide
Quick Reference Commands
# User-mode emulation
sudo chroot /mnt/firmware /usr/bin/qemu-arm-static /bin/sh
# System-mode emulation (ARM)
qemu-system-arm -M versatilepb -kernel zImage -drive file=rootfs.ext4,if=sd \
-append "root=/dev/mmcblk0 console=ttyAMA0" -nographic
# GDB debugging
qemu-arm -g 1234 binary
gdb-multiarch binary → target remote :1234
# Network capture
sudo tcpdump -i tap0 -w capture.pcap
# FirmAE automated
sudo ./run.sh -r Brand firmware.bin
# Check architecture
file binary
# Create TAP interface
sudo tunctl -t tap0 -u $USER
sudo ifconfig tap0 192.168.100.1/24 up