Persisting in the boot chain
Patching an Existing UEFI Firmware Module: Traces and Checks
How MoonBounce and CosmicStrand patched CORE_DXE and CSMCORE inside SPI flash firmware, why only a module-by-module diff finds it, and how to check and recover.
- Goal
- Persisting in the boot chain
- Layer
- Firmware
- Where it acts
- UEFI drivers (DXE)On the boot chain map
- Platforms
- Firmware
- ATT&CK
- T1542.001
- Also known as
- DXE module patching, firmware module infection
- Used by
- CosmicStrandMoonBounce
- Checked by
- None: no module reads its traces
Overview
Instead of adding a new driver to the firmware, the attacker changes one the vendor already ships. The module keeps its name, its GUID and its place in the firmware volume; only its contents differ. Extra code is appended to the module, and the module's entry point or some of the functions it provides are redirected to that code. At every boot the firmware runs the vendor's module as always, and the attacker's code with it.
It works at the firmware layer, in the SPI flash chip on the motherboard, and survives reinstalling the operating system and replacing the disk. Compared with adding a DXE driver, it is quieter: a list of firmware files, their names and GUIDs looks exactly like the vendor's. Only a comparison of each module's contents with the vendor's module of the same version shows it.
Both public cases are recent. Kaspersky described MoonBounce in January 2022, in the DXE Core itself, and CosmicStrand in July 2022, in a driver of the Compatibility Support Module, though it dates CosmicStrand's use to the end of 2016. In both, the patched module's job is to start a chain of in-memory hooks that reaches the Windows kernel (hooking the hand-over to the OS).
How it works
| Element | What changes | Effect |
|---|---|---|
| Module body | Code added after the last section (.reloc), as a new unnamed section or inside .reloc | The module grows; its hash changes |
| Entry point or services | The entry point is redirected to the added code, or inline hooks are placed at the start of functions the module provides | The added code runs every time the module does |
| Name, GUID, volume | Unchanged | A list of firmware files matches the vendor's |
| Rest of the image | Unchanged | Binarly's diff of MoonBounce found no other change |
The choice of module matters. The DXE Core (CORE_DXE) provides the boot services that every later driver and boot loader calls, so hooks there see the whole boot, including the call to ExitBootServices that ends firmware control. A widely loaded driver such as CSMCORE is a second option; Kaspersky reports that CosmicStrand's patch redirects the HandleProtocol boot service from it.
How the code got into the flash is unknown in both cases. Kaspersky assumes remote access for MoonBounce and thinks CosmicStrand's change was made with an automated patcher, which implies earlier access to the machine; Binarly lists physical access or flash left without write protection as possibilities. Writing from the operating system is covered in writing the SPI flash from the operating system.
As with an added driver, Secure Boot does not help: it checks the boot applications the firmware loads, not the firmware's own modules. A hardware root of trust such as Intel Boot Guard is what verifies the firmware image. Kaspersky said, answering a reader, that the MoonBounce machine supported neither Boot Guard nor a TPM.
How families use it
| Family | Patched module | What was added | Source |
|---|---|---|---|
| MoonBounce | CORE_DXE, the DXE Foundation (GUID {5AE3F37E-4EAE-41AE-8240-35465B5E81EB} in Binarly's diff); firmware name E7846IMS.M30, which Binarly matched to an MSI image of 2014 | Shellcode and a Windows driver in an unnamed section after .reloc; 5-byte call hooks at the start of AllocatePool, CreateEventEx and ExitBootServices | Kaspersky, Binarly |
| CosmicStrand | CSMCORE (GUID A062CF1F-8473-4AA3-8793-600BC4FFE9A8) in ASUS and Gigabyte boards with the Intel H81 chipset | Code in the .reloc section; the entry point leads to it, and it redirects HandleProtocol | Kaspersky |
Traces it leaves
| Where | What | Source |
|---|---|---|
| SPI flash, patched module | Larger than the vendor's module of the same version; an extra section or extra code after .reloc; an entry point or function starts that jump into it | Kaspersky, Binarly |
| SPI flash, module strings and header | The vendor's build identifiers kept (MoonBounce: E7846IMS.M30, a 2014 time stamp) | Binarly |
| Memory | The hooks and patches the chain applies at each boot | Kaspersky |
| Disk | Nothing from the implant; only what its payload does later (a local account aaaabbbb on one CosmicStrand machine; companion malware on the MoonBounce network) | Kaspersky |
| TPM event log, PCR 0 | A changed firmware measurement, if a log from before the change exists | General Measured Boot behaviour |
Kaspersky's published hashes (MoonBounce's CORE_DXE, CosmicStrand's CSMCORE) each describe one board's module. The same patch applied to another model's module hashes differently, so a hash miss proves nothing; the comparison has to be against the vendor's module.
How to check a host
- Identify the firmware. Note the board, BIOS version and date (on Windows,
Get-CimInstance Win32_BaseBoardandWin32_BIOS; on Linux,sudo dmidecode -t bios -t baseboard) and download the vendor's image for exactly that version. - Dump the flash from a trusted environment:
chipsec_util spi dump rom.binfrom a clean Linux live medium, or a hardware programmer on the chip. - Compare module by module. Decode both images with UEFITool or
chipsec_util decode rom.binand compare each module with the vendor's, or let CHIPSEC do it:
chipsec_main -i -n -m tools.uefi.scan_image -a generate,efilist.json,vendor.rom
chipsec_main -i -n -m tools.uefi.scan_image -a check,efilist.json,rom.bin
A DXE Core or driver that differs from the vendor's module at the same version is a finding by itself: only a firmware update should change it. Then look at the difference: module size, section table, entry point.
- Check the protections with
chipsec_main -m common.bios_wpandchipsec_main -m common.spi_lock, orfwupdmgr securityon Linux, to know whether the flash could have been written from the OS.
What these checks cannot prove: whole-file comparisons fail on every machine, because NVRAM variables, Management Engine data and serial numbers differ, so compare modules. A dump taken through the running platform depends on that platform; a hardware programmer does not. Without the vendor's image for the same version, a module diff is not possible, and a different BIOS version is a different baseline. And a clean flash today does not show what ran last month if the firmware has since been updated.
What the checker looks for
None of the checker's modules can see a patched firmware module, so checks is empty for this technique. The implant is in the SPI flash, and the boot files it later patches in memory keep their original bytes on disk.
esp: the boot files on the EFI system partition keep their genuine bytes and signatures.measuredboot: PCR 0 records the platform firmware's code (Microsoft). The module does not compare PCR 0 measurements between boots and holds no vendor reference values. Decoding two saved logs yourself, as in Reading Measured Boot logs, would show that the firmware changed, not why. The MoonBounce machine had no TPM, so no such log existed.bootsector: not involved.
See what an offline bootkit check can and cannot prove.
Mitigation and recovery
Prevent:
- keep BIOS write protection enabled and locked, and check it;
- buy platforms with Intel Boot Guard or an equivalent configured by the manufacturer, and a TPM;
- keep firmware updated;
- reflash second-hand boards with the vendor's image before use, as Kaspersky advised CosmicStrand readers;
- keep Measured Boot logs, so a firmware change leaves a record.
Recover:
- Preserve the flash dump and, if possible, a memory image.
- Reflash the whole BIOS region with the vendor's image from a trusted environment, then dump and compare again to confirm the patched module is gone. Kaspersky's answer for CosmicStrand was that reflashing is the only reliable removal and replacing the board the alternative; on a board without Boot Guard or a TPM, as with MoonBounce, replacement is the honest fallback.
- Reinstall the operating system: kernel code ran at every boot.
- Treat the network as compromised where the reports describe companion tools, as with MoonBounce.
Sources
Primary public reports, newest first.
- 2022-07-25CosmicStrand: the discovery of a sophisticated UEFI firmware rootkitKaspersky
- 2022-01-21A deeper UEFI dive into MoonBounceBinarly
- 2022-01-20MoonBounce: the dark side of UEFI firmwareKaspersky
- 2022-01-20Technical details of MoonBounce's implementationKaspersky
See also
Related techniques
- Adding a DXE driver to the firmwarePersisting in the boot chain
- Writing the SPI flash from the operating systemGetting past Secure Boot
- Hooking the UEFI hand-over to the OSTaking over the boot
Families that use it
- CosmicStrandFirmware implant
- MoonBounceFirmware implant