IC00AJ74 · Week 4 · activity 3

Task 3: Deeper analysis of the Office document

Extract and analyze an obfuscated macro and the executable it drops.
180minutes
1point

You work at a very big company as a Security Analyst. Someone has sent a suspicious email message to the Chief IT in charge, and she wants the message analysed by you. She saved the message and delivered it in .eml format for you.

The file can be found here.

Saved email messages are based on the RFC 822 standard in most cases. For example, Thunderbird, Outlook, and Gmail export in this format by default, when you want to save a single message. Could we parse the file and see the content without using these clients? Could we get potential attachments as well?

There are ways to get the attachment with tools like ripmime and munpack.

This suspicious email has an archived document file as an attachment - once it has been acquired, we can start analysing it like in the previous task with the same tools.

What does it look like? Macros again? Are they executed automatically?

At first, you can take a look at the document with the tools from the previous task.

However, in this case, the macro in the document is obfuscated, and by looking at the source, functionality might be hard to understand. Luckily for us, obfuscation is implemented a bit poorly, and we could use a specific tool for emulating the execution of the macro, and see at some level what it is doing!

This tool, called vipermonkey, is intended to analyze and deobfuscate malicious VBA Macros in the Microsoft Office files. It attempts to run macros to see interesting commands and their possible arguments. A tool is not perfect, but it works for most of the documents, and also in this case.

The easiest way to run it is the Docker image:

docker run --rm -v $PWD:/w -w /w cincan/vipermonkey <FILENAME>

ViperMonkey is not available on PyPI, and its PyPI-installable GitHub archive does not work on Python 3.10 or newer.

Emulation might be slow, depending on your computer.

Tips for deobfuscating the whole macro (Click here)

Vipermonkey is not revealing the one file write operation action, which is related to acquiring embedded data (executable) from the .doc file. You should figure out how it is stored and extract it.

Can you guess it from the macro source code? If you have a suitable environment or you know what you are doing, you could run code on real Word and debug runtime variables with breakpoints to see the content.

Note If you can’t do that, you can also try to modify the source code to print variable contents in such a way that vipermonkey captures the output. Just run the macro alone and again in vipermonkey to see the output of the prints.

Some helpful documentation about the Word Visual Basic API.

Another way is to attempt to find interesting information from unexpected places.

With oledump, try to compare the sizes and contents of different sections of the file, if there is something strange, particularly in the summary sections. With oledump, you can also view/dump contents from different sections. Vipermonkey finds this same data as potential IOCs; we just don’t know what that is, where it is coming from, and what its purpose is.

You can use oledump to extract the specific macros as plaintext and save them into a file with:

python3 DidierStevensSuite/oledump.py -s <macro_number> -v <Malicious_doc> > <OUTPUT_FILE>

Macro code is using something from there. Which part was related to the actual file structure?

Documentation for the file structure is available here.

What shell commands was the macro executing? Could you briefly describe the idea of carrying the malware and commands? Can we acquire this dropped executable from the document file?

There are a lot of encoded strings, and the command line tool base64 could be useful. Also, if the output is a bit strange, you can use the file command to see the guessed file type.

Once we get our hands on this executable, we can go even further. The file command might tell the type of the executable, and in this case, it is an unprotected .NET assembly.

Because of the way .NET assemblies are created, they can be reversed back into readable source code, if some extra protection is not applied.

And we are about to do that; a tool named ILSpy is capable of decompiling .NET assemblies.

What is this executable doing? How is it trying to persist in the system? Is it dropping even more files?

It is getting at least one file over the internet, and that is protected somehow. The command-line interface of openssl could be useful here for decrypting it. The binary contains the required information for doing that.

Figuring out the functionality of this file is left for the next task.

Shared files

  • Your_great_reward_is_here.emlBinary
    Download

Shared files

  • Your_great_reward_is_here.emlBinary
    Download