Safeguard
Application Security•

Detecting and Mitigating VBA Stomping (T1564.007)

VBA stomping swaps macro source for harmless text while leaving compiled code to run. What MITRE documents, why source scanners miss it, and how to limit VBA.

Safeguard Security Team
2 min read

A scanner that reads macro source code sees what the document wants it to see. VBA Stomping (T1564.007) is a Stealth technique for Linux, macOS and Windows, and a subtechnique of Hide Artifacts.

How attackers use it

MITRE explains that Office documents with embedded VBA store source code in module streams. Each module stream has a PerformanceCache holding a separate compiled version of the code, known as p-code. The p-code runs when the Office version recorded in the _VBA_PROJECT stream matches the host application's version.

An adversary can overwrite the source location with zeros, benign code or random bytes, while leaving the previously compiled malicious p-code in place. Tools that scan VBA source can then be bypassed, because the unwanted code now lives only in the compiled form. If the source is removed, some tools may even conclude there are no macros at all.

If the versions match, the p-code is executed. If they do not, the benign source is decompressed and recompiled to p-code, which removes the malicious p-code and may defeat dynamic analysis.

How to detect it

MITRE's analytics focus on mismatches:

  • Discrepancies between VBA source code and p-code inside Office documents.
  • Anomalies in file metadata streams.
  • Office processes running macros with no visible or consistent source.
  • On Linux, Wine or LibreOffice macros with inconsistent VBA metadata, found through file analysis that shows p-code without matching source.

Document analysis tools that compare source and p-code are the direct answer. For triage on endpoints, an Office process running a macro that your scanner reported as having none or as benign is the case to chase.

How to reduce the risk

MITRE lists one mitigation: disable or remove feature or program. Turn off or restrict access to VB components that are not needed. If nobody in a department uses macros, no policy exception is needed.

Quick check

Why does stomping defeat tools that only read VBA source?

The source is replaced with harmless content, but the compiled p-code still holds the malicious logic and can be executed.

Sources

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.