This is the binary-focused companion to the sandbox-side
anti-vm-detection sub-skill: same artifact catalog, but approached
from the binary under the debugger rather than the detonation
environment. When a sample must be analyzed interactively and it
checks for VMs, you identify each check in the code and defeat it by
spoofing, hooking, or patching. Scope: bypass VM/sandbox detection
only on binaries you are authorized to analyze, in an isolated lab,
during authorized DFIR, malware research, or defensive testing.
Quick Workflow
- Reproduce: runs on bare metal (or unhardened VM A) vs exits on
your analysis VM; confirm the gap is environmental.
- Hunt the check: strings and imports naming VM artifacts; break on
registry, WMI, and adapter queries in the debugger.
- Classify each check by artifact type.
- Defeat: spoof the artifact, hook the query API, or patch the
comparison, one check at a time.
- Verify the sample proceeds; hunt for the next layer.
- Document every spoof and patch with the analysis.
1. Finding checks in the binary
# Strings name the artifacts directly
floss sample.exe | grep -iE "vbox|vmware|qemu|virtual|xen|vmtools|innotek" | sort -u
# Imports name the query mechanism
# RegOpenKeyExA/RegQueryValueExA -> registry artifact check
# CoCreateInstance + IWbemServices -> WMI query check
# GetAdaptersInfo/GetAdaptersAddresses -> MAC check
# __cpuid intrinsic -> CPUID hypervisor bit check
In the debugger, break on the query APIs and watch the arguments:
the registry path or WMI query string tells you exactly which
artifact it wants. Log each: artifact, API, and the code address of
the check.
2. Spoofing artifacts
For registry and file checks, give the sample what a physical machine
would show:
- Registry: in the lab VM, the values are already scrubbed in the
hardened image; for per-sample cases, hook RegQueryValueExA and
return plausible physical strings ("Dell Inc.", real disk model).
- Files: the check usually tests existence (GetFileAttributesA);
hook it to return NOT_FOUND for vmmouse.sys and friends.
- Processes: hook the snapshot APIs to hide vmtoolsd.exe, or rename
the tools in the image.
Hook shape (conceptual):
RegQueryValueExA(hKey, "SystemBiosVersion", ...) called
-> if the real value contains "VBOX", return "DELL - 1" instead
Spoofing beats patching when the check is one of several: the binary
keeps running its logic and you keep observing.
3. WMI, MAC, and CPUID
- WMI: break on the query execution, capture the WQL
(e.g.
SELECT * FROM Win32_ComputerSystem); hook the result or
patch the string comparison on Manufacturer. Setting the
hypervisor's DMI/SMBIOS strings to physical hardware defeats most
WMI checks with no per-sample work.
- MAC: the check reads adapters and compares OUIs
(08:00:27, 00:50:56, 52:54:00). Change the VM's virtual NIC MAC to
a real vendor OUI once, in the image; per-sample, hook
GetAdaptersAddresses.
- CPUID hypervisor bit: leaf 1, ECX bit 31. Patch the test
instruction, or mask the bit if your hypervisor exposes the
option. Some samples also read leaves 0x40000000+ for the
hypervisor brand string; patch those reads too.
4. Patching the verdict
When spoofing is impractical, patch the comparison:
Before:
call check_vm_artifacts ; returns 1 if VM found
test eax, eax
jne exit_quietly
After:
xor eax, eax ; always "not a VM"
nop; nop ; cover the test/jne
Find the check by breaking on the query API and stepping to the
verdict. One patch per check; re-run between patches to catch layered
checks.
5. Validating with test tools
# In the analysis VM, run al-khaser or pafish BEFORE trusting the image
# They enumerate dozens of checks; fix what they flag, snapshot, repeat
A hardened image that passes these tools defeats most real samples
with zero per-sample patching. Re-validate the image quarterly and
after hypervisor updates; new versions sometimes add new artifacts.
6. Validation protocol
- Baseline: unhardened VM, sample exits in seconds, no network.
- Bypassed: hardened VM or patches applied, full behavior observed.
- Revert: back to unhardened, quiet again (proves causation).
- Record: image snapshot ID, MAC, scrubbed artifacts, per-sample
patches with file offsets.
Edge cases
User-artifact checks (empty recent-docs, no browser history):
harden by adding plausible clutter, not just removing VM traces.
Cloud metadata checks (169.254.169.254): block or spoof the
endpoint in the lab network.
Samples that need a GPU: cannot be spoofed cheaply; patch the
check instead.
Over-scrubbed images that look fake in new ways: keep values
plausible, not empty.
Nested virtualization artifacts (a lab inside a VM): the outer hypervisor's traces can confuse per-sample analysis; note the stack in the report.
Escalation
If the sample still evades a fully hardened image plus targeted
patches, escalate to bare-metal analysis or hypervisor-level
tracing.
If the check targets your specific lab (hostname, username),
escalate: that is counter-intelligence-relevant.
If the binary checks for analysis tools by hash rather than name, renaming is not enough; escalate to hook-based hiding.
If spoofing breaks the sample's own logic (it needs the real value), escalate to patching the verdict instead of the artifact.
Detection and defender view
Every VM check a sample performs is threat intel: which artifacts it
fears reveals which sandboxes the author tests against. Log the
artifact list per family; aggregated, it shows ecosystem trends in
evasion. For lab operators, the hardened image is shared
infrastructure: build once, document, snapshot, and share the build
notes. For the SOC, processes that query VM artifacts then exit are a
hunt signal for evasive malware on real hosts.
Key references
1---2name: binary-anti-analysis-bypass-vm-and-sandbox-detection3description: Use when a binary fingerprints virtual machines or4 sandboxes during authorized lab analysis and refuses to run. Covers5 the artifact catalog (registry, files, processes, MAC, WMI, CPUID),6 building a hardened analysis VM image, per-sample spoofing and7 patching of checks, validating with test tools like al-khaser and8 pafish, and the validation protocol proving behavior returned. Use9 when samples exit only in VMs, when building lab infrastructure, or10 when a sandbox fleet needs hardening.11version: 1.0.012domain: binary13lifecycle: stable14last_verified: "2026-10-23"15requires: [binary-anti-analysis-bypass]16extends: []17parent: binary-anti-analysis-bypass18relates: [malware-sandbox-analysis, binary-patching-techniques]19tools:20 - name: x64dbg21 version: "2025.06"22 - name: Python23 version: "3.12"24 - name: CAPE Sandbox25 version: "2.5"26metadata:27 source: https://skillmd.com/skills/mizazhaider-ceh/binary-anti-analysis-bypass-vm-and-sandbox-detection28---2930This is the binary-focused companion to the sandbox-side31anti-vm-detection sub-skill: same artifact catalog, but approached32from the binary under the debugger rather than the detonation33environment. When a sample must be analyzed interactively and it34checks for VMs, you identify each check in the code and defeat it by35spoofing, hooking, or patching. Scope: bypass VM/sandbox detection36only on binaries you are authorized to analyze, in an isolated lab,37during authorized DFIR, malware research, or defensive testing.3839## Quick Workflow40411. Reproduce: runs on bare metal (or unhardened VM A) vs exits on42 your analysis VM; confirm the gap is environmental.432. Hunt the check: strings and imports naming VM artifacts; break on44 registry, WMI, and adapter queries in the debugger.453. Classify each check by artifact type.464. Defeat: spoof the artifact, hook the query API, or patch the47 comparison, one check at a time.485. Verify the sample proceeds; hunt for the next layer.496. Document every spoof and patch with the analysis.5051## 1. Finding checks in the binary5253```bash54# Strings name the artifacts directly55floss sample.exe | grep -iE "vbox|vmware|qemu|virtual|xen|vmtools|innotek" | sort -u5657# Imports name the query mechanism58# RegOpenKeyExA/RegQueryValueExA -> registry artifact check59# CoCreateInstance + IWbemServices -> WMI query check60# GetAdaptersInfo/GetAdaptersAddresses -> MAC check61# __cpuid intrinsic -> CPUID hypervisor bit check62```6364In the debugger, break on the query APIs and watch the arguments:65the registry path or WMI query string tells you exactly which66artifact it wants. Log each: artifact, API, and the code address of67the check.6869## 2. Spoofing artifacts7071For registry and file checks, give the sample what a physical machine72would show:7374- Registry: in the lab VM, the values are already scrubbed in the75 hardened image; for per-sample cases, hook RegQueryValueExA and76 return plausible physical strings ("Dell Inc.", real disk model).77- Files: the check usually tests existence (GetFileAttributesA);78 hook it to return NOT_FOUND for vmmouse.sys and friends.79- Processes: hook the snapshot APIs to hide vmtoolsd.exe, or rename80 the tools in the image.8182```text83Hook shape (conceptual):84 RegQueryValueExA(hKey, "SystemBiosVersion", ...) called85 -> if the real value contains "VBOX", return "DELL - 1" instead86```8788Spoofing beats patching when the check is one of several: the binary89keeps running its logic and you keep observing.9091## 3. WMI, MAC, and CPUID9293- **WMI**: break on the query execution, capture the WQL94 (e.g. `SELECT * FROM Win32_ComputerSystem`); hook the result or95 patch the string comparison on Manufacturer. Setting the96 hypervisor's DMI/SMBIOS strings to physical hardware defeats most97 WMI checks with no per-sample work.98- **MAC**: the check reads adapters and compares OUIs99 (08:00:27, 00:50:56, 52:54:00). Change the VM's virtual NIC MAC to100 a real vendor OUI once, in the image; per-sample, hook101 GetAdaptersAddresses.102- **CPUID hypervisor bit**: leaf 1, ECX bit 31. Patch the test103 instruction, or mask the bit if your hypervisor exposes the104 option. Some samples also read leaves 0x40000000+ for the105 hypervisor brand string; patch those reads too.106107## 4. Patching the verdict108109When spoofing is impractical, patch the comparison:110111```text112Before:113 call check_vm_artifacts ; returns 1 if VM found114 test eax, eax115 jne exit_quietly116After:117 xor eax, eax ; always "not a VM"118 nop; nop ; cover the test/jne119```120121Find the check by breaking on the query API and stepping to the122verdict. One patch per check; re-run between patches to catch layered123checks.124125## 5. Validating with test tools126127```bash128# In the analysis VM, run al-khaser or pafish BEFORE trusting the image129# They enumerate dozens of checks; fix what they flag, snapshot, repeat130```131132A hardened image that passes these tools defeats most real samples133with zero per-sample patching. Re-validate the image quarterly and134after hypervisor updates; new versions sometimes add new artifacts.135136## 6. Validation protocol1371381. Baseline: unhardened VM, sample exits in seconds, no network.1392. Bypassed: hardened VM or patches applied, full behavior observed.1403. Revert: back to unhardened, quiet again (proves causation).1414. Record: image snapshot ID, MAC, scrubbed artifacts, per-sample142 patches with file offsets.143144## Edge cases145146- User-artifact checks (empty recent-docs, no browser history):147 harden by adding plausible clutter, not just removing VM traces.148- Cloud metadata checks (169.254.169.254): block or spoof the149 endpoint in the lab network.150- Samples that need a GPU: cannot be spoofed cheaply; patch the151 check instead.152- Over-scrubbed images that look fake in new ways: keep values153 plausible, not empty.154155- Nested virtualization artifacts (a lab inside a VM): the outer hypervisor's traces can confuse per-sample analysis; note the stack in the report.156157## Escalation158159- If the sample still evades a fully hardened image plus targeted160 patches, escalate to bare-metal analysis or hypervisor-level161 tracing.162- If the check targets your specific lab (hostname, username),163 escalate: that is counter-intelligence-relevant.164165- If the binary checks for analysis tools by hash rather than name, renaming is not enough; escalate to hook-based hiding.166- If spoofing breaks the sample's own logic (it needs the real value), escalate to patching the verdict instead of the artifact.167168## Detection and defender view169170Every VM check a sample performs is threat intel: which artifacts it171fears reveals which sandboxes the author tests against. Log the172artifact list per family; aggregated, it shows ecosystem trends in173evasion. For lab operators, the hardened image is shared174infrastructure: build once, document, snapshot, and share the build175notes. For the SOC, processes that query VM artifacts then exit are a176hunt signal for evasive malware on real hosts.177178## Key references179180- al-khaser:181 https://github.com/LordNoteworthy/al-khaser182- pafish:183 https://github.com/a0rtega/pafish184- MITRE ATT&CK: T1497.001 (System Checks), T1497185 (Virtualization/Sandbox Evasion)186- CAPE Sandbox documentation:187 https://capev2.readthedocs.io/188- Practical Malware Analysis (Sikorski and Honig), Chapter 17189 (anti-VM techniques)