Skip to content

VBE self-modifying macros, RTF/altChunk extraction fixes and issue #24 - #28

Merged
debugactiveprocess merged 5 commits into
mainfrom
vbe-self-modifying-macros
Dec 3, 2026
Merged

debugactiveprocess merged 5 commits into
mainfrom
vbe-self-modifying-macros

Conversation

@debugactiveprocess

Copy link
Copy Markdown
Owner

Summary

Emulation

  • Emulate the VBE object model (VBComponents(...).CodeModule: Lines, InsertLines, ReplaceLine, AddFromString, ...) so self-decrypting macros and macro viruses run their revealed code; new vba_self_replication, vba_code_modification and vba_code_executed findings.
  • Fix single-line If parsing (statements after : and Else) and modules with bare CR line breaks.

Extraction

  • Read altChunk imports and OOXML embeddings up to the input limit (a padded 54 MB RTF dropper was reported clean).
  • Ignore other RTF destinations nested in \objdata (\panose text shifted the hex stream) and extract files from OLE1 Package objects.

Issue #24

  • Default step budget 10M (was 1M), shared by all modules of a project; emulation may use half of the timeout; budget exhaustion is reported in diagnostics and verdict reasons.
  • Decode -EncodedCommand behind cmd /c / %ComSpec% wrappers (HTA droppers) and FromBase64String literals (C# loaders).
  • Drop .NET names, Base64 and junk fragments from domain indicators; end URLs at typographic quotes.
  • --dump-payloads manifest kinds follow how the artifact was found.
  • Interpreter performance: Mid/Left/Right/Len/InStr, repeated concatenation and ReDim Preserve growth are linear instead of quadratic; InStr returns character positions on non-ASCII text.

Regression (old build vs this branch, same files)

Set Verdict up Verdict down Hit time budget
2026 corpus (1,021 files) 11 0 0
Recent MalwareBazaar samples (245) 6 0 0

go test ./... and go vet ./... pass.

Closes #24

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.
@debugactiveprocess
debugactiveprocess merged commit ae606cd into main Dec 3, 2026
8 checks passed
@debugactiveprocess
debugactiveprocess deleted the vbe-self-modifying-macros branch December 3, 2026 03:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Script loaders: step budget, -EncodedCommand in HTA, Base64 in -Command, indicator noise

1 participant