Skip to main content
Be Bitwise

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.

bash
# Search extracted filesystem for common credential patterns
grep -r "password" etc/ usr/ --include="*.conf" --include="*.sh"
grep -r "admin" etc/passwd etc/shadow
find . -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 vs Hardcoded

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:

c
// 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 leaked

Hunting for command injection looks roughly like this:

  1. Find every CGI binary and script under the web server's tree.
  2. Track user input — HTTP parameters, headers, cookies — through the code.
  3. Hunt for system(), popen(), execvp(), or backtick execution at the other end.
  4. 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
c
// Common firmware buffer overflow pattern
void 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):

0x7fffffffe04000buffer[0..15]
0x7fffffffe04100
0x7fffffffe04200
0x7fffffffe04300
0x7fffffffe04400
0x7fffffffe04500
0x7fffffffe04600
0x7fffffffe04700
0x7fffffffe04800
0x7fffffffe04900
0x7fffffffe04a00
0x7fffffffe04b00
0x7fffffffe04c00
0x7fffffffe04d00
0x7fffffffe04e00
0x7fffffffe04f00
0x7fffffffe0500x9c3d5e1a7b2f4400Stack Canary
0x7fffffffe0580x00007fffffffe0d0Saved RBP
0x7fffffffe0600x00005555555551a9Return Address
Buffer
Canary
Saved RBP
Return Addr

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.

bash
# After emulating the firmware, scan for open ports
nmap -sV -p 1-65535 emulated_device_ip
# Compare with documented ports
# Any unexpected open port is a potential backdoor or debug interface

Automated Vulnerability Scanning

A few tools automate the first sweep of firmware vulnerability scanning:

bash
# 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 more

Tools 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.

The Firmware Security Landscape

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.