Malware Analysis Sandboxes
CAUTION
Educational reference only. Analysis of live malware must be performed in an isolated, disposable environment with no path to production systems. Handling live samples outside such an environment risks infection and is outside the scope of authorized testing.
1. Overview
A malware analysis sandbox is a defensive tool: it runs an untrusted sample in an instrumented, isolated environment and records what the sample does. The analyst gets a behavioral report (files, registry, network, process activity) without risking the host.
This is the mirror image of the previous files. The browser, OS, and mobile sandboxes exist to contain code the user willingly runs. The malware sandbox exists to observe code that is deliberately hostile, which means the isolation must be even stronger and the observation must be richer.
This file covers how analysis sandboxes are built, how malware evades them, and how to harden and verify them.
2. Threat Model
The malware sandbox defends the analyst's host and network against:
- A sample that actively tries to detect the sandbox and behave benignly.
- A sample that attempts to escape the guest (VM escape, shared-folder abuse).
- A sample that attempts to reach the analyst's real network or the internet.
- A sample that persists across reboots or infects the analysis image.
The sandbox must simultaneously:
- Contain the sample (no escape).
- Observe the sample (rich telemetry).
- Preserve the sample's behavior (no early detection that changes behavior).
The third requirement conflicts with the first two: the more instrumentation, the more detectable the environment. This tension is the core design problem of malware sandboxes.
3. How Malware Analysis Sandboxes Work
3.1 Isolation Layers
A typical analysis sandbox stacks:
- Full VM - the sample runs in a guest OS on a hypervisor.
- Snapshot / rollback - the guest is reset to a clean snapshot after each run.
- Network isolation - the guest's traffic is routed through a controlled simulation layer (INetSim, FakeNet-NG) or a monitored egress.
- Host hardening - the hypervisor host is dedicated, patched, and has no shared folders or clipboard.
- Physical separation - ideally, the analysis host is on an isolated network segment with no route to production.
The hypervisor boundary is the strongest layer. It is also the one that a VM-escape sample targets (see Virtualization 02 VM Escape).
3.2 Instrumentation
The sandbox records:
- Process activity: process creation, command lines, parent-child trees.
- File activity: created, modified, deleted files and their hashes.
- Registry activity (Windows): keys created, modified, deleted.
- Network activity: DNS queries, HTTP requests, TLS SNI, raw sockets.
- API calls: user-mode hooks (and, in some products, kernel callbacks).
- Memory: dumps of injected regions, unpacked payloads.
- Screenshots: periodic and on-event, for GUI malware.
The instrumentation is what makes the sandbox detectable (section 4).
3.3 Controlled Network
The guest must not reach the real internet. Options:
- Full simulation (INetSim, FakeNet-NG): answers DNS and common protocols locally, so the sample "succeeds" and reveals its C2 logic.
- Sinkhole: real DNS resolves C2 domains to a controlled IP.
- Monitored egress: the guest reaches the internet through a proxy that logs everything, used only when the sample's real C2 interaction is needed.
Full simulation is the default for safety. Monitored egress is used only for targeted analysis, on an isolated segment, with the analyst's explicit approval.
3.4 Common Products
- Cuckoo (open source, largely unmaintained) - the classic reference implementation.
- CAPE - a Cuckoo fork with unpacking and config extraction.
- DRAKVUF - hypervisor-level, no guest agent; harder to detect.
- ANY.RUN, Joe Sandbox, Hybrid Analysis - commercial/cloud services.
- Speakeasy, Qiling - emulation-based, no full OS.
Cloud sandboxes submit the sample to a third party; that is a data-sharing decision, not just a technical one.
4. Common Evasion Techniques
Malware evades sandboxes in three broad ways: detect the environment, delay the payload, or attack the sandbox itself.
4.1 Environment Fingerprinting
The sample checks for artifacts that betray an analysis environment:
- Usernames like
sandbox,malware,cuckoo,user. - Computer names like
SANDBOX,MALTEST,VIRUS. - MAC address prefixes of VM vendors (VMware
00:0C:29,00:50:56; VirtualBox08:00:27; Hyper-V00:15:5D; QEMU52:54:00). - Registry keys and drivers of analysis tools.
- Installed processes (Wireshark, Procmon, x64dbg).
- Disk size, RAM size, CPU count below typical thresholds.
- Absence of user activity (no mouse movement, no recent documents).
- Uptime too short.
If detected, the sample exits, sleeps, or runs benign code.
4.2 Timing Evasion
- Sleep for hours or days before acting (sandboxes run for minutes).
- Use
NtDelayExecutionwith long intervals. - Wait for a specific date or user interaction.
- Stalling via
Sleeploops that exceed the analysis window.
The defense is accelerated time (hooking Sleep/NtDelayExecution) - which
is itself detectable.
4.3 Anti-Instrumentation
- Detect user-mode hooks by comparing in-memory code to on-disk code.
- Detect the debugger (
IsDebuggerPresent,NtQueryInformationProcess). - Detect hypervisor via CPUID leaf
0x40000000(the hypervisor vendor leaf). - Detect the analysis agent's process, driver, or named pipes.
4.4 Sandbox Escape
The sample attacks the sandbox itself:
- Shared-folder abuse: a writable shared folder lets the guest write to the host, or a symlink turns a host read into a host write.
- Clipboard sharing abuse.
- Hypervisor escape (see Virtualization 02 VM Escape).
- Guest-agent exploit.
This is why the hardened configuration forbids shared folders, clipboard, and guest agents wherever possible.
4.5 Payload Staging
The sample downloads the real payload only after checking the environment. The first stage looks benign; the second stage (the payload) never runs in the sandbox.
The defense is to observe the first stage's network activity and retrieve the second stage for separate analysis.
5. Exploitation Recipes
These are defensive analyst recipes: how to probe a sandbox you operate, to verify that evasion detection works.
5.1 Check for Shared Folders
From inside the guest, look for host shares.
# Windows guest
Get-SmbShare
net use
Get-ChildItem \\vboxsvr 2>$null
Get-ChildItem \\vmware-host 2>$null
Expected (hardened): no host shares listed. Any share is a defect.
5.2 Check the Hypervisor Fingerprint
# Linux guest: CPUID hypervisor vendor leaf
grep -m1 hypervisor /proc/cpuinfo
systemd-detect-virt
Expected (for a VM): the hypervisor name is visible. This is why samples use it: the guest cannot hide it from itself.
5.3 Check the Instrumentation Hooks
# Windows guest: look for the analysis agent's driver and service
Get-Service | Where-Object { $_.Name -match 'cuckoo|cape|agent|monitor' }
Get-CimInstance Win32_SystemDriver | Where-Object { $_.PathName -match 'agent|mon' }
Any agent found is a fingerprint the sample can use. DRAKVUF-style hypervisor instrumentation avoids guest-visible agents.
5.4 Check the Network Simulation
# from the guest: does DNS resolve, and to what
nslookup example.com
# is the response a real internet address or a simulated one
curl -s http://example.com | head -c 200
Expected (full simulation): the DNS answer and HTTP response come from the simulation layer, not the internet. Confirm the simulation's certificates are not trusted by the guest in a way that leaks the simulation.
6. Post-Exploitation
If the sample escapes the analysis sandbox, the analyst's host is compromised.
Response priorities:
- Isolate the analysis host from the network immediately (physical or firewall).
- Do not power off - preserve volatile memory for forensics if the escape is a hypervisor bug.
- Treat the host as compromised: reimage, do not clean.
- Review how the escape happened (shared folder, agent, hypervisor bug) and fix the configuration before the next run.
- Report the escape to the hypervisor vendor if it is a vendor bug.
For a cloud sandbox, the vendor handles the isolation; the analyst's obligation is to not upload samples that violate the vendor's terms.
7. Preventive Controls
- Use a dedicated analysis host. Never analyze on a workstation.
- Disable shared folders, clipboard sharing, drag-and-drop, and guest agents where the sandbox product allows it.
- Patch the hypervisor and the guest OS; VM escapes are usually patched bugs.
- Keep the analysis host on an isolated network segment with no route to production.
- Simulate the network (INetSim, FakeNet-NG) instead of granting internet access, unless real C2 interaction is required.
- Snapshot and roll back after every run; never reuse an infected image.
- Randomize the environment fingerprint where possible (hostname, username, MAC, uptime) to defeat naive fingerprinting.
- Use hypervisor-level instrumentation (DRAKVUF) when guest-visible agents would be detected.
- Log every sample submission and every network egress for accountability.
8. Detection Controls
The analysis sandbox is itself a detection system. What to watch:
- Samples that behave benignly and then exit: a strong evasion signal.
- Samples that sleep past the analysis window: extend the window or accelerate time.
- Samples that check CPUID, MAC prefixes, hostnames, or specific processes: record the checks, they are the fingerprinting logic.
- Samples that contact a second-stage URL: retrieve and analyze the second stage separately.
- For the analyst's own environment: monitor the host for unexpected outbound traffic or file writes from the hypervisor process.
9. Verification
To verify an analysis sandbox configuration:
- Confirm no host shares, clipboard, or drag-and-drop (section 5.1).
- Confirm the network is simulated or sinkholed, not open (section 5.4).
- Confirm the analysis agent is either minimal or hypervisor-level (section 5.3).
- Confirm snapshot/rollback works: run a benign file-writing sample, roll back, confirm no trace remains.
- Confirm the host is patched and on an isolated segment.
- Run a known evasive sample and confirm the evasion is detected and logged.
10. References
- Cuckoo Sandbox - https://cuckoosandbox.org/
- CAPE Sandbox - https://capev2.readthedocs.io/
- DRAKVUF - https://drakvuf.com/
- INetSim - https://www.inetsim.org/
- FakeNet-NG - https://github.com/mandiant/flare-fakenet-ng
- Speakeasy - https://github.com/mandiant/speakeasy
- Qiling - https://qiling.io/
- NIST SP 800-83 Rev. 1, Guide to Malware Incident Prevention and Handling for Desktops and Laptops - https://csrc.nist.gov/pubs/sp/800/83/r1/final