HackTricks
Searchโ€ฆ
๐Ÿ‘ฝ
Network Services Pentesting
Office file analysis
Support HackTricks and get benefits!
โ€‹
โ€‹
Through Security Skills as a Service, we help organizations to defend against the Dark Hacking Arts. Security Skills as a Service is an offensive cybersecurity consultancy model that combines an Intelligent Platform with the top-class, globally distributed, offensive security engineers, delivering high-quality penetration testing results. Security Hubs bring together offensive penetration testing tactics with human behavioral science, providing real-time insights into threat actors' tradecraft and a complete assessment of any risks.
Security Skills as a Service | Security Hubs

Introduction

Microsoft has created dozens of office document file formats, many of which are popular for the distribution of phishing attacks and malware because of their ability to include macros (VBA scripts).
Broadly speaking, there are two generations of Office file format: the OLE formats (file extensions like RTF, DOC, XLS, PPT), and the "Office Open XML" formats (file extensions that include DOCX, XLSX, PPTX). Both formats are structured, compound file binary formats that enable Linked or Embedded content (Objects). OOXML files are actually zip file containers, meaning that one of the easiest ways to check for hidden data is to simply unzip the document:
$ unzip example.docx
Archive: example.docx
inflating: [Content_Types].xml
inflating: _rels/.rels
inflating: word/_rels/document.xml.rels
inflating: word/document.xml
inflating: word/theme/theme1.xml
extracting: docProps/thumbnail.jpeg
inflating: word/comments.xml
inflating: word/settings.xml
inflating: word/fontTable.xml
inflating: word/styles.xml
inflating: word/stylesWithEffects.xml
inflating: docProps/app.xml
inflating: docProps/core.xml
inflating: word/webSettings.xml
inflating: word/numbering.xml
$ tree
.
โ”œโ”€โ”€ [Content_Types].xml
โ”œโ”€โ”€ _rels
โ”œโ”€โ”€ docProps
โ”‚ โ”œโ”€โ”€ app.xml
โ”‚ โ”œโ”€โ”€ core.xml
โ”‚ โ””โ”€โ”€ thumbnail.jpeg
โ””โ”€โ”€ word
โ”œโ”€โ”€ _rels
โ”‚ โ””โ”€โ”€ document.xml.rels
โ”œโ”€โ”€ comments.xml
โ”œโ”€โ”€ document.xml
โ”œโ”€โ”€ fontTable.xml
โ”œโ”€โ”€ numbering.xml
โ”œโ”€โ”€ settings.xml
โ”œโ”€โ”€ styles.xml
โ”œโ”€โ”€ stylesWithEffects.xml
โ”œโ”€โ”€ theme
โ”‚ โ””โ”€โ”€ theme1.xml
โ””โ”€โ”€ webSettings.xml
As you can see, some of the structure is created by the file and folder hierarchy. The rest is specified inside the XML files. New Steganographic Techniques for the OOXML File Format, 2011 details some ideas for data hiding techniques, but CTF challenge authors will always be coming up with new ones.
Once again, a Python toolset exists for the examination and analysis of OLE and OOXML documents: oletools. For OOXML documents in particular, OfficeDissector is a very powerful analysis framework (and Python library). The latter includes a quick guide to its usage.
Sometimes the challenge is not to find hidden static data, but to analyze a VBA macro to determine its behavior. This is a more realistic scenario, and one that analysts in the field perform every day. The aforementioned dissector tools can indicate whether a macro is present, and probably extract it for you. A typical VBA macro in an Office document, on Windows, will download a PowerShell script to %TEMP% and attempt to execute it, in which case you now have a PowerShell script analysis task too. But malicious VBA macros are rarely complicated, since VBA is typically just used as a jumping-off platform to bootstrap code execution. In the case where you do need to understand a complicated VBA macro, or if the macro is obfuscated and has an unpacker routine, you don't need to own a license to Microsoft Office to debug this. You can use Libre Office: its interface will be familiar to anyone who has debugged a program; you can set breakpoints and create watch variables and capture values after they have been unpacked but before whatever payload behavior has executed. You can even start a macro of a specific document from a command line:
$ soffice path/to/test.docx macro://./standard.module1.mymacro

โ€‹oletoolsโ€‹

sudo pip3 install -U oletools
olevba -c /path/to/document #Extract macros

Automatic Execution

Macro functions like AutoOpen, AutoExec or Document_Open will be automatically executed.

References

Support HackTricks and get benefits!