Defensive Office macro analyzer that extracts VBA and XLM, deobfuscates strings, and emulates macros in a simulated sandbox to recover commands, shellcode, and dropped payloads.

MaldocTrace is a defensive analyzer for malicious Office documents, written in Go. It extracts VBA and Excel 4.0 (XLM) macros, rebuilds obfuscated strings, and emulates the macros in a fully simulated environment. The output reports what the document would do: the commands it would run, the payloads it would decode and the files it would drop. All of it is backed by evidence that points to the module, procedure and line (or sheet and cell) that produced it.
Documents with no macros at all are covered too. Remote template injection, DDE fields, linked and embedded OLE objects (including Equation Editor exploits in RTF), hyperlinked lure images and VBA stomping are reported as static findings.
Container extraction: OLE/CFB (.doc, .xls, .ppt, including the VBA project and OLE objects PowerPoint keeps in compressed ExOleObjStg records), OOXML (.docx, .docm, .xlsx, .xlsm, .pptm), RTF and raw VBA text. Includes MS-OVBA decompression, UserForm control properties, and resource limits against zip bombs and malformed containers.
Encrypted documents: Excel's default password VelvetSweatshop, a short list of common passwords and any --password you give are tried against:
.xls workbooks encrypted with RC4 or RC4 CryptoAPI (FILEPASS), so cells and Excel 4.0 macro sheets can be read. The VBA project of an .xls is stored outside the encrypted stream and is always extracted;EncryptionInfo/EncryptedPackage with ECMA-376 Standard (AES) or Agile (AES, SHA-1/256/384/512) encryption.The report gives the scheme and the password that worked. When none works, it says so: the absence of macros then proves nothing.
Excel 4.0 (XLM) macros:
.xls (BIFF8 formulas decompiled from parsed tokens, using the MS-XLS function tables) and .xlsm, including hidden and very hidden sheets;Auto_Open (any name Excel would run). It follows GOTO, RUN, IF, WHILE/FOR/NEXT, ON.TIME and RETURN, and applies FORMULA/FORMULA.FILL/SET.VALUE/SET.NAME, so self-decoding macros rebuild their real code;EXEC, CALL, REGISTER and aliases (URLDownloadToFileA, ShellExecuteA, WinExec, CreateProcessA) and FOPEN/FWRITE. Anti-sandbox probes (GET.WORKSPACE, GET.WINDOW, GET.CELL) get plausible answers, flagged as simulated;Static findings (no emulation needed):
attachedTemplate, RTF \*\template, the attached template of Word 97-2003 .doc files);ms-msdt (Follina) monikers;Shell.Explorer.1 browser objects (CVE-2026-21509) and the URL they open, with OLE objects identified by their storage CLSID even when CompObj is missing or forged;INCLUDEPICTURE, INCLUDETEXT and LINK fields (including QUOTE-encoded ones) in .docx, RTF and every story of .doc files (body, headers, footnotes, comments, text boxes), and Excel DDE formulas and links;.doc files (ObjectPool): class and ProgID, OLE Packages (label, original and temp path), URL and file monikers of linked objects (CVE-2017-0199 pattern) and Equation Editor exploits;\objdata, corrupted OLE1 headers), with Equation Editor exploit detection: the MTEF FONT overflow (CVE-2017-11882 / CVE-2018-0802) and the MATRIX overflow (CVE-2018-0798), plus extraction of the bytes that follow;.xls (MBD storages), .doc (ObjectPool) and OOXML (embeddings/) files: linked objects with URL monikers, OLE Packages, Equation Editor data, and the files they carry (PDF with its active-content markers and links, scripts, executables, archives). Embedded documents are analysed recursively and reported under children with their own verdict;checks field);Declare statements with their library and alias) and compares it with the source: string literals or procedures that exist only in the p-code mark the module as stomped, and the code rebuilt from the p-code is what gets emulated. --pcode analyses every module that way.dir stream) that is missing from the PROJECT stream does not appear in the VBA editor but still runs (the EvilClippy technique); it is reported as hidden_vba_module.Payload hiding places: cell values (Sheets("x").Range("A1"), Cells(r, c)), document properties (BuiltInDocumentProperties("Comments"), custom properties), document variables (ActiveDocument.Variables, from .docx settings and the StwUser table of .doc files) and UserForm controls (TextBox.Text, Label.Caption) are all available to the emulated macro.
Document body text: extracted from Word 97-2003 (piece table) and .docx. Droppers often hide their payload in the document body and read it back through ActiveDocument.Paragraphs(n).Range.Text.
VBA interpreter: a lexer, parser and bounded interpreter covering the subset of VBA that malware relies on: procedures, ByRef parameters, named arguments, conditional compilation, loops, arrays and the string built-ins.
Static deobfuscation: constant folding of Chr/StrReverse/Replace/concatenation. Each value records how it was rebuilt (concatenation+Chr, StrReverse, ...).
Simulated environment:
WScript.Shell, Shell, WMI Win32_Process.Create (both GetObject and CreateObject("winmgmts:..."))FileSystemObject, ADODB.Stream (position, text/binary mode and charsets), XMLHTTP/WinHttpMSXML2.DOMDocument elements, including the bin.base64/bin.hex decoding trickMSScriptControl.ScriptControl; commands that the script runs through a WScript.Shell exposed with AddObject are recoveredParagraphs, Range, Delete, SaveAs2Sheets, Worksheets, Range, Cells, Offset), shared with the XLM engine, and ExecuteExcel4Macro/Application.Run into macro sheetsVarPtr pointersPayload recovery:
-EncodedCommand decoding, with static folding of 'ht'+'tp' concatenations before URLs are extractedMultiByteToWideChar(CP_UTF7)certutil -decode, reproduced over a virtual file system built from what the macro wroteScriptControl.AddCode, reported as script payloads rather than command linesShellcode and PE profiling (static; nothing is executed):
block_api hashes and the randomized variant with a seeded, chained hash, resolved to module!function;