Bare Metal Reverse Engineering
This talk demonstrates techniques for reverse engineering bare-metal firmware, focusing on ARM-based microcontrollers. It covers the process of extracting raw binary data, identifying memory structures, and utilizing tools like Ghidra to reconstruct source code. The presentation highlights the use of SVD loaders and custom scripts to automate the identification of peripheral mappings and function signatures in stripped binaries.
Reverse Engineering Bare-Metal Firmware Without Losing Your Mind
TLDR: Analyzing bare-metal firmware on ARM-based microcontrollers often feels like staring into a void of raw binary data. This research introduces a streamlined workflow using Ghidra combined with SVD-Loader and custom scripts to automate peripheral mapping and function identification. By leveraging System View Description files, researchers can turn opaque memory offsets into readable, actionable code, significantly reducing the time required to identify critical logic in embedded systems.
Reverse engineering embedded firmware is usually a miserable experience. You dump a binary from a chip, load it into a disassembler, and are immediately greeted by a sea of raw hex. There are no symbols, no clear entry points, and the code is often just a collection of direct register writes that mean nothing without the datasheet open in another tab. Most people give up here, or they spend weeks manually mapping memory addresses to peripherals. It is tedious, error-prone, and frankly, it is the biggest bottleneck in embedded security research.
The reality is that most bare-metal firmware, especially on ARM Cortex-M microcontrollers, follows predictable patterns. If you understand how the Board Support Package (BSP) and Hardware Abstraction Layer (HAL) interact with the hardware, you can stop guessing what a specific memory write does. The goal is to move from "what is this binary doing" to "this is the UART initialization routine" as quickly as possible.
Automating the Mapping Process
When you load a raw binary into a tool like Ghidra, the biggest hurdle is the lack of context. You see a write to 0x40023800, but you have no idea if that is a GPIO port, a timer, or a clock configuration register. This is where System View Description (SVD) files become your best friend. These XML files describe the entire memory map of a microcontroller, including every peripheral and its associated registers.
Instead of manually defining these regions, you can use the SVD-Loader plugin. This tool parses the SVD file and automatically populates the memory map in your disassembler. Suddenly, that mysterious write to 0x40023800 is labeled as RCC_AHB1ENR. You are no longer looking at raw addresses; you are looking at the actual hardware configuration. This shift in perspective is massive. It turns a blind reverse engineering effort into a guided tour of the firmware's logic.
Identifying Logic with BSim
Once you have the memory map sorted, the next challenge is identifying the actual code. Embedded firmware is often stripped of all symbols, making it difficult to distinguish between custom application code and standard library functions. This is where BSim comes into play. Originally developed by the NSA, BSim allows you to perform fuzzy matching against known libraries.
You can pre-compile a project, build a database of function signatures, and then use that database to annotate your target binary. Even if the compiler settings are slightly different or the binary is stripped, BSim can often identify common functions like memcpy, memset, or standard RTOS calls. For a pentester, this is a force multiplier. You can instantly filter out the noise of the standard library and focus your attention on the unique, custom code that likely contains the vulnerabilities you are looking for.
Practical Application in the Field
During a real-world engagement, you rarely have the luxury of time. If you are auditing an IoT device, you might be dealing with a custom RTOS or a vendor-specific implementation of a communication protocol. The workflow is simple: extract the binary, apply the SVD-Loader to get your peripheral context, and then use BSim to strip away the known library functions.
If you find a function that interacts with a communication peripheral, you can use a tool like TypeLoader to apply custom data types to memory regions. By casting these regions to the structures defined in the vendor's HAL, you can make the decompiled code look almost identical to the original source. This is not just about making the code look pretty; it is about enabling static analysis that actually works. When you can see the structure of the data being passed to a function, you can spot buffer overflows or logic errors that would be invisible in a raw disassembly.
A Note on Defensive Reality
Defenders often rely on the complexity of bare-metal firmware as a form of security through obscurity. They assume that because the code is stripped and lacks an operating system, it is "safe" from deep analysis. This is a dangerous assumption. If a researcher can automate the identification of peripheral mappings and library functions, the barrier to entry for finding vulnerabilities drops significantly. Manufacturers should focus on implementing hardware-level protections like Memory Protection Units (MPUs) to enforce privilege separation, rather than relying on the difficulty of reverse engineering to keep their devices secure.
Stop wasting time on manual memory mapping. The tools to automate this exist, and they are mature enough to be used in production-grade research. If you are still manually renaming functions in Ghidra without using SVD files or signature matching, you are working harder, not smarter. Start building your own databases of common library signatures and peripheral definitions. The next time you encounter a stripped binary, you will be able to identify the attack surface in minutes rather than days.
Target Technologies
Up Next From This Conference
Similar Talks

Hacking Apple's USB-C Port Controller

Unmasking the Snitch Puck: The Creepy IoT Surveillance Tech in the School Bathroom




