Skip to content

Firmware implant

CosmicStrand UEFI Firmware Rootkit: Traces and Checks

CosmicStrand patched a DXE driver in ASUS and Gigabyte H81 firmware and hooked Windows boot in memory. What was reported, what disk checks miss, and recovery.

Kind
Firmware implant · Firmware layer
Platforms
Firmware, Windows
First seen
2016
Status
In the wild
Checked by
None: no module reads its traces

Overview

CosmicStrand is a UEFI firmware rootkit that Kaspersky described on 25 July 2022. It was found in firmware images of Gigabyte and ASUS motherboards, all of them designs built on the Intel H81 chipset. The implant sits in a modified DXE driver inside the firmware stored in the board's SPI flash; from there it hooks the Windows boot chain in memory at every start and plants a kernel-mode stager. Nothing of it is written to the disk.

Kaspersky dates its use to the end of 2016. An older variant was active from late 2016 to mid-2017, judging by the life of its command-and-control domain, and the variant Kaspersky analysed was in use in 2020. Kaspersky notes that Qihoo 360 had described an early variant in 2017 and suggested that a victim received an already-backdoored board from a second-hand reseller; Kaspersky could not confirm this. The initial infection vector is unknown.

The victims Kaspersky identified were in China, Vietnam, Iran and Russia, and all appeared to be private individuals using its free product; none could be tied to an organisation. Kaspersky attributes CosmicStrand, with low confidence, to a Chinese-speaking actor, citing code patterns shared with the MyKings botnet and the same API hashing algorithm seen in MoonBounce and the xTalker malware. It could not tie it to a known cluster.

How it loads and hides

From Kaspersky's analysis, at the level a responder needs:

  1. Firmware. The attackers modified the CSMCORE DXE driver (GUID A062CF1F-8473-4AA3-8793-600BC4FFE9A8): its entry point leads to code added in the .reloc section, which redirects the HandleProtocol boot service. Kaspersky thinks the change was made with an automated patcher, which implies earlier access to the machine, remote or physical.
  2. Windows Boot Manager. The HandleProtocol hook waits for a specific call during boot and then patches Archpx64TransferTo64BitApplicationAsm in the Boot Manager, in memory.
  3. Windows OS loader. That patch, when it runs, finds OslArchTransferToKernel in the OS loader and hooks its end.
  4. Kernel. Before the kernel starts, the rootkit copies code into unused space at the end of the .text section of the in-memory ntoskrnl.exe and diverts ZwCreateSection to it. It also patches KiFilterFiberContext so that PatchGuard, the kernel's patch protection, does not start. On the first ZwCreateSection call it restores the original bytes and runs a kernel shellcode.
  5. Payload. The shellcode waits for a thread in winlogon.exe, waits ten minutes, tests connectivity by talking to the TCP/UDP device objects directly, then fetches a payload from its server in 528-byte chunks and runs it in kernel memory.

Kaspersky could not obtain any payload from the server. On one infected machine it found an in-memory user-mode program that created a local user aaaabbbb and added it to the local administrators group, and it infers that the kernel shellcode acts as a stager for such programs.

The files on the disk, the Boot Manager and loader included, are never modified; every hook is applied in memory after the file has been read. Reinstalling Windows or changing the disk does not remove the rootkit (Kaspersky). Secure Boot checks the signatures of the boot applications the firmware loads, not the firmware's own modules (ESET made the same point for LoJax), so it does not stop a modified CSMCORE.

Traces on disk

The rootkit itself leaves nothing on the disk. What can be found:

LocationWhatSource
SPI flash, CSMCORE DXE driver (GUID A062CF1F-8473-4AA3-8793-600BC4FFE9A8)Entry point patched to code added in .reloc; differs from the vendor's module of the same versionKaspersky
Memory, Boot Manager, OS loader, kernelPatched Archpx64TransferTo64BitApplicationAsm and OslArchTransferToKernel; code in the slack space of the kernel's .text; patched KiFilterFiberContextKaspersky
Memory, winlogon.exeKernel shellcode running in the context of a winlogon.exe threadKaspersky
SAM hive, Security logA local account aaaabbbb in the Administrators group, seen on one machineKaspersky
NetworkThe current variant's server update.bokts[.]com; the older variant's www.erda158[.]topKaspersky

Kaspersky lists the modified DXE driver as SHA-256 951F74882C1873BFE56E0BFF225E3CD5D8964AF4F7334182BC1BF0EC9E987A0A (MD5 DDFE44F87FAC7DAEEB1B681DEA3300E9) in its report. That value describes one sample. Each board model has its own CSMCORE, so a patched driver from another image will not match; compare against the vendor's module instead. Kaspersky did not publish the infected firmware images.

How to check a host

Who is exposed

The reported cases are desktop boards with the Intel H81 chipset from Gigabyte and ASUS. A machine of that kind, especially one built from a second-hand board, deserves a firmware check after any reason for suspicion. Machines on other platforms are not known to be affected, but the patching method is not specific to these boards.

The firmware

  1. Dump the SPI flash from a trusted environment: chipsec_util spi dump rom.bin from a clean Linux live medium, or a hardware programmer on the chip. CHIPSEC's Windows driver needs driver signature checks turned off (installation guide), which you should not do on the suspect host.

  2. Fetch the vendor's image for the exact board and BIOS version, and compare the CSMCORE module of both after decoding them with UEFITool or chipsec_util decode rom.bin. CHIPSEC can compare every executable module against a list built from the vendor's image:

    chipsec_main -i -n -m tools.uefi.scan_image -a generate,efilist.json,vendor.rom
    chipsec_main -i -n -m tools.uefi.scan_image -a check,efilist.json,rom.bin
    

    Compare modules, not whole files: NVRAM variables and other regions differ between two machines of the same model.

  3. Check write protection with chipsec_main -m common.bios_wp and chipsec_main -m common.spi_lock, or fwupdmgr security on Linux.

The running system

The firmware runs first, so a live check cannot clear the host. It can still collect context and the user-mode traces:

Get-CimInstance Win32_BaseBoard | Select-Object Manufacturer, Product
Get-CimInstance Win32_BIOS | Select-Object SMBIOSBIOSVersion, ReleaseDate
Get-LocalUser -Name aaaabbbb
Get-LocalGroupMember -Group Administrators
Get-WinEvent -FilterHashtable @{LogName='Security'; Id=4720,4732}

Events 4720 (account created) and 4732 (member added to a security-enabled local group) depend on the account management audit policy; the SAM hive keeps the account either way (windowsforensics.app, windowspersistence.com). Look for the two domains in DNS and proxy logs. The kernel-side code exists only in memory; a memory image is the only way to see it on a running host, and with PatchGuard disabled the usual integrity alarms may stay silent.

What the checker looks for

None of the checker's modules can see CosmicStrand, so checks is empty for this family. The implant is in the SPI flash, which no collection contains as a file, and every later stage lives in memory.

  • esp: bootmgfw.efi and the other boot files on the EFI system partition keep their original bytes and signatures; the patches are applied in memory.
  • windrivers: no driver service, .sys file or install event is created; the kernel code is shellcode, not a loaded driver.
  • measuredboot: PCR 0 records the platform firmware's executable code (Microsoft). The module does not compare PCR 0 measurements between boots and has no vendor reference values, so it raises nothing for a changed firmware. If the board has a TPM and Windows kept boot logs from before the infection, decoding them yourself, as in reading Measured Boot logs, would show that the firmware changed, not why.
  • bootsector: not involved.

The account aaaabbbb is outside the checker's scope; look for it with the commands above. For what a clean offline result does and does not mean, see what an offline rootkit check can and cannot prove.

Removal and recovery

  1. Preserve the flash dump and, if you have one, a memory image.
  2. Reflash the firmware with the vendor's image for that board, from a trusted environment, then dump the flash again and compare it with the vendor's image. Answering readers under its report, Kaspersky said that reflashing the motherboard firmware is the only reliable removal and that replacing the board is the alternative. A firmware update that rewrites the whole BIOS region should also replace the patched module; verify it rather than assume it.
  3. Reinstall Windows. Kernel code ran at every boot with PatchGuard disabled, so nothing on the installed system can be trusted. Wiping the disk alone does nothing against the implant (Kaspersky).
  4. Rotate credentials used on the machine, remove unknown local accounts, and check the other machines that share them.
  5. Source boards carefully. Kaspersky's advice to readers was to reflash second-hand boards with the official firmware before use. Where the platform supports it, enable BIOS write protection and keep TPM-backed Measured Boot logs so that a later change leaves a record.

Sources

Primary public reports, newest first.

  1. 2022-07-26CosmicStrand: a UEFI rootkitKaspersky
  2. 2022-07-25CosmicStrand: the discovery of a sophisticated UEFI firmware rootkitKaspersky

See also