Repository navigation
VBE self-modifying macros, RTF/altChunk extraction fixes and issue #24 - #28
Merged
Merged
Conversation
Single-line If: only the first statement after Then was conditional,
statements after ':' always ran and Else was parsed as a call to a
procedure named "Else". A guard such as
If x = "" Then MsgBox "...": Exit Sub
therefore ended every procedure before the rest of it was emulated.
Colon-separated statements, Else branches and "If x Then: a Else: b"
are now parsed as VBA does.
Modules stored with bare CR line breaks were read as a single line,
which produced a false vba_stomping finding ("no procedures in its
source") and wrong IOC line numbers. Module source is now normalised to
CRLF on extraction, including --input-format vba.
New static rules on VBA that writes code through the VBE object model:
vba_self_replication (high, malicious) when the code goes into
Normal.dotm / Personal.xlsb, and vba_code_modification (low) otherwise,
since legitimate tools (Oracle Web ADI, form generators) also do it.
Checked on 843 Office samples from MalwareBazaar (2026): 5 reports
change, one macro virus goes from suspicious to malicious and two
procedures are now emulated past their Exit Sub guard.
…macros VBProject -> VBComponents -> CodeModule is modelled over each module's real source and an empty Normal.dotm (NormalTemplate): Lines, CountOfLines, Find, ReplaceLine, InsertLines, DeleteLines and AddFromString. When a module's source changes, the interpreter re-reads its procedures before the next call, so a macro that decrypts its own body and then calls it runs the decrypted code. Options.VirusProtection and friends are modelled too. Reporting: - vba_code_write / vba_template_infection events, one per call site with a call count, and security_setting_disabled events. - Code inserted into a module (the copy a virus writes into Normal.dotm) is kept whole as a "VBA source (code module)" artifact, hashed and saved by --dump-payloads as .txt. - Each module that revealed code is also delivered decoded: its source at the moment most of it was rewritten, deduplicated by hash with the copy above. - Text output summarises code writes on one line and lists the decrypted or generated lines in a new "Code revealed at run time" section. - vba_code_executed finding (medium) for code written at run time and then run; the VBA project rules also run on revealed code. On the Sattelite v1.0 macro virus the report goes from suspicious 45 to malicious 100 with the decrypted replication code; on 843 Office samples from MalwareBazaar (2026) no other verdict changes.
.docx droppers pad an altChunk RTF past the 32 MiB per-part limit (about 54 MB of table junk around an Equation.3 object with \objupdate). The part was skipped with an info diagnostic and the import was not counted, so the document was reported clean. altChunk imports and OOXML embeddings are analysed as files of their own, so they are now capped by MaxInputSize instead of MaxModuleSize. A part beyond every limit is reported as an altchunk/embedded_ole finding and recorded in LimitsHit, so it cannot look clean. Three samples change from clean to malicious: two MalwareBazaar samples of 2026-11-24 and one in the 2026 corpus. No other verdict changes across 917 samples.
Droppers insert groups such as {\dao97556105\panose "function
hexadeciamlTobinary(){...}"} into \objdata. Word sends that text to
\panose, but every hex letter in it was read as object data, shifting
the rest of the object by a nibble: a 3.6 KB Equation.3 object decoded
as 720 KB of noise and an OLE Package looked like a corrupted header.
Text after an RTF destination control word in a nested group is now
skipped, as Word does.
RTF Package objects now deliver the file they carry, so a VBScript
dropped by an RTF is extracted and emulated.
On the 2026 corpus, 54 droppers improve and none regress, including
VBScript and PE DLL packages and 5 CVE-2017-11882 exploits that were
not detected.
… noise (#24) - Default interpreter budget is now 10M steps, shared by all modules of a project; emulation may use half of the timeout. Budget exhaustion is reported in diagnostics and verdict reasons. - Remove cmd /c and %ComSpec% wrappers before PowerShell detection so -EncodedCommand is decoded; decode FromBase64String literals as payloads. - Drop .NET names, Base64 and junk fragments from domain indicators; end URLs at typographic quotes. - Label --dump-payloads manifest kinds by how the artifact was found. - Make Mid/Left/Right/Len/InStr, repeated string concatenation and ReDim Preserve growth linear instead of quadratic; fix InStr returning a byte offset on non-ASCII text.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Emulation
VBComponents(...).CodeModule:Lines,InsertLines,ReplaceLine,AddFromString, ...) so self-decrypting macros and macro viruses run their revealed code; newvba_self_replication,vba_code_modificationandvba_code_executedfindings.Ifparsing (statements after:andElse) and modules with bare CR line breaks.Extraction
altChunkimports and OOXML embeddings up to the input limit (a padded 54 MB RTF dropper was reported clean).\objdata(\panosetext shifted the hex stream) and extract files from OLE1 Package objects.Issue #24
-EncodedCommandbehindcmd /c/%ComSpec%wrappers (HTA droppers) andFromBase64Stringliterals (C# loaders).--dump-payloadsmanifest kinds follow how the artifact was found.Mid/Left/Right/Len/InStr, repeated concatenation andReDim Preservegrowth are linear instead of quadratic;InStrreturns character positions on non-ASCII text.Regression (old build vs this branch, same files)
go test ./...andgo vet ./...pass.Closes #24