Taking over the boot
Int 13h Hooking: How BIOS Bootkits Patch Windows as It Loads
How legacy bootkits hook BIOS interrupt 13h to patch the Windows boot manager, loader and kernel in memory: TDL4, Gapz, Rovnix, and what is left to check.
- Goal
- Taking over the boot
- Layer
- Boot
- Where it acts
- In memoryOn the boot chain map
- Platforms
- Windows
- ATT&CK
- T1542.003
- Also known as
- INT 13h hook, BIOS disk interrupt hook
- Checked by
- None: no module reads its traces
Overview
On a BIOS machine, early boot code reads the disk through the firmware: BIOS interrupt 13h is the service for reading and writing sectors. The Windows boot manager and the OS loader use it to read their own files and the kernel before Windows has disk drivers of its own. A bootkit that has run first, from an infected MBR, VBR or IPL, replaces the int 13h handler with its own and passes every request on to the original. It now sees every sector the boot chain reads, and it patches the files in the read buffer before the caller sees them.
That is how a boot-sector infection becomes a kernel compromise. The files on disk are never changed: the boot manager, winload.exe, the kernel and the BCD stay intact and validly signed. Only the copy in memory carries the patches, and each patch sets the next hook, from real mode into the boot manager, the loader and the kernel. Kaspersky described the hook in TDL4 as being called "every time that the BIOS 13h interrupt is called".
Every legacy bootkit in this catalogue does it: TDL4, Gapz, Rovnix, the legacy version of ESPecter and the FinSpy MBR bootkit. ESET's Virus Bulletin 2014 paper traces modern bootkits back to eEye's BootRoot proof of concept (2005) and ties their return to the code signing policy of 64-bit Windows Vista. On UEFI machines the same idea moves to the firmware's boot services; see hooking UEFI boot services.
How it works
The sequence, as the reports describe it:
- Stay resident. The bootkit copies its code to memory that the Windows loader will not reuse. Kaspersky reports that FinSpy's MBR loads its code into "the highest available memory located before the EBDA" (the Extended BIOS Data Area) and hooks interrupt 15h as well, so that the Windows loader does not overwrite it: asked for the size of the memory before the EBDA, "the hook will reduce the amount of available memory".
- Take over int 13h. The bootkit points the interrupt at its own handler, then runs the original MBR or VBR code it saved, so the normal boot proceeds.
- Watch the reads. On each read request it checks what was read. ESET reports that ESPecter's handler looks at the sector-read services
0x02and0x42"to intercept loading of bootmgr"; Gapz identifiesntldr,bootmgrandwinload.exe"using special byte sequences"; TDL4's hook "scans each sector that was read" for the kernel debugger librarykdcom.dll. - Patch and chain. When the target arrives, the handler patches it in the buffer so the bootkit regains control after the processor leaves real mode. From there the chain continues in protected or long mode: ESET's Gapz paper lists hooks in
bootmgr, thenOslArchTransferToKernelinwinload.exe, thenIoInitSystemin the kernel, after which Gapz reads the rest of its code from disk and runs it in a new system thread.
The int 13h hook only matters while the boot code reads through the BIOS. Once the kernel's own disk drivers run, it sees nothing more, which is why every chain above sets later hooks and ends with kernel code of its own: a driver or code block loaded without the kernel's signature checks (see turning off driver signing from the boot chain).
How families use it
| Family | Where the hook comes from | What it patches as the boot reads it | Next stage | Source |
|---|---|---|---|---|
| TDL4 | ldr16, loaded by the infected MBR from the hidden store | Substitutes its own ldr32 / ldr64 when kdcom.dll is read; switches the boot configuration to Windows PE mode in memory | Fake kdcom.dll loads the rootkit driver | Kaspersky, 2011 |
| TDL4 (Olmasco variant) | The boot file, started by the VBR of TDL4's own partition | "Patch the BCD and OS bootloader" | The original active partition boots | ESET, 2011 |
| Gapz | Bootkit code loaded by the infected MBR or redirected VBR | ntldr, bootmgr, winload.exe | OslArchTransferToKernel, then IoInitSystem in the kernel | ESET, 2013 |
| Rovnix | Malicious IPL code | ntldr / bootmgr | Copies itself over the second half of the IDT, hooks the protected-mode int 1h handler with hardware breakpoints, and loads its driver during kernel initialisation | ESET, 2011 |
| ESPecter (legacy) | Infected MBR | bootmgr, then the OS loader | Much the same kernel stage as the UEFI version, per ESET | ESET, 2021 |
| FinSpy (MBR) | Loader copied from the last MiB of the disk; int 15h hooked too | The OS loader | A chain of hooks ends in a kernel thread that injects into winlogon.exe | Kaspersky, 2021 |
ESET notes that ESPecter's legacy version, unlike its UEFI version, does not need to patch the boot manager's self-integrity check (BmFwVerifySelfIntegrity): on a BIOS boot the boot manager file on disk is never modified; only its copy in memory changes.
Traces it leaves
The hook leaves almost nothing of its own:
| Where | Trace |
|---|---|
| Disk: MBR, VBR or IPL | The code that installs the hook (see MBR infection and VBR and IPL infection) |
| Disk: outside the partitions | The hook's code and the later stages (hidden storage) |
| Disk: Windows boot files and BCD | Unchanged. Kaspersky notes TDL4's Windows PE switch is made in memory |
| Memory during boot | The hooked interrupt vector, memory reserved below the EBDA, patched boot manager and loader. Gone once Windows runs |
| Memory after boot | Only the end of the chain: kernel code with no driver file, injected user-mode code |
| TPM on BIOS machines with BitLocker | Changed measurements of the MBR code (PCR 4) or NTFS boot sector and code (PCR 8, 9), from the code that installs the hook |
How to check a host
Offline, the installer. The hook cannot be read from disk, but the code that installs it can. Image the disk from trusted media and check the MBR, each boot sector, the IPL and the space outside the partitions, as the MBR and VBR pages describe. Any unknown code there is the place to start.
Dynamic analysis, on a copy. To see what unknown boot code does, boot a copy of the disk image in an isolated virtual machine with a debugger attached, for example with QEMU's GDB stub, and watch the interrupt vector for 13h change after the boot sector runs. Never boot the original disk or a networked machine for this.
Live, the end of the chain. On the running system the int 13h hook is gone. What remains is what it loaded:
- A memory image analysed with Volatility 3:
windows.drivermodulereports driver objects with no loaded module behind them, andwindows.driverirpthe IRP handlers of the disk drivers, which these bootkits also hook (see disk stack hooking). - Network traffic and injected processes, as each family page lists.
- On BIOS machines with BitLocker and a TPM, an unexplained recovery prompt, or protection found suspended.
None of these proves an int 13h hook on its own: they prove that something ran before or below Windows. A disk read through the running system can be filtered, so the offline image remains the reference.
What the checker looks for
The hook is in memory, so the checker cannot see it, and checks is empty for this technique. bootsector sees the code that installs it, whose findings belong to MBR infection and VBR and IPL infection:
- "MBR boot code does not match a known loader" for an infected MBR (TDL4, Gapz.C, ESPecter legacy, FinSpy);
- "Volume boot code does not match a known loader", "NTFS loader sectors do not match a known loader" and "VBR hidden-sectors value differs from the partition start" for VBR and IPL infections (Rovnix, Gapz.A);
- "Small last partition with no recognised file system" for TDL4's Olmasco variant;
- "Data before the first partition does not match a known loader" and "Data after the last partition" for the code the hook runs from.
It does not run or emulate boot code, so it cannot say what that code hooks. esp and measuredboot do not apply to BIOS boots: there is no EFI system partition, and the checker does not compare the MBR measurements a BIOS with a TPM records. As with every disk check here, a disk head copied through the infected system may show clean sectors. See what an offline bootkit check can and cannot prove.
Mitigation and recovery
Prevention. Int 13h exists only on BIOS boots and on UEFI firmware running its legacy compatibility module (CSM). Boot through UEFI from a GPT disk with Secure Boot on, and turn off legacy boot in the firmware settings where it can be. Microsoft notes that Secure Boot settings cannot be changed by software, only from the firmware menu. On BIOS machines that remain, BitLocker with a TPM detects changes to the code that installs the hook. Restrict the administrator rights needed to write boot sectors.
Recovery. There is nothing to remove from memory: a power-off clears the hook. The infection lives in the boot sectors and the hidden storage, and the kernel code it loaded had full control while the machine ran. Preserve an image, then rebuild: wipe the whole disk, including the space outside the partitions, reinstall from trusted media, and rotate the credentials used on the host. Repairing only the MBR or boot sector leaves the stages outside the partitions on the disk.
Sources
Primary public reports, newest first.
- 2021-10-05UEFI threats moving to the ESP: Introducing ESPecter bootkitESET
- 2021-09-28FinSpy: unseen findingsKaspersky
- 2014-11-12Bootkits: past, present & futureVirus Bulletin (ESET)
- 2013-04-08Mind the Gapz: The most complex bootkit ever analyzed?ESET
- 2011-10-18TDL4 rebootedESET
- 2011-08-23Hasta La Vista, Bootkit: Exploiting the VBRESET
- 2011-01-25TDSS. TDL-4Kaspersky
See also
Related techniques
- Replacing the MBR boot codePersisting in the boot chain
- Infecting the VBR, its BPB or the IPLPersisting in the boot chain
- Turning off driver signing from the boot chainTaking over the boot
- Hidden storage outside the partitionsPersisting in the boot chain
- Hooking the UEFI hand-over to the OSTaking over the boot
Families that use it
- ESPecterUEFI bootkit
- FinSpy UEFI bootkitUEFI bootkit
- GapzVBR bootkit
- RovnixVBR bootkit
- TDL4 (TDSS / Alureon)MBR bootkit