> For the complete documentation index, see [llms.txt](https://docs.hex-rays.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.hex-rays.com/add-ons/malware/how-tos/triage-a-loader-with-a-sandbox-trace.md).

# Triage a Loader with a Sandbox Trace

This how-to shows how to overlay a sandbox trace on IDA's code views to triage a multi-stage loader. Consider the infection chain described by Google's Threat Intelligence Group in their post [“Mark Your Calendar: APT41 Innovative Tactics”](https://cloud.google.com/blog/topics/threat-intelligence/apt41-innovative-tactics): PLUSDROP is a DLL that decrypts and executes the next stage in memory. Then PLUSINJECT launches and performs process hollowing on a legitimate `svchost.exe` process, injecting the final payload. TOUGHPROGRESS executes actions on the compromised Windows host and uses Google Calendar for C2.

To follow along, you need two files from the chain. Both have a `.jpg` extension, but neither is an image:

| File    | Contents                 | SHA-256                                                            |
| ------- | ------------------------ | ------------------------------------------------------------------ |
| `7.jpg` | PLUSDROP, a 64-bit DLL   | `151257e9dfda476cdafd9983266ad3255104d72a66f9265caa8417a5fe1df5d7` |
| `6.jpg` | The encrypted next stage | `50124174a4ac0d65bf8b6fd66f538829d1589edc73aa7cf36502e57aa5513360` |

You can download them from MalwareBazaar ([PLUSDROP](https://bazaar.abuse.ch/sample/151257e9dfda476cdafd9983266ad3255104d72a66f9265caa8417a5fe1df5d7/), [encrypted stage](https://bazaar.abuse.ch/sample/50124174a4ac0d65bf8b6fd66f538829d1589edc73aa7cf36502e57aa5513360/)) or VirusTotal ([PLUSDROP](https://www.virustotal.com/gui/file/151257e9dfda476cdafd9983266ad3255104d72a66f9265caa8417a5fe1df5d7), [encrypted stage](https://www.virustotal.com/gui/file/50124174a4ac0d65bf8b6fd66f538829d1589edc73aa7cf36502e57aa5513360)).

{% hint style="warning" %}
The samples are live malware. Work on copies of the samples. Speakeasy runs the sample only inside the emulator, never on your system.
{% endhint %}

Save both files in the same directory, and name the encrypted stage `6.jpg`, because PLUSDROP looks for `6.jpg` next to itself. When you run the Speakeasy sandbox, the add-on copies the files next to the input file into the emulated `C:\Windows\system32` directory. The screenshots below use the SHA-256 hash as the name of the DLL.

## Why a sandbox report isn't enough

Reconstructing and understanding this chain is challenging: payloads are only uncovered at runtime, and a typical sandbox report is light on details. For example, consider how VMRay enumerates the host behavior:

![VMRay host behavior of PLUSDROP, with file operations on 6.jpg](https://492083732-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFP6ibt8r6WPBHTqekG9u%2Fuploads%2Fgit-blob-7e87ccdd9a001911fa085b84f99179688fa742c8%2Fsandbox-vmray-host-behavior.png?alt=media)

It records the file path `6.jpg`, which is good, a Host-Based Indicator of Compromise (HBI, IOC). But it doesn't give any insight into the purpose of the file: is it a marker of infection? Part of the decoy? An encrypted payload? Ultimately, can you confidently use it to flag a system for investigation? Not yet. Further malware analysis is needed.

## Run the sandbox

So let's overlay a sandbox trace on top of IDA's code views. If you have access to VMRay, the Malware Analysis Add-on can pull the analysis archive directly from VMRay's API and load it alongside the disassembly view in IDA (see [Sandbox Integration](https://docs.hex-rays.com/add-ons/malware/concepts/sandbox-integration.md#vmray)). Or, you can use Speakeasy, an open source Windows emulator written in Python, to analyze the program and capture code coverage and API call traces.

In this how-to, we use Speakeasy. Open your copy of `7.jpg` in IDA, wait for the auto-analysis to finish, and select **Extensions → Malware Analysis → Sandbox → Run Speakeasy sandbox**. Speakeasy runs `DllMain` and the exports of the DLL, including `plus`, the export that the infection chain calls. When the run is done, the Sandbox Trace Viewer opens next to the disassembly, and IDA highlights the instructions that executed.

## Find the relevant code

We can find the relevant code trivially: do a full-text search across the API trace to highlight the calls referencing the `6.jpg` file. Type `6.jpg` in the search box of the trace view. The table shows us a time ordered list of:

* rendered API calls, with parameters and return values, and
* their location within IDA, including addresses and symbol names.

![The trace view filtered on 6.jpg, next to the CreateFileW call in sub\_180001270](https://492083732-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFP6ibt8r6WPBHTqekG9u%2Fuploads%2Fgit-blob-8e4e7d8bd01d8e031fc65e63c997ac6b63d4ff90%2Fsandbox-trace-search.png?alt=media)

The `GetFileAttributesW` call on `..\image\6.jpg` fails, since PLUSDROP first looks in the `image` directory from the original ZIP archive. Then `CreateFileW` opens `6.jpg` next to the DLL.

If we double click a row, we jump directly to the event's address in the disassembly/pseudocode listing. So, we can quickly find the crucial logic within the loader, here `sub_180001270`.

Once we're at the call to `CreateFileW`, we can use the context menu action **Sandbox → Select events in this function** to find *all* the relevant rows from this interesting function:

![The Sandbox submenu in the disassembly view](https://492083732-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFP6ibt8r6WPBHTqekG9u%2Fuploads%2Fgit-blob-dccf5cf1b7862695703e3f7104da6a919e869d7f%2Fsandbox-context-menu.png?alt=media)

This gives us a view like:

![The trace view with the events of the function at 0x180001c9b](https://492083732-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFP6ibt8r6WPBHTqekG9u%2Fuploads%2Fgit-blob-f619750da176e44eefd097e37f36605cbfa32f81%2Fsandbox-events-in-function.png?alt=media)

Highlighted rows are events found at addresses *within* this function's bounds, while the muted lines are events from callees, such as when this function invoked subroutines, behavior happened, and control returned to our target function. This is a really powerful way to visualize the relationship between the linear disassembly and the call stack encountered at runtime.

## Resolve indirect calls

Unfortunately when we look closely at the call instructions, they're indirect via local variables, so their target is difficult to interpret. Usually we'd have to resolve the function pointers just like the loader does: by brute forcing hardcoded hash values to API names, or using a debugger to recover the values from runtime. But since we have the sandbox trace, we can resolve indirect calls with the context menu action **Sandbox → Apply all API names/types in function**.

![The disassembly with API names, parameter names, and types from the trace](https://492083732-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFP6ibt8r6WPBHTqekG9u%2Fuploads%2Fgit-blob-cf15feeca3193d766fbebb99cff12359c7b7ca13%2Fsandbox-apply-api-names.png?alt=media)

The add-on applies names, parameters, and types to the disassembly view, as well as the pseudocode view. Before:

![The pseudocode before the add-on applies the API names](https://492083732-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFP6ibt8r6WPBHTqekG9u%2Fuploads%2Fgit-blob-ef7ae260f653e71d689509d9e165684084265786%2Fsandbox-pseudocode-before.png?alt=media)

After:

![The pseudocode after the add-on applies the API names](https://492083732-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFP6ibt8r6WPBHTqekG9u%2Fuploads%2Fgit-blob-d2cf9f06a173a62b3590119370f5a43f7f634945%2Fsandbox-pseudocode-after.png?alt=media)

Reading closely, it's clear that `6.jpg` contains encrypted shellcode that gets decoded and executed via a chain of calls: `CreateFileW` → `GetFileSize` → `VirtualAlloc(RWX)` → `ReadFile` → `CloseHandle`. The loop after the calls decodes the end of the buffer with XOR and a 16-byte key that sits just before the encoded data.

## Import the shellcode

In the sandbox trace, the subsequent events no longer translate to the IDB, because their code doesn't come from the mapped image: the **Function** column is empty for events at `0x50254` and later. With the Malware Analysis Add-on, we can import the shellcode directly in the IDB and continue analysis. Double click on a row at an unmapped address and you'll see the dialog:

![The Import Memory Regions dialog with the RWX region at 0x50000](https://492083732-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFP6ibt8r6WPBHTqekG9u%2Fuploads%2Fgit-blob-0ba4dd3735d8065864d0a06fcc25a665efa60206%2Fsandbox-import-memory.png?alt=media)

Click **Import** on the `api.VirtualAlloc.0x50000` row. The add-on adds the 976 KB RWX region to the IDB and jumps to the address.

## Follow the next layers

We can continue to use the sandbox and disassembly views to find relevant code. Ultimately, it's quick to resolve additional layers of loaders, including LZNT1 decompression and process replacement, to recover the inner payload.

![The trace view after the import, with events in the shellcode functions](https://492083732-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFP6ibt8r6WPBHTqekG9u%2Fuploads%2Fgit-blob-eee6f88d072c85c82c307510239548f497f6c272%2Fsandbox-shellcode-trace.png?alt=media)

After the import, events from the shellcode show their functions, such as `sub_50184`. The shellcode resolves `LoadLibraryA`, `VirtualAlloc`, and `VirtualFree`, allocates a buffer at `0x14C000`, decompresses the next layer into it with `RtlDecompressBuffer`, and then resolves `CreateProcessA` to start the process replacement.

To study the process that receives the final payload, use the **Remote Process IDBs** group of the **Import Memory Regions** dialog. Click **Generate** to build an IDB for that process. See [Rebuilding IDBs from child processes](https://docs.hex-rays.com/add-ons/malware/concepts/sandbox-integration.md#rebuilding-idbs-from-child-processes).

If you have a question, an idea, or a problem, email <support@hex-rays.com>. The Malware Analysis team reads every message and replies quickly.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.hex-rays.com/add-ons/malware/how-tos/triage-a-loader-with-a-sandbox-trace.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
