# Analysis

# Oletools

# 🕵️‍♂️ Guide: Analyzing `.docx` and `.xlsm` Files with `oletools`

## 🔧 0. Install `oletools`

```bash
pip install oletools

```

---

## 📄 Analyzing `.docx` Files (OpenXML Word Documents)

### 1. Run `olevba` on the `.docx` file

```bash
olevba file.docx

```

> ⚠️ `.docx` files usually do **not** contain VBA macros. But it's always good to check.

---

### 2. Unzip the `.docx` to check for embedded objects

```bash
unzip file.docx -d extracted/

```

---

### 3. Look for embedded OLE objects

Check this directory:

```
extracted/word/embeddings/

```

You may find:

```
oleObject1.bin
oleObject2.bin

```

---

### 4. Analyze embedded OLE objects

```bash
olevba extracted/word/embeddings/oleObject1.bin

```

Repeat for any other `.bin` files.

---

### 5. Use `oleid` for file metadata overview

```bash
oleid file.docx

```

This gives a quick summary of:

- Macros present
- External relationships
- Encryption
- Suspicious flags

---

## 📊 Analyzing `.xlsm` Files (Macro-Enabled Excel)

### 1. Run `olevba` on the file

```bash
olevba file.xlsm

```

This will:

- Extract all VBA macros
- Show suspicious keywords
- Show auto-executing macros
- Print the actual macro code

---

### 2. Look for these red flags

<table id="bkmrk-type-keyword-why-it-"><thead><tr><th>Type</th><th>Keyword</th><th>Why it matters</th></tr></thead><tbody><tr><td>`AutoExec`</td><td>`Workbook_Open`, `Auto_Open`</td><td>Executes macro automatically on open</td></tr><tr><td>`Suspicious`</td><td>`Shell`, `CreateObject`, `WScript.Shell`</td><td>Can run system commands</td></tr><tr><td>`IOC`</td><td>`http`, `.exe`, `powershell`, registry edits</td><td>Potential malware payloads</td></tr><tr><td>`Obfuscation`</td><td>`Chr`, `Base64`, `StrReverse`, `Split`</td><td>Used to hide real behavior</td></tr></tbody></table>

---

### 3. Extract VBA code to a file (optional)

```bash
olevba file.xlsm > macro_output.txt

```

---

### 4. Use `oleid` for metadata

```bash
oleid file.xlsm

```

---

## ✅ Key Indicators to Watch

<table id="bkmrk-category-example-why"><thead><tr><th>Category</th><th>Example</th><th>Why It’s Suspicious</th></tr></thead><tbody><tr><td>**AutoExec**</td><td>`Auto_Open`, `Workbook_Open`</td><td>Runs automatically</td></tr><tr><td>**Command Exec**</td><td>`Shell`, `powershell`, `cmd`</td><td>System command execution</td></tr><tr><td>**Obfuscation**</td><td>`Chr(72) & Chr(84)`, `Base64`</td><td>Payload hiding</td></tr><tr><td>**Downloader**</td><td>`URLDownloadToFile`, `XMLHTTP`</td><td>Drops additional malware</td></tr><tr><td>**Persistence**</td><td>Registry writes, `Startup`</td><td>Foothold creation</td></tr><tr><td>**Encoding**</td><td>Long strings, encoded blobs</td><td>Shellcode or encoded scripts</td></tr></tbody></table>

---

## 🧾 Quick Command List (Cheat Sheet)

```bash
# General analysis
olevba file.xlsm
olevba file.docx

# Extract and analyze embedded objects
unzip file.docx -d extracted/
olevba extracted/word/embeddings/oleObject1.bin

# Inspect file metadata
oleid file.xlsm
oleid file.docx

# Save macro code to a text file
olevba file.xlsm > macros.txt

# Identify embedded objects
ls extracted/word/embeddings/
file extracted/word/embeddings/oleObject1.bin

```

---

## 🧠 Pro Tips

- Use `olevba` with caution on unknown files — always analyze in a **VM/sandbox**.
- Combine `olevba` with `strings`, `file`, or `hexdump` for deeper inspection.
- Copy suspicious VBA code for manual review or deobfuscation if needed.
- Use `oleid` first for a fast overview before diving into macro code.