Heap-based AMSI bypass for MS Excel VBA and others
The blog post describes a heap-based AMSI bypass for Excel VBA that corrupts the AMSI context on the heap to make AmsiScanBuffer fail, causing Excel to treat the payload as not malicious. An attacker with VBA code execution could evade AMSI scanning, but the bypass requires a trigger function to be called and may be slow in pure VBA.
This blog post describes how to bypass Microsoft's AMSI (Antimalware Scan Interface) in Excel using VBA (Visual Basic for Applications). In contrast to other bypasses this approach does not use hardcoded offsets or opcodes but identifies crucial data on the heap and modifies it.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the AMSI context is stored on the heap with a magic value, and if that value is corrupted, AmsiScanBuffer fails and the caller treats the payload as not malicious.
Impact
An attacker with VBA code execution in Excel could bypass AMSI scanning, but the bypass may be slow (seconds to minutes) and requires a trigger function to be called; Microsoft states AMSI is not a security boundary.
What the attacker needed
Code execution in Excel via VBA; victim opens a malicious document; AMSI context present on heap
How it was found
- Implement a small AMSI client in C that calls AmsiInitialize and AmsiScanBuffer on a test string.
- Walk the heap of the process to find chunks starting with the ASCII characters 'AMSI'.
- Overwrite the magic bytes of the AMSI context with garbage.
- Verify that AmsiScanBuffer returns a failure and the payload is no longer flagged.
- Port the heap-walking and memory-corruption logic to VBA using imported functions like RtlMoveMemory or CryptBinaryToStringA.
- Trigger AMSI by calling a known malicious VBA function to confirm the bypass works.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
AMSI is a Windows feature that lets antivirus scan scripts before they run. This post shows a way to break AMSI's internal data so it stops working, letting malicious VBA code run without being flagged. The attacker needs to already run code in Excel, for example by tricking a victim into opening a document.
What is Access control?
A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.