This post shows how to design and implement automated malware scanning for diagnostic and test programs on removable media to satisfy NIST SP 800-171 Rev.2 / CMMC 2.0 Level 2 control MA.L2-3.7.4. You will get practical architecture patterns, scripts (Windows and Linux), small-business deployment examples, logging and evidence collection guidance, and compliance-focused best practices so you can demonstrate implementation during an assessment.
Why this control matters and the risk of not implementing it
MA.L2-3.7.4 requires that diagnostic and test programs introduced via removable media be scanned for malicious code before execution. Removable media are high-risk vectors: a single infected USB or diagnostic tool can deliver ransomware, create persistence, or exfiltrate CUI. For small organizations supporting DoD contracts, failure to implement this control can result in non-conformance findings, loss of contracts, and real operational compromise. From a technical standpoint, unscanned tools can bypass perimeter defenses because they're run locally with user privileges.
High-level architecture and components
An automated solution consists of four core components: (1) device insertion detection, (2) automated scanning engine(s) and signature/ITO rule sets (AV, EDR, YARA), (3) quarantine and execution gating, and (4) centralized logging and evidence collection for audits. Architecturally you can implement scanning on endpoint agents (preferred for immediate blocking), on networked gatekeeper stations that users must use to authorize media, or as a hybrid where endpoints perform a quick scan and a gateway performs deeper analysis (YARA, sandboxing, VirusTotal/AV cloud lookups).
Endpoint / Agent-based approach (recommended)
Install an EDR/AV with removable-media policy enforcement on all workstations that might run diagnostic/test software. Configure the agent to: (a) automatically scan mounted removable devices on insertion, (b) block execution of binaries from unscanned locations, (c) quarantine malicious files and (d) emit a device-inserted event to your SIEM. Evidence for assessors: agent configuration screenshots, SIEM events showing scan results, and quarantine logs.
Practical Windows implementation (PowerShell + Defender example)
For many small businesses using Windows, Windows Defender (Microsoft Defender for Endpoint) plus a PowerShell wrapper provides an immediate, low-cost automation path. The example below demonstrates an automated scan triggered by device insertion (Event ID 4663/File system events or by polling) and uses Defender's MpCmdRun or Start-MpScan to scan the drive, then moves infected files to a quarantine folder and logs results to a central share.
# Example PowerShell (run as scheduled task or triggered by Event Log)
$drive = "E:\" # replace with detected drive letter
$scanLog = "\\fileserver\usb-scans\scanlog.csv"
# Update definitions (run periodically)
"%ProgramFiles%\Windows Defender\MpCmdRun.exe" -SignatureUpdate
# Full scan the removable drive
"%ProgramFiles%\Windows Defender\MpCmdRun.exe" -Scan -ScanType 3 -File "$drive"
# Example parse & quarantine logic (simplified)
# Use Defender logs or API to find detection; on detection, move to quarantine share
# Log outcome
$entry = "{0},{1},{2}" -f (Get-Date), $drive, "Scanned"
Add-Content -Path $scanLog -Value $entry
Production scripts should parse Defender event logs (Windows Event IDs 1116/1001 for Defender detections), include robust error handling, and run with least privilege. If you use Microsoft Defender for Endpoint, implement Device Control policies to block unsigned executables from removable media and use advanced hunting queries as evidence.
Practical Linux implementation (ClamAV/YARA + udev or systemd)
On Linux-based scan stations or hardened endpoints, combine ClamAV for signature-based scanning with YARA for pattern/rule-based detection. Use a udev rule to detect new block devices and trigger a systemd service that runs a scanning script. Example udev snippet and systemd service startup:
# /etc/udev/rules.d/90-usb-scan.rules
ACTION=="add", SUBSYSTEM=="block", KERNEL=="sd[a-z][0-9]", ENV{ID_USB_DRIVER}=="usb-storage", RUN+="/usr/local/bin/usb-scan.sh %k"
# /usr/local/bin/usb-scan.sh (simplified)
#!/bin/bash
DEV="/dev/$1"
MNT="/mnt/usbscan/$1"
mkdir -p $MNT
mount $DEV $MNT -o ro
clamscan -r --infected --log=/var/log/usbscan/$(date +%F-%T)-$1.log $MNT
yara -r /etc/yara/rules.yar $MNT >> /var/log/usbscan/$(date +%F-%T)-$1-yara.log
# on detection, copy artifact to quarantine share and send alert
umount $MNT
For a small-business setup, a single hardened Linux "scan station" (even an inexpensive Raspberry Pi 4) with automatic signature updates via freshclam, and a web UI to show scan results, can centralize scanning and reduce endpoint configuration overhead. Keep the scan station on a separate VLAN and enable strict access to the quarantine share.
Small-business real-world scenarios and deployment options
Scenario A β Field technicians with diagnostic tools: Issue company-controlled USB keys or small SSDs recorded in an inventory system. Require technicians to insert devices into a docked scan station before use. The station runs automated ClamAV+YARA scans, logs to the company's SIEM, and stamps the device with a digital βscannedβ label containing timestamp and SHA256 manifest. Scenario B β Office test-labs: Deploy Defender/EDR on lab machines with application whitelisting (AppLocker) to prevent execution from removable media unless the file is signed and scanned. Scenario C β Limited budget: Use a bootable ISO on a locked laptop that runs a preconfigured Linux scanner (offline signatures updated weekly) before any tools are moved to production systems.
Compliance tips, logging, and best practices
Practical tips to satisfy assessors: (1) Document the scan workflow in policy (who, what, when), include screenshots of agent policies, udev rules, or scheduled tasks. (2) Maintain signature update evidence (freshclam/AV update logs). (3) Centralize logs to a SIEM or secure file share and retain them per your data retention policy (e.g., 180 days). (4) Use hashes and code signing to track approved diagnostic tools; keep a βwhitelistβ manifest and require checksums before execution. (5) Disable AutoRun/AutoPlay across Windows, and enforce least privilege so removable media cannot execute without a privileged scan result. (6) Test incident response: simulate a detection and document quarantine/remediation timelines. These artifacts are the direct evidence auditors seek for MA.L2-3.7.4.
Implementation pitfalls and risk mitigation
Common failures include relying solely on manual scans, not collecting logs, not updating signatures, and permitting personal removable media. Avoid these by enforcing technical controls (EDR policies, gateway scanning, application whitelisting), operational controls (mandatory scan workflow, training), and continuous monitoring (alerts, periodic validation scans). The residual risk can be further reduced by combining scanning with network segmentation, limiting write access from removable media, and performing periodic forensic sampling of devices used in the field.
In summary, implementing automated malware scans for diagnostic and test programs on removable media is achievable with modest technical and operational investments. Use endpoint agents for immediate blocking, supplement with dedicated scan stations for high-risk tools, maintain signature and rule hygiene (AV, YARA), centralize logs for evidence, and document your policies and procedures to demonstrate compliance with NIST SP 800-171 Rev.2 / CMMC 2.0 Level 2 MA.L2-3.7.4. For a small business, practical patterns include Defender+PowerShell automation, a hardened Linux scan station, or a hybrid approach with EDR and a quarantine workflow β all of which provide clear, auditable artifacts for assessors while reducing real operational risk.