Sandbox-aware malware checks its environment and refuses to misbehave when it finds one. The checks are finite and well cataloged: registry keys, driver files, running processes, MAC addresses, WMI queries, and CPUID leaves. This sub-skill covers identifying exactly which check a sample uses, defeating it environmentally (hardened image) or surgically (patch/hook), and proving the sample's real behavior emerged. Scope: defeat environment checks only on samples you are authorized to handle, inside an isolated lab, during authorized DFIR or malware research.
Quick Workflow
- Confirm evasion: compare the quiet sandbox run against static expectations (imports and strings promise behavior the run lacks).
- Hunt the check statically: grep strings and imports for VM vendor names and fingerprint APIs.
- Classify: registry/file/process check, WMI query, MAC check, CPUID, or timing.
- Apply the matching bypass: harden the image for environmental checks, patch or hook for logic checks.
- Re-run and compare: new behavior (network, drops, injection) proves the bypass.
- Record the bypass set with the report for reproducibility.
1. The artifact catalog
What samples check, and where to scrub it in your image:
Registry:
HKLM\HARDWARE\DESCRIPTION\System\SystemBiosVersion (VBOX, QEMU strings)
HKLM\HARDWARE\DESCRIPTION\System\VideoBiosVersion
HKLM\SYSTEM\...\Enum\IDE, SCSI (VBOX HARDDISK, QEMU HARDDISK)
Files:
C:\windows\system32\drivers\vmmouse.sys, vmhgfs.sys, vboxguest.sys
Processes:
vmtoolsd.exe, vboxservice.exe, vboxtray.exe, qemu-ga.exe
MAC OUIs:
08:00:27 (VirtualBox), 00:05:69, 00:0C:29, 00:50:56 (VMware),
52:54:00 (QEMU/KVM)
WMI:
SELECT * FROM Win32_ComputerSystem -> Manufacturer, Model
SELECT * FROM Win32_BIOS -> SerialNumber, Version
CPUID:
leaf 1, ECX bit 31 (hypervisor present)
hypervisor brand leaves 0x40000000+
Build one hardened image with these scrubbed: guest tools uninstalled or renamed, virtual MAC replaced with a real vendor OUI, registry strings cleaned, WMI responses neutral. Snapshot it; every detonation starts from there.
2. Finding the sample's specific check
# Strings name the check directly in most cases
floss sample.exe | grep -iE "vbox|vmware|qemu|virtual|xen|vmtools" | sort -u
# Imports name the mechanism
# RegOpenKeyEx + the strings above -> registry check
# WMI COM APIs -> WMI query check
# GetAdaptersInfo -> MAC check
Example output shape:
VBoxGuest
SELECT * FROM Win32_ComputerSystem WHERE Manufacturer LIKE "%innotek%"
00:50:56
Three checks found: file/driver probe, WMI manufacturer query, VMware MAC check. Harden or spoof exactly these three; do not boil the ocean.
3. Environmental bypasses
For artifact checks, fix the environment once:
- Uninstall guest additions from the analysis VM, or rename their services and drivers.
- Set the VM's MAC to a common real OUI (e.g. a laptop vendor range).
- Edit the scrubbed registry values in the hardened snapshot.
- For WMI: some hypervisors let you set the DMI strings (SMBIOS manufacturer/product); set them to plausible physical hardware.
Verify the hardened image with an anti-VM test tool before trusting it:
# al-khaser reports which checks still trigger in your image
# run it in the VM, fix what it flags, snapshot again
A hardened image that passes al-khaser defeats the large majority of real-world samples with no per-sample work.
4. Surgical bypasses for stubborn checks
When the image is hardened and the sample still exits:
- Patch the comparison: find the string compare against "VMware" or the MAC prefix and force it to fail (flip the jump after the compare).
- Hook the query API: intercept RegQueryValueEx or the WMI call and return plausible physical values.
- CPUID hypervisor bit: patch the test of ECX bit 31, or mask the bit if your hypervisor allows it.
- Timing-based VM detection (rdtsc deltas that catch emulation): treat as a timing check; see the parent skill's timing section.
x64dbg patch shape for a WMI manufacturer check:
Before: call compare_manufacturer ; returns 1 if "innotek"
test eax, eax
jne skip_payload ; VM found -> skip
After: xor eax, eax ; always "not a VM"
nop the test/jne
One check at a time, re-run between patches. Layered checks are common; the sample that passes check one often has check two waiting.
5. Validation protocol
- Baseline: hardened image off, sample exits in under 5 seconds with no network.
- Bypass: hardened image on (or patch applied), sample runs 60+ seconds, beacons, drops files.
- Revert: back to unhardened, sample goes quiet again.
- The revert step proves causation; without it you may be seeing nondeterminism.
Record: image name and snapshot ID, MAC used, which artifacts were scrubbed, and any per-sample patches with file offsets.
Edge cases
- Samples that check for the absence of normal user artifacts (no recent documents, empty browser history): harden by adding plausible user clutter to the image, not just removing VM traces.
- Cloud-metadata checks (169.254.169.254): some samples detect cloud labs; block or spoof the metadata endpoint in the lab network.
- Checks that require a GPU or specific hardware: cannot be spoofed cheaply; patch the check instead.
- Bare-metal-only samples: rare; escalate rather than fighting the VM indefinitely.
- Over-hardening: an image scrubbed so aggressively it looks fake in new ways (no plausible hardware strings at all) can trigger paranoia checks; keep values plausible, not empty.
Escalation
If the sample still evades a fully hardened image plus targeted patches, escalate to bare-metal detonation or hypervisor-level tracing.
If evasion behavior suggests a targeted sample checking for your specific lab (hostname, username), escalate: that is counter-intelligence-relevant, not routine triage.
If patching risks breaking the payload, prefer environmental bypasses and document the residual risk.
If a sample fingerprints your specific sandbox fleet (not VMs in general), escalate: that suggests the operator has studied your defenses.
Detection and defender view
The artifacts malware checks for are a fingerprint of its author's expectations: which VM vendors they fear tells you who they think hunts them. Log every environment check a sample performs (strings queried, APIs called) as threat intel; aggregated across samples it shows which sandboxes the ecosystem considers dangerous. For your own detection engineering, the hardened image is infrastructure: build it once, document it, and share the build notes with partner labs. Evasion-aware detonations produce the behavior timelines that feed honest ATT&CK coverage maps.
Key references
- al-khaser (anti-analysis test tool): https://github.com/LordNoteworthy/al-khaser
- MITRE ATT&CK: T1497.001 (System Checks), T1497 (Virtualization/ Sandbox Evasion)
- CAPE Sandbox documentation (VM profiles): https://capev2.readthedocs.io/
- Practical Malware Analysis (Sikorski and Honig), Chapter 17 (anti-debugging and anti-VM concepts)
- Pafish (paranoid fish, VM detection demo): https://github.com/a0rtega/pafish
