livewells
Menu

Macro emulation

Attackers hide the links, commands and file names of a macro behind many small steps. The macro builds them while it runs, so they stay hidden in the text of the macro.

livewells follows the macro code step by step, in a disposable container. It reads the code as data and works out what the macro builds. It reports the links, commands and file names that it finds.

Send a file with macros

Send a Word, Excel or PowerPoint file on the Upload a file tab, or through the API. livewells follows the macros of every Office file it reads. See Word, Excel, PowerPoint and RTF files.

What livewells follows

CodeWhere it comes from
VBA macrosWord, Excel and PowerPoint files, in the Open XML format (.docx, .xlsx, .pptx) and in the older binary format
Excel 4.0 macros (macro sheets)Excel files, including hidden and very hidden sheets
Compiled macro codeFiles where the compiled code is different from the visible macro text

livewells follows the code of one document at a time. An Office file inside another Office file is a document of its own, up to three levels deep.

How livewells follows the code

  1. livewells starts at the places that start by themselves: names such as AutoOpen and Document_Open, the names that start a macro sheet, and the click and event handlers that the file lists. A macro with no start has every procedure that needs no input followed.
  2. livewells works out the built-in functions the way Office does, and reads the values that the file keeps for the macro: document variables, properties, form and control values, cell values and document text.
  3. livewells follows loops, branches, calls between modules and strings that the macro builds in many functions. When the macro writes more macro code, livewells follows that code too.
  4. When the macro builds a command line, livewells decodes the line. This covers PowerShell encoded commands, base64 and compressed text, joined and reversed text, character codes and the escape marks of the command prompt.

Calls that reach outside the file

Many macros start a program, connect to an address or write a file. livewells records each of these calls as a call that the macro would make. It shows the call with its decoded arguments. The arguments are the links, commands and paths that you look for. The calls stay in the report.

GroupExamples
Start a programShell, WScript.Shell run and exec, ShellExecute, WMI process create, Excel 4.0 EXEC
Connect to an addressXMLHTTP and WinHttp requests, downloads through URLDownloadToFile, HYPERLINK
Write or change filesOpen for output, FileSystemObject, ADODB.Stream save, Kill, FileCopy, MkDir
Change the registryRegWrite, RegDelete, SaveSetting
Start a script hostScript control AddCode, Eval and ExecuteStatement
Call a system libraryEvery Declare line, and each call through it
OtherTimed macros (OnTime, OnKey), SendKeys, Run of a name that is not in the file

When a macro creates an object that livewells cannot model, the call returns an empty value and the report lists the object under Unknown functions and differences.

What the report shows

  • Decoded strings. The text that the macro built, with the steps that made it. Each string shows where in the macro it was made.
  • Indicators. Links, host names, addresses, mail addresses, file names, commands, registry keys, paths and the SHA-256 of decoded payloads and written files. Each indicator names the decoded string that holds it.
  • Calls the macro would make. The table in the section above, with the decoded arguments.
  • Second stages. Command lines and scripts that the macro built, with the layers that livewells removed. Programs and shell code that the macro builds are shown by their size and SHA-256.
  • Written files. Each file that the macro would write, with its size, its SHA-256 and the start of its text.
  • Code that the macro writes. Macro code, scripts and Excel 4.0 formulas that the macro writes and then runs.
  • Obfuscation methods. The tricks that livewells met. The table below lists them.
  • Where. Each finding shows its place: a module and line, a compiled code position, or an Excel 4.0 sheet and cell. A finding from compiled code is labelled as such.
  • Compiled and visible code. When the two differ, livewells follows both. The report lists what only one of them does.

Each web address that the macro builds is an item that you can send to the browser with one click. livewells opens it in a disposable browser. Every address, host name and mail address in the report is defanged. For example, an address appears as hxxps[://]login[.]example[.]com/verify. No address in a report is a link that you can click.

Obfuscation methods

MethodWhat it means
Joined textThe macro joins many small pieces of text.
Character codesThe macro builds text from Chr or ChrW codes.
Computed character codesThe macro does a sum, a product or a remainder to get each code.
Reversed textThe macro reverses the text.
Replaced textThe macro removes or swaps marker text.
XorThe macro decodes with the Xor operator.
Base64The macro decodes base64.
Hex textThe macro decodes hexadecimal text.
Picked charactersThe macro picks single characters from other text.
Joined listsThe macro joins the items of a list.
Text conversionThe macro changes the case or the code page of text.
Format stringsA command line builds text with a format string.
Compressed textThe macro unpacks compressed data.
Environment textThe macro takes characters from environment values.
Excel 4.0 charactersAn Excel 4.0 macro builds text with CHAR.
Excel 4.0 joinsAn Excel 4.0 macro joins cells.
Decode loopsThe macro decodes text in a loop.
Dynamic callsThe macro picks the name of a call at run time.
Document dataThe macro reads its text from the document.
Self-writing codeThe macro writes code and runs it.
Many functionsThe macro builds one string in three or more functions.
Junk codeMuch of the code never runs.
Dead branchesA branch can never run, and it holds code.
Compiled code differsThe compiled code and the visible text are not the same.
Encoded PowerShellA command line holds an encoded PowerShell command.
Escape marksA command line hides its words with ^ or backtick marks.

Status of each document

Each module and each Excel 4.0 sheet has a status.

StatusWhat it means
Decodedlivewells followed all the code that can run.
Partly decodedlivewells stopped early, met code that is unknown to it, or could not read a statement. The report gives the reason.
Not decodedlivewells could not read the code.
Not checkedlivewells did not follow the code. The reason is that the file is locked, or that the compiled code could not be read.
Not supportedThe macro data has a version that this checker cannot read.

When a document is partly decoded, treat the file as hostile and read the indicators that livewells found. The report gives the reason: a step, time, memory, string, array, compression or output limit, a function that is unknown to livewells, or a statement that livewells could not read.

Limits

LimitValue
Steps5,000,000
Memory384 MiB
One string1 MiB
One array1,000,000 items
Unpacked data1 MiB, and at most 100 times the packed size
Calls inside calls200
Decoded strings kept500, each up to 2,048 characters
Indicators500
Calls the macro would make500
Second stages50
Written files24
Unknown items for one module100
Report size for this part1 MiB

A macro that goes over a limit gets the status Partly decoded. livewells keeps the findings that it made before the limit and lists the limit in the report.

Flags

LevelWhat livewells tells you
HighThe macro would start a program.
HighThe macro would connect to another computer.
HighThe macro would start a script host.
HighThe macro builds a second program or script.
HighThe stored code and the visible code differ.
HighThe macro writes new macro code and runs it.
HighThe macro builds a link that is not visible in the file.
MediumThe macro would write a file to disk.
MediumThe macro would change or read the Windows registry.
MediumThe macro hides its text with encoding tricks.
MediumPart of the macro code was not emulated.
MediumThe macro data could not be read.
MediumThe macro data was too large to read.
MediumThe file is locked. The macro code was not read.
MediumThe macro emulator stopped on this file.
LowThe macro calls functions that are outside the livewells model.
InfoThe macro has no automatic start. All procedures were emulated.
InfoThe Excel 4.0 macro starts when the workbook opens.