Practice library / Security operations basics
Lab · Medium · 1.5 hoursFree account
Malicious Document Analysis
Analyse malicious Office documents, PDFs, and macros with olevba and remnux.
On this page 13 sections
- ·Prerequisites
- ·Lab Setup
- 1Fingerprint the file
- 2Triage with oleid and mraptor
- Locked: Open the container
- Locked: Extract the macro source
- Locked: Decode the obfuscation
- Locked: Check a .docx for template injection and embedded objects
- Locked: Write a YARA rule
- Locked: Write the IOC list
- Locked: Defence and Detection
- Locked: Check Your Work
- Locked: Clean-up
A weaponised Office document or PDF is still the most reliable way to land malware on a corporate endpoint, because a user opening a file feels normal in a way that running an executable does not. Working safely on a REMnux box, you fingerprint containers, pull VBA from macros, decode staged payload URLs, find template injection in a .docx, and write a YARA rule that catches the sample again.
What You'll Learn
- Identify the container of an Office file (OLE or OpenXML) and find where macros and external links hide
- Run
oleidandmraptorto triage a file in under a minute - Extract VBA source with
olevbaand read its keyword table - Decode Base64 and
Chr()strings to find a staged payload URL - Find template injection and embedded objects in a
.docx - Write a YARA rule for the macro and list the indicators of compromise (IOCs)
A phishing email with an Office attachment is still a common first step of an intrusion. The file looks like an invoice. Inside, a macro or a remote template starts a download. Your job as a defender is to learn what the file does without opening it in Office.
All work in this lab is static analysis. You read the file with tools. You never run the macro.
Prerequisites
Finish the Malware Analysis workbook first. It explains safe handling, hashes and the static and dynamic analysis phases.
Step 7 uses YARA. If you did not write a rule before, do the short YARA & Sigma for Defenders lab first or after this one.
Lab Setup
Use your own analysis VM (Kali or REMnux). You need these tools:
oletools(givesoleid,mraptorandolevba). Install it withpip3 install oletoolsorsudo apt install python3-oletools.yara,unzip,file,sha256sum,base64,iconvandgrep.
You need two samples: one macro workbook (.xlsm) and one .docx. Take them from a public research collection such as the InQuest malware-samples repository on GitHub, and place them in ~/samples. Public collections often zip their files with a password. The README of the collection gives it.
In this lab the files are called sample.xlsm and sample.docx. Your file names and your output will differ. The method is the same.
These files are real malware. Use only the isolated analysis VM, with no route to the internet or to other machines. Do not open them in Word or Excel. Do not copy them to a production computer. Take a VM snapshot before you start. On a real case you also have written permission to handle the file.
Make a work folder and copy the samples into it.
mkdir -p ~/maldoc && cd ~/maldoc
cp ~/samples/sample.xlsm ~/samples/sample.docx .Step 1: Fingerprint the file
Hash the file and check its real type
A file name and an extension are only labels. The hash identifies the file. The magic bytes (the first bytes of the file) show its real format.
Hash both files and save the values. You need the hashes for your report and for a lookup in a threat-intelligence service.
sha256sum sample.xlsm sample.docx | tee hashes.txtExample output:
9b1c4e0f6d2a7b83c5e1f0a9d4b6c2e8f7a3d1b5c9e0f2a4b6d8c0e1f3a5b7c9 sample.xlsm
4e7a2c9d1b3f5a8e0c6d4b2f9a7e1c3d5b8f0a2e4c6d9b1f3a5c7e8d0b2f4a6c sample.docxShow the file type.
file sample.xlsm sample.docxExample output:
sample.xlsm: Microsoft Excel 2007+
sample.docx: Microsoft Word 2007+Both files are Microsoft ... 2007+. This format is OpenXML, and an OpenXML file is a ZIP archive. The older .doc and .xls formats use a different container called OLE (Object Linking and Embedding). The tools in this lab read both.
Step 2: Triage with oleid and mraptor
Decide in one minute if the file has active content
oleid lists indicators: macros, Excel 4 macros, embedded objects and external links. mraptor (MacroRaptor) judges the macro itself. It looks for three behaviours: Auto-run, Write to disk and eXecute.
Run oleid on the workbook.
oleid sample.xlsmExample output:
Filename: sample.xlsm
--------------------+--------------------+----------+-------------------------
Indicator |Value |Risk |Description
--------------------+--------------------+----------+-------------------------
File format |MS Excel 2007+ Macro|info |
|-Enabled Workbook | |
|(.xlsm) | |
Container format |OpenXML |info |Container type
Encrypted |False |none |The file is not encrypted
VBA Macros |Yes, suspicious |HIGH |This file contains VBA
| | |macros. Suspicious
| | |keywords were found.
XLM Macros |No |none |
External |0 |none |External relationships
Relationships | | |such as remote templatesLook at the line VBA Macros. The value Yes, suspicious with risk HIGH means that oleid found a macro with an auto-run keyword or a keyword that runs commands.
Run mraptor on the same file.
mraptor sample.xlsmExample output:
----------+-----------+---------------------------------------------------------
Result |Flags |Filename
----------+-----------+---------------------------------------------------------
SUSPICIOUS|AWX |sample.xlsmSUSPICIOUS with flags AWX means the macro runs by itself, writes data and executes it. A macro with only A is often harmless. The three flags together are the profile of a downloader.
Now check the .docx.
oleid sample.docx | grep -E 'VBA|External|Embedded'Example output:
VBA Macros |No |none |
External |1 |HIGH |External relationships
Relationships | | |such as remote templatesA .docx cannot hold a macro. This one has no VBA, but it has one external relationship, rated HIGH. You find out why in Step 6.
oleid shows a row XLM Macros. Excel 4.0 macros live in hidden sheets, not in VBA, and olevba does not read them. If this row says Yes, use the tool XLMMacroDeobfuscator (xlmdeobfuscator --file sample.xlsm).
Sign in to continue
9 more sections are for signed-in members. It is free: sign in with Google.
Related
This lab is extra practice for the course Security operations basics. Do the lessons first.Open the course