Reading a firmware dump
Vector tables, strings and disassembly, what attackers look for, and protecting the image.
Assume the dump
Sooner or later someone reads your firmware. They desolder the flash chip and read it with a clip, or connect to an unlocked SWD port, or glitch the readout protection, or simply download the update file from your server. Security that depends on the firmware staying secret does not hold. Engineers who read their own images the way an attacker does find the problems first, and the skills are the same ones used to debug a crash in a binary without its source, or to check what a vendor's blob really does.
What a dump looks like
A raw image of an MCU's flash is just bytes from address 0 of the flash (0x08000000 on an STM32). Its structure is still easy to find, because the hardware dictates the start.
The vector table
A Cortex-M image begins with its vector table: 32-bit little-endian words.
| Offset | Content | What it tells you |
|---|---|---|
| 0x00 | initial stack pointer | the top of RAM: 0x2000xxxx on an STM32, so the chip's RAM size |
| 0x04 | Reset_Handler | the entry point, with bit 0 set (Thumb): the first code to read |
| 0x08 to 0x3C | NMI, HardFault, ... SysTick | the system handlers; many point to one default handler |
| 0x40 onwards | the peripheral interrupts | which are used (each different), which share the default |
Every handler address must be odd (Thumb) and inside flash; the stack pointer must be inside RAM and aligned. Those checks tell an image from noise, find the image's base address (an image linked for 0x08004000 is an application behind a 16 KB bootloader), and let a tool place the code correctly.
#include <stdio.h>
#include <stdint.h>
static uint32_t word(const uint8_t *p) { return (uint32_t)p[0] | (uint32_t)p[1] << 8 | (uint32_t)p[2] << 16 | (uint32_t)p[3] << 24; }
int main(void) {
/* The first 16 bytes of an STM32 image: SP, Reset_Handler, NMI_Handler, HardFault_Handler. */
const uint8_t dump[16] = { 0x00, 0x80, 0x01, 0x20, 0x99, 0x02, 0x00, 0x08,
0x61, 0x03, 0x00, 0x08, 0x61, 0x03, 0x00, 0x08 };
uint32_t sp = word(dump), reset = word(dump + 4);
printf("initial SP 0x%08X: %u KB of RAM from 0x20000000\n", (unsigned)sp, (unsigned)((sp - 0x20000000u) / 1024));
printf("reset handler 0x%08X: code at 0x%08X, Thumb %s\n", (unsigned)reset, (unsigned)(reset & ~1u), (reset & 1) ? "yes" : "no");
printf("NMI and HardFault share 0x%08X: the default handler\n", (unsigned)word(dump + 8));
return 0;
}
Strings
The fastest way into an unknown image is its printable strings: runs of four or more ASCII characters. They give away the build (compiler and SDK versions, file paths with the developer's user name), the features (log messages, command names, AT commands), the network (host names, URLs, MQTT topics), and too often the secrets: Wi-Fi passwords, API keys, the cloud's TLS private key, a backdoor password for "factory test". strings -n 4 dump.bin is the first command anyone runs.
Disassembly
The code itself is read with a disassembler that knows the architecture (Ghidra, IDA, Binary Ninja, radare2, or arm-none-eabi-objdump -D -b binary -marm -Mforce-thumb). Starting from the reset handler, the tool follows calls; peripheral addresses (0x40013800 is USART1 on an STM32F1) name drivers; a string's address loaded into a register finds the function that prints it. From there an attacker looks for the code that checks a password, verifies an update, or parses network input, which is where the vulnerabilities are.
Finding what should not be there
Teams that review their own images look for the same things attackers do:
- Shared secrets. A key or password that is the same in every unit is a key to every unit once one is dumped. Provision per-device credentials at manufacturing (a device certificate and key generated on the device or injected into its secure storage) and design the cloud to accept only those.
- Debug leftovers. Test commands, verbose logs, a UART console with a "factory" mode, a JTAG port left unlocked.
- Weak update checks. The update verification is the most valuable target: find it, and check that it really verifies a signature, before writing anything, with no fallback path that skips it.
- Parsers of untrusted input. Every place that copies network or radio data with a length taken from the data itself.
Protecting the image
Readout protection, encryption and obfuscation raise the cost of analysis; none removes the need to assume it happens.
- Lock the debug port and readout in production (RDP level 1 or 2, eFuses on an ESP32, APPROTECT on nRF). Level 2 is permanent; test the production programming flow with it before committing.
- Encrypt the image in external flash and in update files where the chip supports it (ESP32 flash encryption, STM32 on-the-fly decryption, or the bootloader decrypting into internal flash).
- Keep secrets out of the image entirely, in a secure element or the chip's key storage, so that even a full dump does not contain them.
Going deeper
Interview question: You are handed a raw flash dump from an STM32-based product. How do you start analysing it?
Answer: First establish its layout: read the vector table at the start, check that the first word is a plausible stack pointer in RAM and the next words are odd addresses inside flash, which confirms it is a Cortex-M image and gives its load address and entry point, and shows whether it sits behind a bootloader. Run strings over it for version information, log messages, commands, URLs and anything that looks like a credential. Load it into a disassembler such as Ghidra at the right base address with the chip's memory map, start from the reset handler, and use peripheral register addresses and string references to name functions. Then focus on the security-relevant code: authentication, update verification and parsers of external input.
Interview question: Why are shared secrets in firmware a problem, and what replaces them?
Answer: Every device running the image carries the same secret, so extracting it once, by reading the flash, dumping it over an unlocked debug port, or analysing an update file, compromises every device and often the cloud service they talk to. Firmware should hold no secret that is common to all units. Instead each device gets its own credentials at manufacturing, ideally a key pair generated inside the device or a secure element with a certificate signed by the manufacturer, and the server authenticates devices individually so that a compromised unit can be revoked alone. Secrets that must exist are kept in protected key storage rather than in the image.
Explain it: In your own words, explain what the first few words of a Cortex-M firmware image reveal and how to check that a dump really is one.
Answer: The image starts with the vector table: the first word is the initial stack pointer, which should point into the chip's RAM near its top and so reveals the RAM size, and the second is the reset handler's address, the entry point, which should lie in flash with bit 0 set for Thumb code. The following words are the other exception and interrupt handlers, also odd addresses in flash, many often equal to one default handler. If these hold, the bytes are a Cortex-M image, the reset handler's address shows where it was linked to run, for example after a bootloader, and gives the place to start reading code.