Persisting in the boot chain
Boot Manager Replacement on the ESP: Traces and Checks
How UEFI bootkits replace or patch bootmgfw.efi, GRUB or the fallback loader on the EFI system partition, the traces this leaves, and how to check a host.
- Goal
- Persisting in the boot chain
- Layer
- Boot
- Where it acts
- EFI system partitionOn the boot chain map
- Platforms
- Windows, Linux
- ATT&CK
- T1542.003
- Also known as
- ESP bootkit, boot loader replacement
- Checked by
- EFI system partitionMeasured Boot logs
Overview
On a UEFI computer the firmware does not run code from the first sector of the disk. It reads a boot entry from its NVRAM, which names a file on the EFI system partition (ESP), and runs that file. On Windows the file is \EFI\Microsoft\Boot\bootmgfw.efi; on Linux it is a distribution's shim, which then runs GRUB; when no entry works, the firmware falls back to \EFI\BOOT\BOOTX64.EFI, the default path Microsoft's BCDBoot documentation cites. Whoever controls that file runs before the operating system, its kernel and every security product.
This technique replaces that file with the attacker's loader, or patches it in place. The bootkit runs first, then starts the genuine loader so the machine boots as usual, and follows the boot into memory from there (see hooking the hand-over to the OS). It works at the boot layer: the files are on the disk, and the firmware in the SPI flash is not touched. That makes it easier to deploy than a firmware implant, and easier to find. Writing to the ESP needs administrator or root rights, or physical access.
In October 2021 ESET called ESPecter only the second real-world bootkit persisting on the ESP, after Kaspersky's FinSpy bootkit. It is the UEFI successor of MBR infection.
How it works
Secure Boot is the obstacle. With it on, the firmware checks the Authenticode signature of each loader against the db and dbx databases, so a patched or attacker-built loader is refused. Every family that uses this technique therefore pairs it with a way past Secure Boot: Secure Boot already off (ESPecter, FinSpy), an attacker key trusted by shim (BlackLotus, Bootkitty; see enrolling an attacker key in shim's MOK list), or an exploit.
The public reports show three shapes:
| Shape | What changes on the ESP | Who starts the genuine loader | Signature of the file at the boot path |
|---|---|---|---|
| Replace and rename | The loader at the expected path is replaced; the original is kept under another name or in another folder | The bootkit, which loads the renamed original | Unsigned, self-signed, or another signer's |
| Patch in place | A section is added to the loader and its entry point moved there | The patched loader itself, once the added code has run | Present but broken: the digest no longer matches |
| Chain through a signed loader | A legitimately signed loader takes the path and loads the bootkit under a name it expects | The bootkit, after that loader has started it | Valid, but from the wrong signer for that path |
In each catalogue case the bootkit took a path the existing boot chain already loads, so the firmware's boot entry did not need to change. Several things then hide it. Windows gives the ESP no drive letter and most triage collections skip it. The files keep familiar names. The user sees a normal boot, because the original loader runs at the end. And once the kernel runs, the bootkit's own driver may guard the files: ESET reports that BlackLotus's driver holds handles on its ESP files so they cannot be changed or deleted.
How families use it
| Family | What it does on the ESP | Source |
|---|---|---|
| BlackLotus | Puts Microsoft's shim (signed by the third-party UEFI CA) at \EFI\Microsoft\Boot\bootmgfw.efi, adds the self-signed bootkit as grubx64.efi in the same folder, and keeps the original boot manager there as winload.efi | ESET, Microsoft |
| ESPecter | Patches \EFI\Microsoft\Boot\bootmgfw.efi and the fallback \EFI\Boot\bootx64.efi in place: a new section named .efi, the entry point moved into it; the signature no longer verifies, so it needs Secure Boot off | ESET |
| FinSpy UEFI bootkit | Replaces bootmgfw.efi with its loader and keeps the original boot manager, plus two RC4-encrypted components, in \EFI\Microsoft\Boot\en-us\ under hexadecimal names | Kaspersky |
| Bootkitty | Sits at /EFI/ubuntu/grubx64.efi, where shim expects GRUB, with the real GRUB moved to grubx64-real.efi; self-signed, so it runs only with Secure Boot off or its certificate enrolled | ESET |
Traces it leaves
| Where | What to look for | Seen with |
|---|---|---|
Boot path files (bootmgfw.efi, bootx64.efi, grubx64.efi) | A signer that does not fit the path; no signature; a digest that does not match the signature; an extra section holding the entry point | All four |
| Files beside them | Names Windows never puts in \EFI\Microsoft\Boot\ (grubx64.efi, winload.efi, BCDR), hexadecimal names in a language folder, grubx64-real.efi in a distribution folder | BlackLotus, FinSpy, Bootkitty |
| File times on the ESP | Boot files much newer than their neighbours, or than the copies in C:\Windows\Boot\EFI | Microsoft's BlackLotus guidance |
| Measured Boot logs | New or changed boot applications in PCR 4; Secure Boot measured as off in PCR 7 | BlackLotus (Microsoft); ESPecter and FinSpy need Secure Boot off |
| Live host | A sharing violation when hashing ESP boot files | BlackLotus (Microsoft) |
| Firmware NVRAM | An attacker certificate in MokList; not on the disk | BlackLotus, Bootkitty |
The replaced or patched file is the durable trace. Hashes from the reports describe single samples, and FinSpy's encrypted files differ on every disk, so the layout matters more than an IOC match.
How to check a host
Offline. Image the ESP, so that deleted directory entries survive, or at least copy all of it. For every .efi file, read its Authenticode signer, recompute its digest and compare it with what belongs at that path: the Windows Boot Manager is signed through Microsoft's Windows chain, shim through Microsoft's third-party UEFI CA, GRUB by the distribution. Compare the Windows boot folder with C:\Windows\Boot\EFI, and a Linux distribution folder with the package copies in /usr/lib/shim/ and /usr/lib/grub/x86_64-efi-signed/. List files that should not be there and compare file times within each folder. Then read the Measured Boot logs (C:\Windows\Logs\MeasuredBoot\ or a saved binary_bios_measurements) for each boot's applications and Secure Boot state. The full collection steps are in How to check the EFI system partition offline and Reading Measured Boot logs.
Live, Windows, elevated:
mountvol S: /S
powershell -c "Get-ChildItem S:\EFI -Recurse -Force -Include *.efi | Get-AuthenticodeSignature | Format-List Path, Status, SignerCertificate"
powershell -c "Get-ChildItem S:\EFI\Microsoft\Boot -Force | Format-Table Name, Length, LastWriteTime"
bcdedit /enum firmware
mountvol S: /D
Live, Linux:
sudo efibootmgr -v
sudo ls -la /boot/efi/EFI/*/
sudo sbverify --list /boot/efi/EFI/ubuntu/grubx64.efi
sudo sha256sum /boot/efi/EFI/ubuntu/grubx64.efi /usr/lib/grub/x86_64-efi-signed/grubx64.efi.signed
mokutil --sb-state
What these cannot prove: a valid signature says who signed a file, not whether dbx has since revoked it (Secure Boot rollback). Windows updates rewrite the boot manager, so a new time or digest needs the update history beside it. And a live listing comes from a kernel the bootkit has already patched: an ESP copy read on another machine, or an image taken from trusted boot media, is the reliable check.
What the checker looks for
The esp module reads every EFI binary and BCD store on the partition and raises, depending on the shape:
- Patched in place: "The file was changed after it was signed", linked to ESPecter when the boot manager has an added
.efisection or its entry point in its last section; "The entry point is in an unusual section". - Replaced: "An unsigned EFI binary on a boot path" (high on the Windows boot manager and fallback paths, medium on a Linux loader path); "The Windows Boot Manager is not signed by a Windows production CA", linked to BlackLotus when the signer is Microsoft's third-party UEFI CA, as with a shim; "A self-signed signature on" a loader; "A certificate imitates a Microsoft UEFI CA".
- Files beside the loader: "does not belong in the Windows boot folder" for
grubx64.efi,winload.efi,BCDRor FinSpy's hexadecimal files; "is much newer than the other files in its folder" for an.efifile modified a week or more after its folder's median.
The measuredboot module reads Windows TCG logs and a saved Linux binary_bios_measurements. It raises "Secure Boot was off during this boot" and "Secure Boot was on in the previous boot and off in this one"; "was started from the Windows boot folder" for grubx64.efi or winload.efi (the BlackLotus pair); "A boot application outside the usual boot paths"; and, between two saved Windows boots, a new boot application path or "The digest of" a boot application "changed since the previous boot", a low finding because updates do the same.
Limits: the checker does not compare files with package or C:\Windows\Boot\EFI copies, so Bootkitty's renamed grubx64-real.efi, which keeps GRUB's valid signature, is listed without a finding. It checks no trust store, db, dbx or MOK list, and it cannot decrypt FinSpy's files.
Mitigation and recovery
Prevent:
- keep Secure Boot on and set a firmware administrator password, so it cannot be switched off from the setup screen;
- apply Microsoft's boot manager revocations (KB5025885) and firmware updates;
- on Windows-only machines that do not need it, remove the Microsoft third-party UEFI CA from the Secure Boot configuration, which Microsoft says blocks BlackLotus from working;
- limit administrator rights, which every one of these installers needs;
- keep the Measured Boot logs, so a change in the boot path leaves a record.
Recover:
- Preserve the ESP image, the Measured Boot logs and the BitLocker recovery key before changing anything.
- Rebuild the host from trusted media and recreate the ESP. Microsoft's advice for BlackLotus is to reformat both the OS partition and the ESP, or restore a clean backup that includes the ESP. Replacing the boot file from a clean copy removes the boot stage but not what the bootkit's kernel code did; treat it as a stopgap.
- Remove any attacker key from the MOK list (it lives in NVRAM and survives a disk wipe), and turn Secure Boot back on.
- Rotate the credentials used on the host: the bootkit ran with full control of it.
Sources
Primary public reports, newest first.
- 2024-11-27Bootkitty: Analyzing the first UEFI bootkit for LinuxESET
- 2023-04-11Guidance for investigating attacks using CVE-2022-21894: The BlackLotus campaignMicrosoft
- 2023-03-01BlackLotus UEFI bootkit: Myth confirmedESET
- 2021-10-05UEFI threats moving to the ESP: Introducing ESPecter bootkitESET
- 2021-09-30BCDBoot command-line optionsMicrosoft
- 2021-09-28FinSpy: unseen findingsKaspersky
See also
Related techniques
- Enrolling an attacker key in shim's MOK listGetting past Secure Boot
- Rollback to a vulnerable signed boot managerGetting past Secure Boot
- Hooking the UEFI hand-over to the OSTaking over the boot
- Replacing the MBR boot codePersisting in the boot chain
Families that use it
- BlackLotusUEFI bootkit
- BootkittyUEFI bootkit
- ESPecterUEFI bootkit
- FinSpy UEFI bootkitUEFI bootkit