Finding Vulnerabilities in Firmware
Firmware Reverse Engineering · Embedded Systems & Firmware track
5 min read
In this module
Where Firmware Breaks
Firmware is, frankly, a vulnerability researcher's playground. Tight development budgets, ancient code that nobody dares touch, almost no security testing, and devices that stay deployed for a decade: it adds up to bugs. Lots of bugs. This lesson walks the patterns that show up over and over again, and how to spot them.
Hardcoded Credentials
The bread-and-butter firmware bug, and the easiest one to find with a stiff grep. Username/password pairs, SSH private keys, API tokens, encryption keys — embedded directly in the firmware image and shipped to every customer.
# Search extracted filesystem for common credential patternsgrep -r "password" etc/ usr/ --include="*.conf" --include="*.sh"grep -r "admin" etc/passwd etc/shadowfind . -name "*.pem" -o -name "id_rsa" -o -name "*.key"strings firmware.bin | grep -i "passw\|secret\|token\|key="Hardcoded creds are nasty because they don't just affect one device — every unit running that firmware version is exposed. The user can't change them, and an attacker who pulls them once gets durable access to the entire fleet.
Default credentials can be changed by the user (though many do not). Hardcoded credentials are compiled into the binary and cannot be changed. Some devices have both: a user-visible admin account with a changeable password AND a hidden maintenance account with a hardcoded password in the binary.
Command Injection
A staple of firmware web interfaces: take user input, slot it into a shell command, run it, and forget to sanitise. The pattern shows up everywhere CGI scripts are written in C or shell:
// Vulnerable CGI handler (simplified)char cmd[256];char *ip = get_cgi_param("target_ip");snprintf(cmd, sizeof(cmd), "ping -c 4 %s", ip);system(cmd);// If ip = "8.8.8.8; cat /etc/shadow", the shadow file is leakedHunting for command injection looks roughly like this:
- Find every CGI binary and script under the web server's tree.
- Track user input — HTTP parameters, headers, cookies — through the code.
- Hunt for
system(),popen(),execvp(), or backtick execution at the other end. - Check what (if anything) sanitises the input on the way through.
Plenty of vendors wrap system() in a custom helper. Cast a wide net: look for any function that eventually ends up at execve or one of its friends.
Buffer Overflows in Custom Protocols
Firmware tends to roll its own network protocols, written in C, parsed by hand, and unburdened by memory-safe languages or vetted libraries. Buffer overflows show up reliably in:
- Custom management protocols — vendor-defined UDP/TCP services for "device admin"
- Protocol parsers — DHCP options, UPnP messages, anything with length-prefixed structures
- HTTP header parsing — embedded HTTP daemons with hand-cranked parsers and bounds-check amnesia
// Common firmware buffer overflow patternvoid handle_request(int socket) { char buffer[1024]; int len = recv(socket, buffer, 4096, 0); // Receives up to 4096 into 1024-byte buffer process_request(buffer, len);}The simulator scales that bug down to a 16-byte buffer. Copy the 40-byte input in and watch it run through the canary, the saved frame pointer and the return address. The frame is laid out x86-64 style with a canary, which plenty of firmware builds don't have; without one, nothing notices until the function returns somewhere it shouldn't.
Buffer Overflow Simulator
Input: 40 bytes | Buffer: 16 bytes | Overflow: 24 bytes
Stack (high addresses at top):
Fuzzing — AFL, boofuzz, or your own purpose-built tooling — against emulated firmware is a productive way to find these, once the target boots under emulation. Throw malformed protocol traffic at the service and watch for crashes. Emulation helps here: a crashed process in QEMU gives you a core dump and a debugger, where the real device would just reboot.
Backdoor Detection
Intentional backdoors come in a few flavours:
- Hidden accounts — users who don't show up in the admin UI
- Magic packets — the device watches for specific byte sequences that unlock secret commands
- Debug interfaces — Telnet or SSH daemons disabled in the UI but very much alive in the binary
- Undocumented APIs — HTTP endpoints or protocol commands that don't appear in any datasheet
The detection strategy is pleasingly simple: diff what the device actually does — services running, ports open, endpoints responding — against what the documentation says. Any gap is worth a closer look.
# After emulating the firmware, scan for open portsnmap -sV -p 1-65535 emulated_device_ip
# Compare with documented ports# Any unexpected open port is a potential backdoor or debug interfaceAutomated Vulnerability Scanning
A few tools automate the first sweep of firmware vulnerability scanning:
# EMBA: automated firmware analysis./emba.sh -f firmware.bin -l ./logs
# Checks for: hardcoded credentials, known CVEs in included binaries,# unsafe function usage, binary hardening status, and moreTools like EMBA blend static analysis (greppable patterns in the filesystem and the binaries) with dynamic analysis (boot the firmware and poke at its services). Treat them as a first sweep — they hoover up the obvious wins so you can spend your manual time on the interesting bugs.
Consumer firmware security has improved but remains far behind desktop and server software. Many devices still ship with default credentials, unencrypted updates, disabled ASLR, and no stack canaries. Each firmware analysis you perform contributes to improving the ecosystem by identifying issues that vendors can fix and by raising awareness of the common vulnerability patterns that developers must avoid. When you find a bug in a real vendor's firmware, report it to them privately and agree a disclosure date before publishing; Responsible Disclosure covers how.