Getting past Secure Boot
Attacker Keys in Shim's MOK List: Traces and Checks
How BlackLotus and Bootkitty enrolled their own certificate in shim's MokList so Secure Boot trusts a self-signed bootkit, where it shows, and how to remove it.
- Goal
- Getting past Secure Boot
- Layer
- Boot
- Where it acts
- UEFI variablesEFI system partitionOn the boot chain map
- Platforms
- Windows, Linux
- Also known as
- MOK abuse, MokList enrollment
- Used by
- BlackLotusBootkitty
- Checked by
- EFI system partitionMeasured Boot logs
Overview
Shim is the small first-stage loader that lets Linux boot with Secure Boot on. Microsoft signs it through its third-party UEFI CA, which most PCs trust, and shim in turn verifies the next loader, normally GRUB, against keys it carries and against the Machine Owner Key (MOK) list. The MOK list exists so that a machine's owner can trust their own kernels and modules without changing the firmware's db. Adding a key is meant to require someone at the console: the request is made from the operating system, and shim's MokManager asks for confirmation at the next boot.
This technique writes the attacker's certificate straight into that list. From then on, Microsoft-signed shim loads a bootkit signed with the attacker's self-signed key, and every file the firmware itself checks is properly signed. Secure Boot stays on and a "Secure Boot enabled" check passes. Shim runs on Windows machines too: firmware that trusts Microsoft's third-party CA will start it from any path, including the Windows boot manager's.
The technique sits at the boot layer and needs a way in first. ESET notes that MokList is a boot-only NVRAM variable, so it cannot be written from the running operating system, and that changing it on a system with Secure Boot on requires physical access. Both catalogue families got around that with an exploit that ran their code before ExitBootServices, while boot-only variables are still writable. Public reporting dates the technique to BlackLotus, described in March 2023.
How it works
Shim's variables, from its MokVars.txt:
| Variable | Contents | Who can read or write it |
|---|---|---|
MokList | Authorized keys and hashes (an EFI_SIGNATURE_LIST) | Boot services only, non-volatile |
MokListRT | A copy of MokList made available to the kernel at runtime | Recreated by shim at each boot; what mokutil reads |
MokListX, MokListXRT | Forbidden keys and hashes, and their runtime copy | As above |
MokNew | Keys the OS asks to add, pending confirmation in MokManager | Written by mokutil --import |
MokSBState | When set, shim switches to insecure mode | Boot services only |
The normal path is mokutil --import, which writes a request to MokNew; at the next boot MokManager asks for the password set with the request before enrolling anything. The attack skips that path and writes MokList itself, which only code running before ExitBootServices can do.
The resulting chain, with Secure Boot on:
| Step | Signed by | Checked by | Result |
|---|---|---|---|
| shim at the boot path | Microsoft third-party UEFI CA | Firmware, against db | Accepted |
Bootkit as grubx64.efi | Attacker's self-signed certificate | shim, against MokList | Accepted, because the attacker's certificate is enrolled |
| Original loader | Microsoft or the distribution | The bootkit | Started, after the bootkit has set its hooks |
Because the key lives in firmware NVRAM, it survives reinstalling the operating system, reformatting the disk and replacing the disk. Revoking the vulnerable boot manager afterwards does not remove it either: ESET notes that BlackLotus keeps working if Microsoft's revocations are applied after the key is enrolled.
How families use it
| Family | How the key got in | What it trusts | Source |
|---|---|---|---|
| BlackLotus | During installation, code running through CVE-2022-21894 (Secure Boot rollback) enrolls the attacker's certificate in MokList. ESET gives its subject CN as "When They Cry CA" | \EFI\Microsoft\Boot\grubx64.efi, the bootkit, loaded by shim placed at bootmgfw.efi | ESET |
| Bootkitty | Binarly found that logofail.bmp, found alongside the samples, exploits LogoFAIL (CVE-2023-40238) in Insyde firmware; its shellcode writes MokList with a certificate matching the one on bootkit.efi (LogoFAIL). ESET's own report says only that the bootkit cannot run with Secure Boot on unless the attacker's certificates are installed | /EFI/ubuntu/grubx64.efi, the bootkit, loaded by Ubuntu's shim | Binarly, ESET |
Traces it leaves
| Where | What | Source |
|---|---|---|
NVRAM MokList, runtime copy MokListRT | An enrolled certificate nobody on the team added | ESET, Binarly |
| ESP | A self-signed loader where shim looks for GRUB; on Windows, a shim at \EFI\Microsoft\Boot\bootmgfw.efi | ESET, Microsoft |
| TPM event log, PCR 14 | Shim extends MokList, MokListX and MokSBState when set (shim README.tpm), so an added key changes this measurement | shim |
| TPM event log, PCR 7 | When shim accepts an image because of a MOK certificate, it extends that certificate, logged as MokListRT | shim |
| TPM event log, PCR 4 | Shim and the loaders it starts, as boot applications; Microsoft reports grubx64.efi and winload.efi here for BlackLotus | Microsoft, shim |
| Linux kernel log | At each boot the kernel reports Loading X.509 certificate: UEFI:MokListRT and the name of each certificate it loads (load_uefi.c, digsig.c) | Linux kernel |
On a Windows-only machine, shim has no reason to run, so any shim measurement in the TCG logs, or a MokListRT variable at all, deserves an explanation.
How to check a host
Linux, live:
mokutil --sb-state
mokutil --list-enrolled
mokutil --list-new
ls /sys/firmware/efi/efivars/ | grep -i '^Mok'
sudo journalctl -k -b | grep -i 'X.509'
--list-enrolled prints the certificates in MokListRT; compare each with what the organisation enrolled (distribution keys for DKMS or vendor drivers are common and legitimate). --list-new shows a pending request. The kernel log lines name the certificates loaded at this boot; saved journals or kern.log files give the same list for earlier boots, which dates a new key.
Windows. Windows has no built-in tool for shim's variables. Boot a trusted Linux live medium through its own shim, which recreates MokListRT from MokList, and run mokutil --list-enrolled there; ESET's removal advice uses mokutil the same way.
Offline. Read the Measured Boot logs (Reading Measured Boot logs): shim in PCR 4, the certificate logged as MokListRT in PCR 7, and the PCR 14 measurement compared across boots. Check the ESP for a self-signed second-stage loader (How to check the EFI system partition offline).
What these cannot prove: mokutil reads the runtime copy that the booted shim created, from a system the bootkit may already control. A clean list on an infected boot is possible in principle; reading it from trusted media is stronger. The logs are files that an administrator can edit, and a Linux log covers only the boot it was saved in.
What the checker looks for
The checker cannot read NVRAM, so it never sees MokList itself. It sees the files the key makes bootable, and some of the measurements:
espraises "A self-signed signature on" a loader: high in the Windows boot folder and on the fallback path, linked to BlackLotus for\EFI\Microsoft\Boot\grubx64.efi; medium in a Linux distribution folder when the signing certificate is itself self-signed, as with Bootkitty. On Windows, "The Windows Boot Manager is not signed by a Windows production CA" flags a shim sitting atbootmgfw.efi.measuredbootraises "was started from the Windows boot folder" forgrubx64.efiandwinload.efi. Each boot's detail sheet lists the certificates named by the PCR 7 authority events. A certificate shim logged from the MOK list appears there, by certificate name or asMokListRT, under a field labelled fordbentries and without a finding. The PCR 14 events shim logs asMokList,MokListXandMokSBStateappear by name among the EV_IPL measurements, without their digests and without a comparison between boots; the module compares boots only for Windows logs.
Mitigation and recovery
Prevent:
- the MOK list is only as safe as the code that runs before
ExitBootServices: apply Microsoft's boot manager revocations (KB5025885) and the firmware vendor's LogoFAIL updates; - on Windows-only machines, remove the Microsoft third-party UEFI CA from the Secure Boot configuration where nothing needs it; Microsoft says this blocks BlackLotus from working, since shim no longer starts;
- keep an inventory of the MOK keys each Linux build should carry, and compare it with
mokutil --list-enrolledfrom your management tooling; - set a firmware administrator password.
Recover:
- Preserve the ESP, the Measured Boot logs and the
mokutil --list-enrolledoutput. - Remove the attacker's certificate:
mokutil --deletewith the certificate file, ormokutil --reset, then confirm at the MokManager prompt on the next boot. This needs someone at the console. - Rebuild the ESP and the operating system: the bootkit ran with control of the kernel.
- Reinstalling alone is not enough. The key survives a disk wipe, and until it is removed, any loader the attacker signs will still boot.
Sources
Primary public reports, newest first.
- 2024-11-29LogoFAIL Exploited to Deploy Bootkitty, the first UEFI bootkit for LinuxBinarly
- 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
See also
Related techniques
- Rollback to a vulnerable signed boot managerGetting past Secure Boot
- Firmware image parser exploits (LogoFAIL)Getting past Secure Boot
- Replacing or patching the ESP boot managerPersisting in the boot chain
Families that use it
- BlackLotusUEFI bootkit
- BootkittyUEFI bootkit