Dynamic analysis executes the sample and watches what it does: files created, registry keys written, processes spawned, and network connections attempted. It answers the questions static analysis cannot, but it carries real risk, so the entire skill is built around containment first, execution second. Every run happens in a disposable VM with a snapshot taken beforehand, host-only or simulated networking, strict time limits, and full instrumentation running before the sample starts. Scope: detonate only samples you are authorized to analyze, in an isolated lab you control. Never run a sample on hardware that touches production, never allow real internet egress unless the engagement explicitly requires it and you have approval, and never detonate someone else's sample on shared infrastructure.
Quick Workflow
- Prepare the sandbox VM: clean snapshot, instrumentation installed, clock set, analysis tools ready.
- Start monitoring first: packet capture, FakeNet-NG, process monitor, and filesystem watcher.
- Copy the sample in (shared folder, never email) and hash it in the VM.
- Execute with a time limit and watch live for the first 2 minutes.
- Let it run the full window (typically 5 to 10 minutes), then stop capture.
- Collect artifacts: new files, registry diffs, network flows, dropped binaries.
- Revert to the clean snapshot immediately after collection.
- Convert observations into IOCs and a behavior report.
1. Sandbox preparation
The snapshot is your safety net and your reproducibility guarantee. No snapshot, no detonation.
# On the host (example with a generic hypervisor CLI; adapt to yours):
# 1. Boot the clean analysis VM, install nothing new, take snapshot 'clean'
# 2. Verify network is host-only or disconnected
# 3. Inside the VM, confirm no route to production:
ip route show
# Expected: only host-only or sandbox subnets, no default via corp gateway
# Inside the VM: baseline the filesystem before detonation
find / -xdev -type f -newer /tmp/baseline_marker 2>/dev/null | head
touch /tmp/baseline_marker
# Windows baseline alternative: export registry hives of interest
reg export HKLM\SOFTWARE baseline_software.reg
reg export "HKCU\Software\Microsoft\Windows\CurrentVersion\Run" baseline_run.reg
Set the VM clock to a plausible recent time; some malware sleeps if the clock looks wrong or refuses to run in an obvious lab year. Disable automatic updates and cloud AV uploads in the sandbox, or your sample gets quarantined mid-run and your hash gets shared with a vendor.
2. Instrumentation: capture everything before execution
Start every monitor before the sample runs. A monitor started late misses the dropper phase, which is usually the interesting part.
# Packet capture on the sandbox interface (run in background, save to file)
dumpcap -i eth0 -w /tmp/capture.pcap &
echo $! > /tmp/dumpcap.pid
# FakeNet-NG: simulate DNS, HTTP, and common services so the sample
# talks to you instead of timing out
python3 -m fakenetng.fakenetng -c /opt/fakenet/default.ini &
# Watch its log for the sample's DNS queries and HTTP requests
tail -f /tmp/fakenet.log
# Linux: trace file and process activity with auditd or sysdig-style tools
# Simple version: log all new processes
ps aux --sort=start_time > /tmp/ps_before.txt
# Windows: Process Monitor with a backing file, filtered later
# (start Procmon, set backing file, begin capture; stop after the run)
Note the FakeNet-NG configuration: it answers DNS for any domain and serves fake HTTP pages, which tricks most malware into revealing its full C2 protocol instead of dying on connection refused.
3. Execution with limits
Copy the sample in, verify the hash matches your triage record, then run it under a timeout. Watch the first two minutes live; most droppers show their hand quickly.
# Verify the sample survived the transfer intact
sha256sum sample.bin
# compare against hashes.txt from static-triage
# Linux sample: run under timeout, capture stdout/stderr
timeout 600 ./sample.bin > /tmp/stdout.txt 2> /tmp/stderr.txt &
SAMPLE_PID=$!
echo "started pid $SAMPLE_PID"
# Watch new processes in real time
watch -n 2 'ps -eo pid,ppid,etime,cmd --sort=start_time | tail -20'
# After the window: kill anything the sample spawned
kill $SAMPLE_PID 2>/dev/null
pkill -P $SAMPLE_PID 2>/dev/null
For Windows samples, double-click execution in the VM is normal, but prefer launching from a console so you see errors, and always with the same timeout discipline. If the sample needs arguments (a C2 URL, a password), you learned them in static triage; pass exactly those.
4. Collecting network behavior
Stop the capture, then read it for intent: DNS queries, HTTP requests, odd ports, and data volumes.
# Stop capture
kill $(cat /tmp/dumpcap.pid)
# DNS queries the sample made (answered by FakeNet-NG)
tshark -r /tmp/capture.pcap -Y dns -T fields -e dns.qry.name | sort -u | head -30
# HTTP requests: method, host, URI
tshark -r /tmp/capture.pcap -Y http.request -T fields -e http.host -e http.request.uri | sort -u | head -30
# All conversations: who talked to whom, how much
tshark -r /tmp/capture.pcap -q -z conv,ip | head -40
# Anything NOT dns/http: potential custom C2 on odd ports
tshark -r /tmp/capture.pcap -Y 'not dns and not http and not arp' -T fields -e ip.dst -e tcp.dstport -e udp.dstport | sort -u | head -30
Record the full FakeNet-NG log lines for each C2 attempt: the URI paths and POST bodies often contain the bot ID format and exfiltration structure, which become high-value detection strings.
5. Collecting host behavior
Diff the after-state against the baseline from step 1.
# New or changed files since baseline
find / -xdev -type f -newer /tmp/baseline_marker 2>/dev/null | grep -v -E '^/(proc|sys|tmp)' | head -40
# New processes that outlived the sample
ps -eo pid,ppid,etime,cmd --sort=start_time > /tmp/ps_after.txt
diff /tmp/ps_before.txt /tmp/ps_after.txt | head -40
# Persistence artifacts on Linux
ls -la /etc/cron* /var/spool/cron/ 2>/dev/null
systemctl list-units --type=service --state=running | grep -v -E 'systemd|dbus' | head -20
grep -r . ~/.config/autostart/ 2>/dev/null | head
# Dropped binaries: hash everything new for the IOC list
find /tmp /var/tmp /dev/shm -type f -newer /tmp/baseline_marker 2>/dev/null -exec sha256sum {} \;
On Windows, export the same registry hives as the baseline and diff them,
check HKCU\...\Run and HKLM\...\Run, scheduled tasks (schtasks /query),
and new services. Any dropped PE gets hashed and sent back through
static-triage.
6. Revert and report
Revert first, analyze second. A sandbox that is not reverted is a contaminated lab.
# Revert to the clean snapshot NOW, before writing the report
# (hypervisor-specific; example pattern)
# vm_control revert --vm analysis-win10 --snapshot clean
# Behavior report skeleton
cat > behavior_report.txt <<'EOF'
Sample SHA256: <hash>
Run window: <start> to <stop> UTC
Network: <DNS names queried> / <HTTP URIs> / <odd ports>
Files: <created/modified paths>
Persistence: <registry keys | cron | services | none observed>
Processes: <spawn tree summary>
Dropped binaries: <hashes>
Verdict: <MALICIOUS with behaviors | BENIGN | INCONCLUSIVE>
IOCs: <domains, IPs, hashes, mutexes, file paths>
EOF
Edge cases
- Sample does nothing: it may be waiting for a trigger (specific date, user interaction, reboot, or a C2 that FakeNet-NG did not satisfy). Check static strings for sleep calls and date checks before declaring it benign.
- Sample detects the VM and exits: look for the checks in static analysis (registry keys, MAC addresses, CPUID), then decide whether defeating them is in scope. Do not modify the sample to evade its own checks without explicit authorization.
- Sample needs real internet (domain fronting, valid TLS): real egress is a scope decision, not a technical one. If approved, use a dedicated egress with full capture and a kill switch, never the corporate network.
- Ransomware behavior starts: kill the run immediately, revert, and note that encryption behavior was observed. Do not let it finish encrypting the sandbox "for completeness".
- Multiple stages: the dropper downloads stage two. Capture stage two from FakeNet-NG's served content or the pcap, hash it, and triage it as a new sample.
Escalation
- Behavior is inconclusive after the standard window: extend to 30 minutes with user-interaction simulation (mouse movement, opening documents), or run again after advancing the VM clock past any date checks found in static analysis.
- Sample requires a specific environment (a target application, a locale): rebuild the sandbox to match the victim profile from the incident, then re-run.
- Need API-level detail: escalate to API monitoring (API Monitor, Frida stalking in a lab) or a full debugger session, still inside the sandbox.
- Kernel-mode behavior suspected (driver drops): use a kernel debugger attached to the VM and memory forensics (memory-forensics) on a snapshot taken mid-run.
Detection and defender view
Dynamic analysis is how behavior-based detections are born: every file path, registry key, mutex, DNS name, and HTTP URI you record becomes a candidate detection or blocklist entry. Defenders should operationalize the outputs: feed dropped hashes to the EDR blocklist, the C2 domains to DNS filtering, and the behavior patterns (e.g., "writes to Run key then beacons every 60s") to the SIEM as correlation rules. The lab itself needs defending too: an internet-connected sandbox that detonates real malware is a launchpad, so default-deny egress, snapshot discipline, and no shared credentials between the lab and production are mandatory. Misuse is detonating malware you have no right to possess, or using a sandbox to test whether your own malware evades detection; both are out of scope.
Key references
- MITRE ATT&CK T1204 (User Execution): the detonation moment.
- MITRE ATT&CK T1497.001 (System Checks): sandbox and VM evasion to watch for.
- MITRE ATT&CK T1059 (Command and Scripting Interpreter), T1053 (Scheduled Task/Job): common observed behaviors.
- MITRE ATT&CK T1071 (Application Layer Protocol): C2 over HTTP/DNS.
- FakeNet-NG documentation: https://github.com/mandiant/flare-fakenet-ng
- Wireshark documentation: https://www.wireshark.org/docs/
See also
malware-sandbox-analysis: Use it instead when the work is reading and interpreting a sandbox report, correlating it with static findings, and deriving IOCs.
