# Volatility3 Exercise 1

### 1. Introduction

> When analyzing a memory image, it is nearly always important to understand what processes were running on the machine and what those processes were doing.
>
> This module introduces the basics of analyzing processes in the memory of Windows operating systems. The focus of this module is on using [Volatility 3](https://github.com/volatilityfoundation/volatility3) to list running processes and to examine the memory accessible by those processes.

### 2. About processes in Windows

The Windows operating system is written in C and therefore C structures are used internally in Windows to represent information.

The most important structure to be aware of regarding processes is the **EPROCESS** **structure** (**the E stands for executive**). This structure is defined in the Windows kernel and it is the base for all processes. It contains many attributes related to a given process and points to other structures that contain further information

Parsing the **EPROCESS structures** is one of the main ways that Volatility extracts information about processes from Windows memory images.

Here is a list of examples of what kind of information you can reach through the **EPROCESS structure**:

* When was the process started&#x20;
* When did the process exit (or if it is still running)&#x20;
* The ID of the process&#x20;
* The filename of the executable of the process&#x20;
* DLLs loaded by the process Working directory of the process&#x20;
* Command line arguments&#x20;
* Information about the memory allocated by a process

### 3. Volatility Pslist Plugin

The very first step in trying to understand the nature and activities of different processes in the machine is to obtain a list of processes present in the memory image. There are a couple of plugins in Volatility that help with this task. Open up a terminal window and prepare to explore these plugins in the following steps.

There is a Windows 10 memory image file named **win.raw** in the **/root/** directory and Volatility has been installed in the `/root/volatility3` directory. Try running the windows.pslist.PsList plugin with the win.raw image.

```
python3 volatility3/vol.py -f win.raw windows.pslist.PsList
```

<div align="left"><img src="https://3977837039-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfT0VPyK6X13Egd9pzy%2Fuploads%2FaABKkB7FGe7gBkeRmLCS%2Fpslist01.png?alt=media&#x26;token=3c6ca727-9029-419b-97cc-4422a19e86e9" alt=""></div>

At the bottom I can see a mimikatz process

<div align="left"><img src="https://3977837039-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfT0VPyK6X13Egd9pzy%2Fuploads%2FYXjSip8uQhHTIp2lhYOZ%2Fpslist02.png?alt=media&#x26;token=3a26a660-ec14-43c8-8572-1a82606f9a36" alt=""></div>

### 3.1 Extracting the executable

I use the folllowing command to extract the mimikatz process

```
python3 volatility3/vol.py -f win.raw windows.pslist.PsList --dump --pid 3604
```

<div align="left"><img src="https://3977837039-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfT0VPyK6X13Egd9pzy%2Fuploads%2F8DnGIPF7Y2rgcAooUS7W%2Fpslist03.png?alt=media&#x26;token=c580b9cd-3935-4b79-bc32-0610103a29b7" alt=""></div>

<div align="left"><img src="https://3977837039-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfT0VPyK6X13Egd9pzy%2Fuploads%2FnEcmQXBBnIJWQRoKyWjD%2Ffileinfo.png?alt=media&#x26;token=bf74922e-a0df-4d8a-b359-1b5493b938a9" alt=""></div>

### 3.2 Volatility Pstree plugin

The `windows.pstree.PsTree` plugin helps visualize child-parent relationships between processes. This is useful if you are trying to figure out how a certain process got created.

The output of this plugin contains the same information that is present in the output of the PsList plugin. In addition to that, the relationships between processes are visualized using `*` symbols

<div align="left"><img src="https://3977837039-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfT0VPyK6X13Egd9pzy%2Fuploads%2FSpCALfT3iTmcISWTWhzF%2Fpstree01.png?alt=media&#x26;token=baf3b9dc-43c7-4cf5-af88-16ba9871795b" alt=""></div>

Here we can see that **mimikatz.exe** is a child process of **powershell.exe**

### 3.3 Volatility PsScan plugin

The `windows.psscan.PsScan` plugin does not go through the linked list. Instead, it scans the memory image directly for EPROCESS structures. This approach will find any processes that have been unlinked from the list but still reside in memory.

Some malware might also attempt to unlink themselves from the list in order to try and hide their presence in the system. Searching for tricky malware is an entire topic on its own. However, just keep in mind that automatic tools can be misled and that they might also fail if the memory image is somehow corrupted or simply missing information. Things may not always work as expected and it is therefore important to have some understanding of what is happening under the hood to be better prepared to deal with any issues.

```
python3 volatility3/vol.py -f /root/prolaco.vmem windows.psscan.PsScan
```

![](https://3977837039-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfT0VPyK6X13Egd9pzy%2Fuploads%2FprGONftA5G9G6uG5EC3S%2Fpsscan01.png?alt=media\&token=caf64018-6c28-4995-9565-0e1d4a00f9c3)

Note some processes like `1_doc_RCData_61` are not listed wit the **pslist** command.

### 4. Virtual address descriptors

The **Virtual Address Descriptor (VAD)** is a data structure used in Windows. It describes memory ranges allocated by a process. The VAD stores information such as the range of the reserved addresses and protections applied for that range (e.g., if the memory range is read-only or read-write and so on).

The **VAD tree** of a process can be found by inspecting the **EPROCESS structure** mentioned earlier. Specifically, the EPROCESS structure contains a field named VadRoot that points to the root of the VAD tree.

Examining the VADs of a process is a convenient way to look at its memory. In the next steps you will experiment with the VadInfo and VadYaraScan plugins that parse the data in the VAD tree.

Let's check the VAD tree for mimikatz.exe

![](https://3977837039-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfT0VPyK6X13Egd9pzy%2Fuploads%2F6sTQ46BWiukFiac0wS6S%2Fvadinfo01.png?alt=media\&token=ff61840a-cd5d-4d13-9d3b-fbdbc64a9500)

### 4.1 Extract data with vadplugin

Similar to the PsList plugin, you can use the --dump flag to extract the contents of VAD regions with the VadInfo plugin. By also specifying an address with the --address option, you can dump the region described by a single VAD node.

```
python3 volatility3/vol.py -f win.raw windows.vadinfo.VadInfo --pid 3604 --dump --address 0x240000 
```

![](https://3977837039-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfT0VPyK6X13Egd9pzy%2Fuploads%2FwXkdP7rprHiunjyB9cXB%2Fvaddump01.png?alt=media\&token=c25117a5-4a55-4205-96ce-9e0f94a5e70c)

### 4.2 The VADYaraScan Plugin

The final plugin you are going to experiment with is the VadYaraScan plugin. This plugin allows you to directly scan VAD regions with YARA rules without having to first dump the memory.

You can specify a PID with the --pid flag if you would like to scan the memory of a specific process. The plugin accepts YARA rules in various formats.

Mimikatz yara rule:

```
rule mimikatz
{
        meta:
                description             = "mimikatz"
                author                  = "Benjamin DELPY (gentilkiwi)"
                tool_author             = "Benjamin DELPY (gentilkiwi)"

        strings:
                $exe_x86_1              = { 89 71 04 89 [0-3] 30 8d 04 bd }
                $exe_x86_2              = { 8b 4d e? 8b 45 f4 89 75 e? 89 01 85 ff 74 }

                $exe_x64_1              = { 33 ff 4? 89 37 4? 8b f3 45 85 c? 74}
                $exe_x64_2              = { 4c 8b df 49 [0-3] c1 e3 04 48 [0-3] 8b cb 4c 03 [0-3] d8 }

                $dll_1                  = { c7 0? 00 00 01 00 [4-14] c7 0? 01 00 00 00 }
                $dll_2                  = { c7 0? 10 02 00 00 ?? 89 4? }

                $sys_x86                = { a0 00 00 00 24 02 00 00 40 00 00 00 [0-4] b8 00 00 00 6c 02 00 00 40 00 00 00 }
                $sys_x64                = { 88 01 00 00 3c 04 00 00 40 00 00 00 [0-4] e8 02 00 00 f8 02 00 00 40 00 00 00 }

        condition:
                (all of ($exe_x86_*)) or (all of ($exe_x64_*)) or (all of ($dll_*)) or (any of ($sys_*))
}
```

Volatility command:

```
python3 volatility3/vol.py -f win.raw windows.vadyarascan.VadYaraScan --pid 3604 --yara-file mimikatz.yara
```

![](https://3977837039-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MfT0VPyK6X13Egd9pzy%2Fuploads%2FmmjLiEkk3VEX4TBcdi21%2Fvadyarascan01.png?alt=media\&token=2a369a48-74e6-4488-bb34-bb8001ba869d)

As you can see we've got three matches!
