Chapter 221

Firmware and Hardware Security

Firmware implants are the highest-persistence threat: they survive OS reinstall, disk wipe, and in some cases physical hardware replacement. They are also the highest-cost attack — firmware access typically requires a prior OS-level compromise or physical access. Detection requires out-of-band integrity checking (TPM PCR measurements, BMC logs) because once firmware is compromised, the OS cannot trust its own attestation. This chapter extends the UEFI bootkit coverage from ch198 with deeper hardware-layer attacks.

Scenario

A nation-state actor with SYSTEM access on a high-value server wants durable persistence that survives OS reimaging. The server has an Intel Xeon with IPMI-enabled BMC (Baseboard Management Controller) accessible on a management network. The attacker can reach the management network from their foothold. Goal: compromise the BMC, install a firmware-resident implant, and establish persistent out-of-band access.

UEFI Attack Surface — Extended

UEFI ATTACK SURFACE MAP ═══════════════════════════════════════════════════════════════════════ Physical / SPI: SPI flash chip holds UEFI firmware image → Direct SPI programmer (hardware) bypasses all software controls → Intel Flash Descriptor protects regions; ME region protected by Intel ME → Attack: modify BIOS region if write protection disabled (PR0 register) Operating System (OS → UEFI via Runtime Services): SetVariable(Authenticated/Non-Authenticated) → write NVRAM variables SetFirmwareEnvironmentVariable → modify boot entries (requires SE_SYSTEM_ENVIRONMENT_NAME) → Implant: add malicious UEFI module as boot option in NVRAM SMM (System Management Mode): Ring -2, above OS and hypervisor; SMRAM accessible only during SMI → SMBASE relocation attack (pre-modern) → overwrite SMRAM with SMM handler → SMM implant survives OS reload; can modify memory, disable Secure Boot check Intel ME / AMD PSP: Independent CPU attached to SPI flash; runs before UEFI → ME firmware update attack: flash malicious ME firmware via HECI interface → Almost impossible to detect from OS; very few public exploits PRACTICAL (OS-level) UEFI ATTACK FLOW: 1. OS compromise → SYSTEM 2. Disable driver signature enforcement: bcdedit /set nointegritychecks on OR: BYOVD → patch g_CiEnabled in ci.dll (ch197) 3. Load malicious UEFI module driver that calls RT→SetVariable 4. Add malicious EFI application as boot option → loads before bootmgfw.efi 5. Malicious app patches winload.efi or calls RT→SetVariable to insert next persistence ═══════════════════════════════════════════════════════════════════════

BMC and IPMI Attacks

// BMC (Baseboard Management Controller): independent processor on motherboard
// Provides: remote power control, KVM-over-IP, serial-over-LAN, iDRAC/iLO/IPMI
// Runs embedded Linux (BusyBox) on management network (dedicated NIC or shared)
// Default credentials are the #1 entry point: ADMIN/ADMIN, root/calvin, admin/password

// IPMI 2.0 cipher suite 0 (Rakp Auth bypass):
// ipmitool -I lanplus -H 192.168.1.100 -C 0 -U admin -P "" chassis status
// Cipher suite 0 = no-auth; if server supports it, no password needed

// IPMI password hash leak (CVE-2013-4786):
// RAKP2 message contains HMAC over password hash — attacker initiates auth,
// receives HMAC, can offline-crack password from HMAC
// Tool: ipmipwner or hashcat mode 7300 (IPMI2 RAKP)
// hashcat -m 7300 ipmi_hashes.txt rockyou.txt

// BMC compromise workflow:
// 1. Scan management network for IPMI port 623/UDP
// 2. Try default credentials or exploit cipher-0 or RAKP hash crack
// 3. Once authenticated: access BMC shell via SOL (Serial-Over-LAN)
//    ipmitool -I lanplus -H BMC_IP -U root -P PASSWORD sol activate
// 4. From BMC shell: modify UEFI NVRAM, replace firmware image, install backdoor
//    → Backdoor persists after complete OS reinstall

// BMC virtual media (remote mount):
// ipmitool -I lanplus -H BMC_IP -U admin -P PASS chassis bootdev cdrom
// → Boot target from attacker-controlled ISO image

// BMC firmware implant (theoretical, demonstrated by researchers):
// Flash malicious BMC firmware via vendor's firmware update mechanism
// Malicious BMC firmware: intercepts ipmitool commands, adds backdoor user,
// maintains persistent access regardless of BMC password reset

NIC Firmware Implants

// NIC firmware implants: malicious code flashed into network card firmware
// Demonstrated by NSA (ANT catalog): HALLUXWATER, JETPLOW for Cisco firmware
// Civilian equivalent: Thunderstrike-style for Macs, NSA-documented SWAP for Intel NICs

// PCI device DMA attack path (without firmware flash):
// 1. Malicious Thunderbolt device (or PCI device) → DMA access to host memory
// 2. Reads/writes RAM directly bypassing CPU: steal keys, patch OS code
// IOMMU (Intel VT-d / AMD-Vi) mitigates DMA attacks:
//    → Restricts which memory ranges each PCIe device can access
//    → Windows DMA Protection: enabled by default on modern devices with Secure Boot

// Network-bootable implant (less persistent, no firmware modification):
// BMC → configure PXE boot order first
// Attacker hosts malicious PXE server on management network
// → On each boot, loads attacker's pre-OS agent before Windows → stealth agent

// Detection for DMA attacks: IOMMU fault events in firmware/BMC logs
// Detection for PXE boot changes: compare boot order configuration against baseline

TPM and Measured Boot

// TPM (Trusted Platform Module): tamper-resistant chip that stores measurements
// PCR (Platform Configuration Register): accumulates SHA-256 hashes of boot components
// Measured Boot: each boot component extends the relevant PCR before execution:
//   PCR 0: UEFI firmware
//   PCR 7: Secure Boot state
//   PCR 11: BitLocker
//   PCR 13: bootmgfw.efi loaded modules

// Remote Attestation: TPM quotes PCR values → verifier checks against golden baseline
// If any boot component changed (UEFI modified, Secure Boot disabled) → PCR mismatch
// → Remote attestation server refuses to unseal keys → BitLocker won't unlock
// → This is how Measured Boot detects UEFI implants (BlackLotus defeated pre-patch Secure Boot)

// Reading PCR values (Windows):
Get-TpmEndorsementKeyInfo
Get-PcpDeviceInfo

// PowerShell: read PCR values via TSS.MSR or WMI
$tpm = Get-WmiObject -Namespace "root\CIMV2\Security\MicrosoftTpm" -Class Win32_Tpm
$tpm.GetPropertyNumericBigIntBinary(512)  # PCR 9

// Linux: tpm2_pcrread sha256:0,7,11,13

// Attestation-based detection: if golden PCR baseline is:
// PCR[0] = AABBCC...  (UEFI hash from known-good build)
// And current measurement shows different value → firmware modification detected
// Requires: out-of-band attestation service (not the compromised host itself)

Detection Engineering

title: UEFI / Secure Boot State Change Detected
logsource:
  product: windows
  service: microsoft-windows-kernel-boot
detection:
  selection:
    EventID: 22  # Boot status indicates Secure Boot disabled or bypass
  condition: selection
level: critical
tags: [attack.defense_evasion, T1542.001]

title: EFI System Partition Mounted in Userland
logsource:
  product: windows
  category: process_creation
detection:
  selection:
    Image|endswith: '\mountvol.exe'
    CommandLine|contains: '/s'
  condition: selection
level: critical

-- MDE KQL: NVRAM modification via SetFirmwareEnvironmentVariable
DeviceEvents
| where ActionType == "SecurityGroupCreated"
    or ActionType == "PrivilegeEscalation"
| where AdditionalFields has "SeSystemEnvironmentPrivilege"
| project Timestamp, DeviceName, InitiatingProcessFileName, AdditionalFields

-- MDE KQL: BCDEdit disabling recovery (ransomware/bootkit prep)
DeviceProcessEvents
| where FileName =~ "bcdedit.exe"
| where ProcessCommandLine has_any ("recoveryenabled","bootstatuspolicy","safeboot")
| project Timestamp, DeviceName, AccountName, ProcessCommandLine

Q&A

TPM-based Measured Boot is described as the definitive defense against UEFI implants. Yet BlackLotus (CVE-2022-21894) was able to bypass Secure Boot even on TPM-equipped systems before the 2023 patch. What was the specific mechanism that allowed this bypass, and what made it particularly difficult to patch?

BlackLotus exploited a vulnerability in the Windows Boot Manager (bootmgfw.efi) that was patched in January 2022 (CVE-2022-21894). The specific mechanism was a secure boot bypass in the Unified Extensible Firmware Interface (UEFI) Secure Boot validation for the bootmgfw.efi file: the vulnerability allowed an un-revoked but vulnerable version of bootmgfw.efi to be placed on the EFI System Partition, and Secure Boot would allow it to execute because the file had a valid Microsoft signature and had not yet been added to the UEFI revocation list (dbx). BlackLotus simply brought back the old, vulnerable version of bootmgfw.efi from before the January 2022 patch, placed it on the ESP, and Secure Boot allowed it to load.

The patch applied in January 2022 fixed the vulnerability in bootmgfw.efi, but the difficulty was that the fix required adding the old (pre-patch) bootmgfw.efi binaries to the UEFI Secure Boot revocation list (dbx). This was the hard part: the dbx update had to be distributed to every UEFI firmware in the world via a Windows Update mechanism that updates the UEFI dbx variable. If Microsoft revoked the old bootloaders immediately and broadly, it would break Windows boot on many machines that still had the old bootloaders installed — including machines with valid installations that hadn't yet updated. The revocation update was rolled out gradually starting in May 2023, and even after rollout, machines that had never installed the revocation update remained vulnerable: an attacker with ESP write access could still place the unrevoked old bootmgfw.efi and bypass Secure Boot.

The lesson for detection is that TPM PCR measurements detect this: if bootmgfw.efi was replaced with an older version, PCR[4] (which measures the boot application) will contain a different hash from the current expected value. Remote attestation against a current PCR baseline would catch this. However, most organizations do not have remote attestation infrastructure — they rely on Secure Boot as a preventive control, not a detection control. BlackLotus demonstrated that Secure Boot as a preventive control had a years-long window of vulnerability between the patch and the revocation dbx update, during which behavioral detection (anomalous ESP writes, bcdedit changes, loading of unsigned kernel modules) was the only viable detection path.