Skip to main content

VBA static and dynamic analysis tool for malware analysts

Project description

SpuriousEmu

Travis (.com) GitHub tag (latest SemVer) PyPI - Downloads Coveralls github PyPI - Python Version Github - License Code style: black

Visual Basic for Applications tools allowing to parse VBA files, interpret them and extract behaviour information for malware analysis purpose.

Installation

SpuriousEmu is available on PyPI, so you can install it using

pip install spurious-emu

Usage

SpuriousEmu can work with VBA source files, or directly with Office documents. For the later case, it relies on olevba to extract macros from the files. All of the command use a final positional argument to specify the input file to work with.

If you work with VBA source files, the following convention is used:

  • procedural modules have .bas extension
  • class modules have .cls extension
  • standalone script files have .vbs extension

SpuriousEmu uses different subcommands for its different operating modes.

Static analysis

Static analysis is performed using the static subcommand.

Usually, the first step is to determine the different functions and classes defined, in order to understand the structure of the program. You can for example use it to determine the entry point prior to dynamic analysis. It is the default behaviour when using no flag:

emu static document.xlsm

Additionally, for large files, you can use the -o flag to serialize the information compiled during static analysis into a binary file that you will be able to use later with the report command for example:

emu static -o document.spurious-com document.xlsm

Dynamic analysis

You can trigger dynamic analysis with the dynamic subcommand.

Once you have found the entry-point you want to use with the static subcommand, you can execute a file by specifying it with the -e flag. For example, to launch the Main function found in doc.xlsm, use

emu dynamic -e Main doc.xlsm

This will display a report of the execution of the program. Additionally, if you want to save the files created during execution, you can use the -o flag: it specifies a directory to save files to. Each created file is then stored in a file with its md5 sum as file name, and a {hash}.filename.txt file contains its original name. You can also save a report of the dynamic analysis using the -r flag. For example:

emu dynamic -o extract_files -r report.spemu-out doc.xlsm

De-obfuscation

SpuriousEmu will often can fail to interpret VBA program, however it should still be able to help you de-obfuscate macros : that is what the deobfuscate command is for.

It works with a document, source file or compiled file and writes to the standard output a de-obfuscated version of macros that have been found. The most basic invocation is

emu deobfuscate document.docm

You can customize de-obfuscation with two options:

  • Flag -p allows you to evaluate expressions without side effects. Use -p 0 to disable it, -p 1 to only handle literal expressions (e.g. replace "W" + "Scr" & "ip" with "WScript") and -p 2 to also handle pure functions (e.g. replace Chr(37) with "%")
  • Flag -s renames symbols that seem to be obfuscated with legible names (e.g. 1l11l1l to var_1). If it is not specified, all the modules will be de-obfuscated.

Additionally, you can choose to only output a given symbol with the -e flag.

Thus, to de-obfuscate Document_Open, using clear variable names and decrypting XOR-encrypted static strings, use

emu deobfuscate -e Document_Open -p 2 -s document.spemu-com

Finally, you can use the experimental Markov classifier feature : variable names to be demangled are determined by a classifier which tries to compute how English a word appears. It is enabled by the -m flag.

Report production

You can work with .spemu-out and .spemu-com file with the report command.

The report commands can have three mutually exclusive flags: --json, --csv and --table, which change the way reports are displayed.

Similarly to the default static output, you can use the --symbols flag with a .spemu-com file to get the list of functions and classes. For example, to have them in a JSON dump, you can use

emu report --symbols --json program.spemu-com

You can extract the files generated by the execution of a program using the --extract-files flag, which behaves like the -o flag with the dynamic command:

emu report --extract-files files program.spemu-out

A timeline of the events can be produced with the --timeline flag. It can be made easier to read with the --shorten and --skip-streaks commands, as in

emu report --timeline --table --shorten --skip-streaks 10 program.spemu-out

Dependencies

Python 3.8 is used, and SpuriousEmu mainly relies on PyParsing for VBA grammar parsing, and oletools to extract VBA macros from Office documents. Report tables are generated using PrettyTable.

nose is used as testing framework, and mypy to perform static code analysis. lxml and coverage are used to produce test reports.

Tests

To set a development environment up, use poetry:

poetry install

Then, use nose to run the test suite:

poetry run nosetests

All test files are in tests, including: - Python test scripts, starting with test_ - VBA scripts used to test the different stages of the tools, with vbs extensions, stored in source - expected test results, stored as JSON dumps in result

You can use mypy to perform code static analysis:

poetry run mypy emu/*.py

Both commands produce HTML reports stored in tests/report.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

spurious_emu-0.4.1.tar.gz (67.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

spurious_emu-0.4.1-py3-none-any.whl (73.6 kB view details)

Uploaded Python 3

File details

Details for the file spurious_emu-0.4.1.tar.gz.

File metadata

  • Download URL: spurious_emu-0.4.1.tar.gz
  • Upload date:
  • Size: 67.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.10 CPython/3.8.5 Linux/5.8.2-arch1-1

File hashes

Hashes for spurious_emu-0.4.1.tar.gz
Algorithm Hash digest
SHA256 5acfefffb6e4ba5b8c7c7e01c0604569bc26de930394b2ad57d2d60fcd6fd51f
MD5 213c5091cf9bafe34a7a4d5d2f91d4c5
BLAKE2b-256 ff96660a361d3b4e95fcd845640bb36c2ff480b675c0ffdf3f9320e9c8d534e3

See more details on using hashes here.

File details

Details for the file spurious_emu-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: spurious_emu-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 73.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.10 CPython/3.8.5 Linux/5.8.2-arch1-1

File hashes

Hashes for spurious_emu-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2bcc8b683d9120422f1d942bee6eebe835036ae630ba3972265c4ce193b4399c
MD5 813275b1e5e102f8a11f7ea06cfabfdc
BLAKE2b-256 db1d738ac98943f1519c378547dcbff6c9a4fa74eb0f97ca2bc423f69bf61379

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page