Getting past Secure Boot
Writing the SPI Flash from the OS: Protections and Checks
How LoJax's tools used the signed RwDrv.sys driver to dump and rewrite SPI flash firmware, the BIOSWE, BLE, SMM_BWP and PRx protections, and how to check them.
- Goal
- Getting past Secure Boot
- Layer
- Firmware
- Where it acts
- UEFI drivers (DXE)On the boot chain map
- Platforms
- Firmware, Windows
- ATT&CK
- T1542.001
- Also known as
- SPI flash reprogramming, BIOS write protection bypass
- Used by
- LoJax
- Checked by
- None: no module reads its traces
Overview
A firmware implant has to reach the SPI flash chip that holds the firmware. With a hardware programmer that takes physical access. From a running operating system it takes two things: kernel access to the chipset's flash controller, and a platform whose firmware left the BIOS region writable.
This technique is that write from the operating system. The attacker's tool loads a kernel driver that can touch hardware registers, reads the firmware out of the flash, modifies the image, and writes it back. Attackers rarely write their own driver for this: a legitimately signed utility driver with raw hardware access does the job and loads without warnings (see BYOVD on rootkits.dev). Whether the write succeeds depends on protections that the firmware, not the operating system, is responsible for setting.
It is the step that turns a compromised Windows host into a compromised motherboard. ESET documented it in 2018 with the LoJax toolchain, the first case in the wild where the full set of tools was found next to the implant.
How it works
The BIOS region of the flash is protected by settings in the chipset, which ESET's LoJax white paper and CHIPSEC's common.bios_wp module describe:
| Protection | What it does | Weakness when misconfigured |
|---|---|---|
BIOSWE (BIOS Write Enable) in BIOS_CNTL | Must be 1 to write the BIOS region | If the firmware leaves it settable, any kernel code can set it |
BLE (BIOS Lock Enable) | Setting BIOSWE triggers a System Management Interrupt whose handler should clear it again | Useless if the firmware's handler does not clear it; and a race condition (VU#766164, "Speed Racer") lets writes through even when it does |
SMM_BWP (SMM BIOS Write Protect, EISS in newer chipsets) | The BIOS region is writable only while all cores run in System Management Mode | Closes the race; available from Intel's Platform Controller Hub chipsets on, and only if the firmware sets it |
Protected Ranges (PR0–PR4) | The SPI controller refuses writes to the ranges listed | Must cover the whole BIOS region; covering only the boot block leaves the rest writable |
FLOCKDN | Locks the SPI controller configuration, protected ranges included, until reset | If unset, code can rewrite the protected ranges |
| Flash descriptor permissions | Which regions the host may write | A writable descriptor lets software bypass the flash protections (CHIPSEC common.spi_desc) |
ESET stresses that these mechanisms are not enabled by default: the firmware must configure them. LoJax's writer read BIOS_CNTL and chose its path accordingly: write directly if BIOSWE was already set; set it if BLE was off; use the race condition if BLE was on but SMM_BWP off; give up if SMM_BWP was set. ESET concluded that the victim's firmware had not configured its protections, or the chipset predated the Platform Controller Hub, and that the tool would not have succeeded on a properly configured modern system.
A successful write is not the end of the defences. Intel Boot Guard verifies the initial boot block before the CPU runs it, with keys and policies in fuses (Intel); a modified image then fails to boot, provided the change falls in the code that the verification covers. ESET wrote that Boot Guard, configured, would have refused LoJax's modified firmware.
How families use it
| Family | Tools and driver | What was written | Source |
|---|---|---|---|
| LoJax | info_efi.exe logs platform settings; ReWriter_read.exe creates a service for RwDrv.sys, the signed driver of the free RWEverything utility, logs BLE, BIOSWE and SMM_BWP, and dumps the flash to image.bin; ReWriter_binary.exe writes the patched image back, dumps it again to compare, sets BootExecute and uninstalls the RwDrv service | A DXE volume with the SecDxe driver added and the vendor's NtfsDxe removed (adding a DXE driver) | ESET |
MoonBounce and CosmicStrand also changed SPI flash, but the reports do not say how; Kaspersky and Binarly list remote access, physical access or unprotected flash as possibilities. They are not linked to this technique.
Traces it leaves
| Where | What | Source |
|---|---|---|
| System event log | Event 7045: a new kernel driver service, for RwDrv.sys in LoJax's case | ESET (service), Windows |
| File system | The driver file, the tools, a dumped image (image.bin), a log of platform settings | ESET |
| Prefetch, Amcache | Execution of the tools | General Windows artifacts |
| SYSTEM hive | Little: the service is uninstalled after the write, so it is gone from Services | ESET |
| SPI flash | The modified firmware (adding a DXE driver, patching a module) | ESET |
| Platform state | BIOSWE, BLE, SMM_BWP or protected ranges left open; the condition, not proof of a write | CHIPSEC |
| TPM event log, PCR 0 | A changed firmware measurement at the next boot, if logs are kept | General Measured Boot behaviour |
LOLDrivers lists RwDrv.sys as a vulnerable driver; other utility drivers with physical memory and I/O access can serve the same purpose.
How to check a host
Was a write possible? From a trusted Linux live medium:
sudo chipsec_main -m common.bios_wp
sudo chipsec_main -m common.spi_lock
sudo chipsec_main -m common.spi_desc
sudo chipsec_main -m common.bios_smi
fwupdmgr security
common.bios_wp checks BIOSWE, BLE, SMM_BWP and whether the protected ranges cover the BIOS region; common.spi_lock checks FLOCKDN; common.spi_desc that the descriptor is read-only; common.bios_smi that the SMI settings the lock relies on are locked. fwupd reports the same bits as its HSI attributes org.fwupd.hsi.Spi.Bioswe, Spi.Ble and Spi.SmmBwp, and the Boot Guard state (fwupd HSI). Avoid installing CHIPSEC's Windows driver on a suspect host: it needs driver signature checks off.
Was a write made? On the Windows side, offline: System log event 7045 for unknown kernel driver services, Amcache and Prefetch for the tools, and any .sys file with raw hardware access outside a known product. On the firmware side, dump the flash and compare it with the vendor's image, as in adding a DXE driver.
What these cannot prove: open protections show that a write was possible, not that one happened. Closed protections today do not show the state when the write happened: a firmware update may have fixed them since. A service that was created and removed leaves its event in the System log only while the log keeps it.
What the checker looks for
None of the checker's modules can see this technique, so checks is empty. It reads no chipset registers, and the firmware it changes is in the SPI flash, not in any file of a collection.
espandbootsectorare not involved.measuredbootdoes not compare PCR 0 between boots, so a rewritten flash raises nothing.
The Windows traces belong to the sister checker. rootkits.dev reads driver services, .sys files, Amcache and the System log: a 7045 event naming RwDrv.sys, or a leftover copy of a driver LOLDrivers lists as vulnerable, shows there. See its BYOVD technique page.
Mitigation and recovery
Prevent:
- keep firmware up to date and confirm that it sets the write protections (
BLE,SMM_BWP, protected ranges covering the BIOS region,FLOCKDN); ESET recommends CHIPSEC for this, and platforms with a Platform Controller Hub chipset, whereSMM_BWPexists; - block known vulnerable drivers: Microsoft's vulnerable driver blocklist and memory integrity (HVCI) on Windows, as covered on rootkits.dev;
- prefer platforms with Intel Boot Guard, which Intel describes as verifying the boot block from keys in fuses, or BIOS Guard, which restricts flash writes to an authenticated module (Intel);
- limit administrator rights: loading a driver needs them.
Recover: if the flash was written, follow adding a DXE driver: dump, compare, reflash the whole BIOS region from a trusted environment or replace the board, then reinstall the operating system and remove the tools and driver. Close the protections, with a firmware update if needed, before the host goes back into service.
Sources
Primary public reports, newest first.
- 2024-11-15Intel vPro Security OverviewIntel
- 2019-07-02LoJax (S0397)MITRE ATT&CK
- 2018-09-27LOJAX: First UEFI rootkit found in the wild, courtesy of the Sednit group (white paper)ESET
- 2018-09-27LoJax: First UEFI rootkit found in the wild, courtesy of the Sednit groupESET
- 2015-01-05Intel BIOS locking mechanism contains race condition that enables write protection bypass (VU#766164)CERT/CC
See also
Related techniques
- Adding a DXE driver to the firmwarePersisting in the boot chain
- Patching an existing firmware modulePersisting in the boot chain
Families that use it
- LoJaxFirmware implant