Attack ATmega Embedded Firmware: The Bootloader Is Also a Door
A locked AVR is usually described as inaccessible. That is true of the program array and false of the device. The lock bits are designed to coexist with field firmware updates, which means the bootloader keeps write access to program memory even when the array cannot be read. That write access is an interface, and an interface can be examined.
The examination is worth doing before any physical step, because it costs a serial connection and an afternoon. What it yields depends on what the bootloader implements, and bootloaders vary enormously.
Why a bootloader exists on a locked device
The combination sounds contradictory and is not. A production device needs to be unreadable and updatable. The lock bits provide both: they block readback, and they leave the boot section able to write.
| Requirement | Mechanism |
|---|---|
| Firmware cannot be extracted | Read lock |
| Firmware can still be updated | Bootloader write access |
| Bootloader cannot be replaced | Boot section lock bits |
| Update cannot be replayed by an attacker | Application-level signature |
The third row is a separate lock from the read lock, and it is frequently not set. A device with a read lock and an unprotected boot section has a writable, executable region that the application does not control.
What the bootloader exposes
The surface is small and varies by implementation.
| Feature | Common in | Value to an assessment |
|---|---|---|
| Write page | Almost all | Can replace the application |
| Read page | Rare | Would read the array back |
| Verify page | Some | Compares, and leaks information through timing |
| Read configuration | Common | Confirms fuse and lock state |
| Write configuration | Some | Could clear locks, at the cost of an erase |
| Jump to application | All | Normal exit |
The second row is the one that would end the project favourably, and it is rare precisely because it defeats the lock. When it exists, it is usually because the bootloader was written for a product that needed backup and restore, and the read command was left enabled.
The third row is the interesting one. A verify command compares supplied data against the array and reports whether it matches. That is not a read, but it is an oracle: an attacker who can test candidate bytes learns the contents one guess at a time. Exploiting it is slow and it works.
Finding the entry condition
A bootloader activates under a specific condition, and the condition is the first thing to establish.
| Entry condition | How to trigger |
|---|---|
| A pin held at a level during reset | Pull the pin |
| A specific byte in EEPROM | Requires EEPROM write access |
| A command received within a timeout | Send it quickly after reset |
| A jump instruction in the application | Requires application cooperation |
| An empty application | Erase, then the bootloader waits |
The fifth row is a design pattern worth knowing: a bootloader that waits indefinitely when the application area is blank. On such a device, a partially failed update leaves the bootloader permanently available.
What can be done with write access
Write access alone does not reveal the firmware, but it changes what is possible.
| Capability | Consequence |
|---|---|
| Replace the application | A custom program can run on the device |
| Run code in the boot section’s context | Access to whatever the bootloader can reach |
| Read EEPROM from a custom program | If the lock permits |
| Read configuration from a custom program | Usually permitted |
| Read flash from a custom program | Blocked by the same lock |
The second and fifth rows together define the limit. A custom program running on the device is subject to the same read restriction as the original firmware, so it cannot simply read the array. What it can do is everything else: characterise the device, read the EEPROM, dump the configuration, and observe the pins.
The extraction that write access enables
There is one technique that combines write access with the lock’s own behaviour, and it is worth understanding because it explains some results that otherwise seem impossible.
| Approach | Mechanism | Side effect |
|---|---|---|
| Page-by-page overwrite and observe | Write a page, observe the response | Destroys the page |
| Exploit a verify oracle | Test candidate contents | Slow, non-destructive |
| Use the bootloader to load a reader | Reader is subject to the lock | Limited |
| Fault the lock check during boot | Skip the read restriction | Requires equipment |
The fourth row is the general answer on many parts and it is not a bootloader technique at all; it is a fault injection against the check that enforces the lock. It belongs here only because the bootloader is often the code whose check is targeted.
When the bootloader is the whole story
On some products the bootloader is not a small update utility but a substantial program with its own protocol, its own state machine, and its own bugs.
| Bootloader size | Implication |
|---|---|
| A few hundred bytes | Simple write-and-jump; little to exploit |
| A few kilobytes | Protocol handling; worth examining for parsing errors |
| Tens of kilobytes | Effectively an operating system; the interesting code |
The third row changes the assessment completely, because a large bootloader may contain more functionality than the application, and its bugs are reachable without any lock being touched.
Where the rest of the picture is
The two configuration blocks, and which of them governs readback, are covered in attacking ATmega embedded firmware. What the EEPROM holds, and why it is often readable when flash is not, is in attacking ATmega AVR programs. The image that eventually comes out still needs its addressing convention resolved, which is the subject of attacking ATmega firmware.
Services at this boundary
Work covers bootloader identification and entry-condition discovery, protocol analysis, assessment of verify or read commands, custom program development for on-device characterisation, and EEPROM and configuration recovery through the bootloader path. It does not cover reading a locked array through a bootloader that respects the lock, because that is what the lock is for.
The practical point is that a locked device is not a closed device. It is a device with a narrow open interface, and the first question is what that interface will do.