r/Malware • u/ironbitss • 13h ago
Emulating VBScript Execute chains and environment checks for static maldoc triage: notes from building an analyzer
I maintain MaldocTrace, an open-source maldoc analyzer (disclosure: I'm the author). The newest release focuses on OneNote droppers, and I wanted to share what it took to recover the final command from IcedID, Emotet and Gozi .one samples without execution, since a lot of the obstacles are generic.
1. The payload is built at run time. These scripts concatenate, Replace() and Chr() their way to a string and pass it to Execute or ExecuteGlobal. A regex over the source sees noise. Running the statements in an emulator and handing the built string back to the interpreter unwinds the obfuscation layer by layer.
2. Stages are written to disk and launched. A typical chain writes a small .vbs and a larger file with a harmless extension (.html), then runs wscript /e:vbscript file.html. The emulator keeps a virtual file system, so when a written file is launched it is analyzed as the next stage, with its own hash and report.
3. Some branches depend on things that never happen in a static run. For example "if the downloaded file is larger than N bytes, run it". Without a network the condition is false and the interesting branch is never reached. When a condition can't be resolved, both sides are explored and the events from the unresolved side are marked speculative, so the analyst knows which commands are certain and which are conditional.
Example: IcedID OneNote dropper, SHA-256 4cdab0573e8b094fe8937a00c833cee67b8ccd9dbb5ae706624e5c12bdb7ae21. The chain it recovers:
OneNote FileDataStoreObject (49 KB VBScript)
-> writes %TEMP%\rad5F3A1A3F5dar.vbs and %TEMP%\rad5F3A1A3F5dar.html, runs the .vbs
-> wscript /e:vbscript %TEMP%\rad5F3A1A3F5dar.html
-> rundll32.exe "C:\Users\user\AppData\Local\Temp\rad5F3A1.tmp.html",#1The three intermediate scripts come out with their SHA-256 as IOCs (61e30e50…, 71490a53…, 833d25d9…), and the second-stage URL is among the indicators of the last stage.
Limitations, to be upfront: it's an emulator, so it covers a supported subset of VBScript/VBA and the Windows objects malware commonly uses. When it hits something it doesn't model, the report says partial instead of guessing.
Code and docs: https://github.com/debugactiveprocess/MaldocTrace
I'd like to hear about chains it fails on.
