Skip to content

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
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:

VariableContentsWho can read or write it
MokListAuthorized keys and hashes (an EFI_SIGNATURE_LIST)Boot services only, non-volatile
MokListRTA copy of MokList made available to the kernel at runtimeRecreated by shim at each boot; what mokutil reads
MokListX, MokListXRTForbidden keys and hashes, and their runtime copyAs above
MokNewKeys the OS asks to add, pending confirmation in MokManagerWritten by mokutil --import
MokSBStateWhen set, shim switches to insecure modeBoot 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:

StepSigned byChecked byResult
shim at the boot pathMicrosoft third-party UEFI CAFirmware, against dbAccepted
Bootkit as grubx64.efiAttacker's self-signed certificateshim, against MokListAccepted, because the attacker's certificate is enrolled
Original loaderMicrosoft or the distributionThe bootkitStarted, 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

FamilyHow the key got inWhat it trustsSource
BlackLotusDuring 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.efiESET
BootkittyBinarly 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 shimBinarly, ESET

Traces it leaves

WhereWhatSource
NVRAM MokList, runtime copy MokListRTAn enrolled certificate nobody on the team addedESET, Binarly
ESPA self-signed loader where shim looks for GRUB; on Windows, a shim at \EFI\Microsoft\Boot\bootmgfw.efiESET, Microsoft
TPM event log, PCR 14Shim extends MokList, MokListX and MokSBState when set (shim README.tpm), so an added key changes this measurementshim
TPM event log, PCR 7When shim accepts an image because of a MOK certificate, it extends that certificate, logged as MokListRTshim
TPM event log, PCR 4Shim and the loaders it starts, as boot applications; Microsoft reports grubx64.efi and winload.efi here for BlackLotusMicrosoft, shim
Linux kernel logAt 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:

  • esp raises "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 at bootmgfw.efi.
  • measuredboot raises "was started from the Windows boot folder" for grubx64.efi and winload.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 as MokListRT, under a field labelled for db entries and without a finding. The PCR 14 events shim logs as MokList, MokListX and MokSBState appear 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-enrolled from your management tooling;
  • set a firmware administrator password.

Recover:

  1. Preserve the ESP, the Measured Boot logs and the mokutil --list-enrolled output.
  2. Remove the attacker's certificate: mokutil --delete with the certificate file, or mokutil --reset, then confirm at the MokManager prompt on the next boot. This needs someone at the console.
  3. Rebuild the ESP and the operating system: the bootkit ran with control of the kernel.
  4. 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.

  1. 2024-11-29LogoFAIL Exploited to Deploy Bootkitty, the first UEFI bootkit for LinuxBinarly
  2. 2024-11-27Bootkitty: Analyzing the first UEFI bootkit for LinuxESET
  3. 2023-04-11Guidance for investigating attacks using CVE-2022-21894: The BlackLotus campaignMicrosoft
  4. 2023-03-01BlackLotus UEFI bootkit: Myth confirmedESET

See also

Related techniques

Families that use it