Skip to content

VBR bootkit

Gapz VBR Bootkit: Traces and Offline Checks

Gapz, the Windows bootkit ESET analysed in 2012 and 2013: the 4-byte VBR hidden-sectors change, the MBR variant, disk traces, offline checks and recovery.

Kind
VBR bootkit · Boot layer
Platforms
Windows
First seen
2012
Status
Historical
Also known as
Win32/Gapz
Checked by
Disk boot sectors

Overview

Gapz is a Windows bootkit for computers that start through the legacy BIOS from an MBR disk. ESET described it in December 2012 and published a 52-page analysis in April 2013, Mind the Gapz, whose title asks whether it is "the most complex bootkit ever analyzed". ESET found the earliest variant at the start of summer 2012, infecting the master boot record (MBR), and a later one, seen at the end of autumn 2012, that infects the volume boot record (VBR) of the active partition by changing only four bytes.

ESET saw few infections: fewer than one hundred detections from the time it started detecting the family, mostly in Russia. Its paper does not attribute Gapz to a named group. The droppers were built with Power Loader, a bot builder ESET says was sold on the Russian cybercrime market, and the C&C servers ESET found were already down during its research.

The paper lists three variants:

DetectionCompiled (per ESET)Boot techniquePrivilege escalation in the dropper
Win32/Gapz.CApril 2012MBRCVE-2010-4398, CVE-2011-2005, COM elevation
Win32/Gapz.ASeptember and October 2012VBRCVE-2011-3402, CVE-2010-4398, COM elevation
Win32/Gapz.BNovember 2012None (no bootkit)CVE-2011-3402, COM elevation

According to ESET, Gapz infects 32-bit Windows from XP SP2 (except Vista and Vista SP1) and 64-bit Windows from Vista SP2. On Windows 8 the bootkit did not work reliably. Public reporting on Gapz stops in 2013, and computers that boot through UEFI never run MBR or VBR code, so the family is historical. It stays useful as the reference case for one detection question: does the VBR's own pointer still point inside its partition?

How it loads and hides

MBR variant. The malicious MBR restores the original MBR code in memory, reads the next stage from the disk and hooks the BIOS disk service (int 13h). It watches ntldr, bootmgr and winload.exe as they are read from disk and patches them to keep control into the kernel, then runs its kernel-mode code once the kernel has initialised.

VBR variant. The NTFS VBR holds a BIOS Parameter Block (BPB) whose "Hidden Sectors" field gives the partition's start on the disk. At boot, the VBR code reads the 15 sectors of the initial program loader (IPL) at that position and runs them. Gapz overwrites that one field so that it points at the bootkit image instead. ESET stresses that the rest of the VBR code and the IPL stay untouched. A comparison of the boot code with known-good code therefore finds nothing: the field's value has to be checked against the partition table.

Both variants write the bootkit image either before the first partition or after the last partition of the disk. Because Gapz runs before Windows, it is not subject to driver signing. ESET notes that Early Launch Antimalware (ELAM) does not stop it either, since ELAM only sees drivers that Windows loads normally.

Hiding. Gapz hooks the IRP_MJ_INTERNAL_DEVICE_CONTROL and IRP_MJ_DEVICE_CONTROL handlers of the disk miniport driver and filters SCSI and ATA pass-through requests. ESET writes that this protects the infected MBR or VBR from being read or overwritten and protects the bootkit image from being overwritten. On an infected running system, a raw disk read can return clean sectors.

Payload. The kernel-mode code is not a PE file: it is a block of position-independent code in twelve parts, with its own TCP/IP stack that talks to the network card's NDIS miniport driver to avoid personal firewalls. It injects payloads into user-mode processes. Its payload and configuration sit in a hidden storage image, encrypted sector by sector with AES-256.

Traces on disk

LocationWhatSource
Sector 0 (MBR variant)MBR boot code replaced; the original is restored in memory at bootESET, December 2012
VBR of the active NTFS partition, BPB "Hidden Sectors" field (offset 0x1C, 4 bytes)Value changed to point at the bootkit image instead of the partition start (VBR variant)ESET, December 2012 and April 2013
Sectors before the first partition, or after the last oneBootkit image: next-stage boot code and kernel-mode codeESET white paper
\??\C:\System Volume Information\{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}Hidden storage image, AES-256 encrypted per sector; the GUID-like name comes from the configurationESET white paper

What is absent matters too: no driver file, no service key, no scheduled task. The kernel code is loaded from raw sectors at every boot. Everything Gapz needs to survive a reboot is outside the files a normal triage collects, except the storage image, and that one has an ordinary-looking name in a folder full of GUID-named Windows files.

How to check a host

First, can it apply? Gapz needs BIOS boot from an MBR disk. In Windows, System Information (msinfo32) shows "BIOS Mode", and bcdedit /enum "{current}" shows winload.exe for BIOS boot and winload.efi for UEFI. Get-Disk | Select-Object Number, PartitionStyle shows MBR or GPT.

Do not trust reads from the running system. Gapz filters raw disk requests, so image the disk from a clean environment (a WinPE or Linux boot medium, or the disk attached to another machine). A full image is best. At a minimum keep the first MiB, the first 16 sectors of each NTFS partition and the last MiB of the disk, since the image can sit after the last partition.

From a Linux boot medium, with /dev/sda the system disk:

sudo dd if=/dev/sda of=disk.img bs=4M status=progress
mmls disk.img
dd if=disk.img bs=512 skip=2048 count=1 2>/dev/null | xxd | head -n 4
dd if=disk.img bs=1 skip=$((2048*512 + 0x1C)) count=4 2>/dev/null | xxd

mmls (The Sleuth Kit) lists the partitions with their start sectors and the unallocated gaps. Replace 2048 with the start of the active NTFS partition. The last command prints the hidden-sectors field, little-endian: for a partition at sector 2048 it reads 0008 0000. A value that differs from the partition start, on a disk that still boots, is the Gapz pattern. Some partitioning and imaging tools leave a stale value, so read the sectors the field points to before you conclude: Gapz puts encrypted, high-entropy data there.

Then look at the gaps. Sectors between the MBR and the first partition are usually zero on a Windows disk; some boot managers, encryption products and OEM tools do keep code there, so identify what you find. A quick entropy hint is how well the gap compresses: dd if=disk.img bs=512 skip=1 count=2047 2>/dev/null | gzip -c | wc -c returns a few kilobytes for zeros and close to 1 MiB for encrypted data.

The storage file in System Volume Information is hard to single out: Windows keeps its own GUID-named files there, Volume Shadow Copy stores among them, and ESET's paper gives the path format only. Treat it as corroboration once the boot records show an infection.

What the checker looks for

bootsector is the module that can see Gapz. On a disk image or disk head it:

  • raises "VBR hidden-sectors value differs from the partition start" when the NTFS boot sector's BPB hidden-sectors field does not match the partition table, which catches the VBR variant. The finding links to this page and says whether the value points before the first partition, past the last one or into another partition. A partition moved or cloned by a tool that did not update its boot sector looks the same;
  • raises "MBR boot code does not match a known loader" for the MBR variant;
  • raises "Data before the first partition does not match a known loader" for non-zero, high-entropy data before the first partition, and "Data after the last partition" when a full image includes the end of the disk.

The sample's LAB-VM-01 host reproduces this layout with synthetic bytes: a hidden-sectors value of 32 for a partition at LBA 63, pointing at pseudo-random data from LBA 33. The sample walk-through reads it.

What it cannot see: a bootkit image after the last partition when only the disk head was collected; the hidden storage file, which it does not read or decrypt; and anything on an image taken from the infected running system, where Gapz may have returned clean sectors. No other module applies. Gapz has no driver service for windrivers, does not touch an EFI system partition, and predates Measured Boot logs on the systems it infected.

Removal and recovery

  1. Preserve the evidence first: a full image, or at least the first MiB, the partitions' boot sectors and the last MiB of the disk, taken from a clean environment.
  2. The boot path can be repaired from the Windows Recovery Environment: bootrec /fixmbr rewrites the MBR boot code and keeps the partition table, and bootrec /fixboot writes a new boot sector to the system partition. Whether a boot sector rewrite also corrects a changed BPB field depends on the tool. Check the hidden-sectors value against the partition start afterwards.
  3. Repairing the boot path does not answer what the kernel code did while it ran. It had full control of the system, injected code into user processes and fetched payloads. Prefer a rebuild: wipe the disk (diskpart, clean all zeroes every sector, including the gaps) and reinstall from known-good media.
  4. Rotate the credentials used on the host.
  5. Move the machine to UEFI boot from a GPT disk with Secure Boot on, where MBR and VBR code is never executed. The same applies to Rovnix and TDL4; UEFI-era bootkits such as ESPecter need the checks in How to check the ESP for a bootkit offline instead.

Sources

Primary public reports, newest first.

  1. 2013-04-08Mind the Gapz: The most complex bootkit ever analyzed?ESET
  2. 2013-04-08Is Gapz the most complex bootkit yet?ESET
  3. 2012-12-27Win32/Gapz: New Bootkit TechniqueESET

See also