Taking over the boot
Hooking the UEFI Hand-over to the OS: Traces and Checks
How bootkits hook ExitBootServices, OslArchTransferToKernel and GRUB to patch the kernel in memory, why the disk stays clean, and what Measured Boot can show.
- Goal
- Taking over the boot
- Layer
- Boot
- Where it acts
- In memoryOn the boot chain map
- Platforms
- Windows, Linux
- Also known as
- boot services hooking, OS loader hooking
- Checked by
- None: no module reads its traces
Overview
A bootkit that runs before the operating system still has to reach the operating system: its payload is a kernel driver, a kernel patch or an injected process, and none of those exist yet when the firmware or the boot manager runs. The answer, in every UEFI family in this catalogue, is to follow the boot in memory. Each stage hooks the code that starts the next one, waits until the next stage is loaded but not yet running, patches it, and repeats, until the kernel starts with the bootkit's code inside it.
The critical point is the hand-over: the moment the OS loader has loaded the kernel and its boot drivers, the firmware's boot services are about to be shut down with ExitBootServices, and the loader jumps to the kernel. On Windows the jump is made by OslArchTransferToKernel in winload.efi. ESET describes this point, for BlackLotus, as the moment when the kernel and some drivers are loaded but not yet executing. A hook there gives the bootkit the kernel image before any kernel defence (code integrity, PatchGuard, security drivers) has run.
The technique works at the boot layer whether the bootkit itself lives in a file on the EFI system partition (ESP) or in firmware. It is the UEFI counterpart of the BIOS-era INT 13h hook, which patched the Windows loader as it was read from disk.
How it works
The UEFI boot, reduced to what matters here:
| Stage | Runs from | What a hook there gives the bootkit |
|---|---|---|
| DXE drivers, boot services | Firmware in SPI flash | Control over memory allocation, protocols and events, including ExitBootServices, for everything that follows |
| Windows Boot Manager, shim, GRUB | ESP | The next loader in memory after it is read and verified |
OS loader (winload.efi) or the kernel's EFI stub | OS volume, ESP | The kernel image in memory, before it runs (OslArchTransferToKernel on Windows) |
| Kernel | Memory | A function patched to run the bootkit's driver or shellcode on first use |
Two properties make this hard to see:
- Nothing changes on disk. Each file is read, verified by Secure Boot or the loader, and measured into the TPM as it is; the patch is applied to the copy in memory afterwards. Kaspersky states that MoonBounce's chain leaves no traces on the hard drive and that CosmicStrand never modifies the boot manager or loader files. When the bootkit itself lives in firmware, reinstalling Windows or replacing the disk changes nothing.
- Hooks remove themselves. MoonBounce removes its
ExAllocatePoolhook after first use, and CosmicStrand restores the original bytes ofZwCreateSectionbefore running its shellcode, according to Kaspersky. A memory image taken later may show the payload but not the path it took.
Kernel defences are often the first target. ESPecter patches the kernel's code integrity initialisation to switch Driver Signature Enforcement off for that boot; CosmicStrand patches KiFilterFiberContext so PatchGuard does not start; Bootkitty patches the Linux kernel's module_sig_check so unsigned modules load. See turning off driver signing from the boot chain.
How families use it
| Family | Starts from | Hooks named in the reports | In the kernel | Source |
|---|---|---|---|---|
| CosmicStrand | Patched CSMCORE DXE driver (firmware) | HandleProtocol boot service; Archpx64TransferTo64BitApplicationAsm in the Boot Manager; OslArchTransferToKernel in the OS loader | Code in the slack of ntoskrnl.exe's .text; ZwCreateSection diverted; KiFilterFiberContext patched | Kaspersky |
| MoonBounce | Patched CORE_DXE (firmware) | Inline hooks on AllocatePool, CreateEventEx, ExitBootServices; end of OslArchTransferToKernel patched | ExAllocatePool hooked once; a driver mapped without a file | Kaspersky, Binarly |
| ESPecter | Patched bootmgfw.efi (ESP) | BmFwVerifySelfIntegrity patched; Archpx64TransferTo64BitApplicationAsm detoured; OslArchTransferToKernel detoured | SepInitializeCodeIntegrity patched to disable Driver Signature Enforcement; MiComputeDriverProtection patched | ESET |
| FinSpy UEFI bootkit | Replaced bootmgfw.efi (ESP) | The original Boot Manager patched in memory; the OS loader function that transfers execution to the kernel patched (Kaspersky does not name it) | PsCreateSystemThread hooked; a new thread decrypts the next stage | Kaspersky |
| BlackLotus | Self-signed grubx64.efi started by shim (ESP) | ImgArchStartBootApplication in the Boot Manager; BlImgAllocateImageBuffer and OslArchTransferToKernel in winload.efi | Entry point of disk.sys hooked to start its driver early; Defender's WdBoot.sys and WdFilter.sys patched | ESET |
| Bootkitty | Self-signed grubx64.efi started by shim (ESP) | With Secure Boot on, EFI_SECURITY2_ARCH_PROTOCOL.FileAuthentication and EFI_SECURITY_ARCH_PROTOCOL.FileAuthenticationState made to report success; GRUB's start_image and grub_verifiers_open hooked | Kernel decompression hooked: module_sig_check always passes, init started with LD_PRELOAD=/opt/injector.so, banner set to BoB13 | ESET |
Traces it leaves
| Where | What | Notes |
|---|---|---|
| Disk | Nothing from the hooks themselves | The carrier may be on disk: a changed ESP file (ESPecter, FinSpy, BlackLotus, Bootkitty) or nothing at all (CosmicStrand, MoonBounce) |
| Measured Boot log | The carrier's digest, if it is an ESP file; Secure Boot state; Windows' boot settings as configured | The in-memory patches are made after measurement and do not appear |
| Memory | Patched boot and kernel functions named above; kernel code outside any loaded module; injected user-mode stagers | Hooks may already be gone |
| Kernel behaviour | Driver Signature Enforcement or PatchGuard off on Windows; an unexpected taint, BoB13 in uname -v, LD_PRELOAD in PID 1's environment on Linux | ESPecter, CosmicStrand, Bootkitty |
| Network | The payload's command-and-control traffic | Usually the first sign responders see |
What Measured Boot can and cannot show. Each stage measures the next before running it (Reading Measured Boot logs). The log therefore shows a replaced or patched boot file by its digest and a boot with Secure Boot off. It does not show a patch made in memory after the measurement. Windows' SIPA events record the boot settings the loader read, so a code integrity patch made later in kernel memory leaves CodeIntegrity as configured. Where the bootkit is in firmware, the boot applications are measured with their genuine digests; only the firmware's own PCR 0 measurement may differ between boots. That firmware measures itself, so without the vendor's reference values a changed PCR 0 says "different", not "malicious".
How to check a host
- Find the carrier. For ESP bootkits, check the ESP as in replacing or patching the ESP boot manager. For firmware bootkits, dump the SPI flash from trusted media and compare it with the vendor's image (patching an existing firmware module).
- Compare boots. Decode the Measured Boot logs and compare boot applications, digests and PCR 0 events between a boot before and after the suspected date.
- Memory. A memory image is the only place the hooks or their results can be seen on a running Windows host. Compare kernel code in the image with
ntoskrnl.exeon disk at the functions the reports name, and look for executable kernel memory that belongs to no loaded module. This is manual work in a memory analysis tool or a debugger; the reports name the functions, not a ready-made detection. On Linux, the checks ESET gives for Bootkitty work live:
uname -v
cat /proc/sys/kernel/tainted
sudo cat /proc/1/environ | tr '\0' '\n' | grep LD_PRELOAD
What a live check cannot prove: the bootkit runs before the kernel and patches it, so the kernel's own answers, security products included, may already be wrong. With PatchGuard disabled, the usual Windows integrity alarms may stay silent. A clean memory image after the hooks have removed themselves does not clear the host.
What the checker looks for
None of the checker's modules can see the hooks, so checks is empty for this technique. They exist only in memory, during a boot.
espsees the carrier when it is a file on the ESP: a patched or replaced boot manager, a self-signed loader. Those findings belong to replacing or patching the ESP boot manager.measuredbootrecords what was measured before each hand-over, not what was patched after it. It raises "Secure Boot was off during this boot" and the boot application findings for the carrier, and nothing for a hook. It does not compare firmware (PCR 0) measurements between boots.bootsectoris not involved on UEFI systems.
Firmware carriers leave the checker nothing: see what an offline bootkit check can and cannot prove.
Mitigation and recovery
Prevent by denying the bootkit its starting point, since the hooks cannot be blocked once it runs:
- keep Secure Boot on, with a firmware password, and apply
dbxand boot manager revocations, so an ESP carrier cannot start; - for firmware carriers, rely on BIOS write protection, Intel Boot Guard or an equivalent hardware root of trust, and firmware updates;
- on Secured-core PCs, Microsoft's System Guard Secure Launch (DRTM) reduces how much early firmware Windows must trust to protect virtualization-based security (Microsoft); the family reports do not say whether it would have stopped these chains.
Recover: remove the carrier (rebuild the ESP, or reflash the firmware and confirm with a new dump), then reinstall the operating system. Kernel code ran at every boot with signature checks or PatchGuard off, so nothing on the installed system can be trusted. Rotate the credentials used on the host.
Sources
Primary public reports, newest first.
- 2024-11-27Bootkitty: Analyzing the first UEFI bootkit for LinuxESET
- 2023-03-01BlackLotus UEFI bootkit: Myth confirmedESET
- 2022-07-25CosmicStrand: the discovery of a sophisticated UEFI firmware rootkitKaspersky
- 2022-01-20Technical details of MoonBounce's implementationKaspersky
- 2021-10-05UEFI threats moving to the ESP: Introducing ESPecter bootkitESET
- 2021-09-28FinSpy: unseen findingsKaspersky
See also
Related techniques
- Replacing or patching the ESP boot managerPersisting in the boot chain
- Patching an existing firmware modulePersisting in the boot chain
- Hooking the BIOS disk service (int 13h)Taking over the boot
- Turning off driver signing from the boot chainTaking over the boot
Families that use it
- BlackLotusUEFI bootkit
- BootkittyUEFI bootkit
- CosmicStrandFirmware implant
- ESPecterUEFI bootkit
- FinSpy UEFI bootkitUEFI bootkit
- MoonBounceFirmware implant