hacktricks/forensics/volatility-examples.md

566 lines
20 KiB
Markdown
Raw Normal View History

# Volatility - Examples
If you want something as **fast** as possible: [https://github.com/carlospolop/autoVolatility](https://github.com/carlospolop/autoVolatility)
```text
python autoVolatility.py -f MEMFILE -d OUT_DIRECTORY -e /home/user/tools/volatility/vol.py # Will use most important plugins (could use a lot of space depending on the size of the memory)
```
[Volatility command reference](https://github.com/volatilityfoundation/volatility/wiki/Command-Reference#kdbgscan)
2020-12-19 00:07:03 +00:00
## Installation
### volatility3
2020-12-19 15:05:05 +00:00
```bash
2020-12-19 00:07:03 +00:00
git clone https://github.com/volatilityfoundation/volatility3.git
cd volatility3
python3 setup.py install
python3 vol.py —h
```
### volatility2
{% tabs %}
{% tab title="Method1" %}
```text
Download the executable from https://www.volatilityfoundation.org/26
```
{% endtab %}
{% tab title="Method 2" %}
2020-12-19 15:05:05 +00:00
```bash
2020-12-19 00:07:03 +00:00
git clone https://github.com/volatilityfoundation/volatility.git
cd volatility
python setup.py install
```
{% endtab %}
{% endtabs %}
## A note on “list” vs. “scan” plugins
Volatility has two main approaches to plugins, which are sometimes reflected in their names. “list” plugins will try to navigate through Windows Kernel structures to retrieve information like processes \(locate and walk the linked list of `_EPROCESS` structures in memory\), OS handles \(locating and listing the handle table, dereferencing any pointers found, etc\). They more or less behave like the Windows API would if requested to, for example, list processes.
That makes “list” plugins pretty fast, but just as vulnerable as the Windows API to manipulation by malware. For instance, if malware uses DKOM to unlink a process from the `_EPROCESS` linked list, it wont show up in the Task Manager and neither will it in the pslist.
“scan” plugins, on the other hand, will take an approach similar to carving the memory for things that might make sense when dereferenced as specific structures. `psscan` for instance will read the memory and try to make out `_EPROCESS` objects out of it \(it uses pool-tag scanning, which is basically searching for 4-byte strings that indicate the presence of a structure of interest\). The advantage is that it can dig up processes that have exited, and even if malware tampers with the `_EPROCESS` linked list, the plugin will still find the structure lying around in memory \(since it still needs to exist for the process to run\). The downfall is that “scan” plugins are a bit slower than “list” plugins, and can sometimes yield false-positives \(a process that exited too long ago and had parts of its structure overwritten by other operations\).
From: [http://tomchop.me/2016/11/21/tutorial-volatility-plugins-malware-analysis/](http://tomchop.me/2016/11/21/tutorial-volatility-plugins-malware-analysis/)
2020-12-19 00:07:03 +00:00
## OS Profiles
### Volatility3
As explained inside the readme you need to put the **symbol table of the OS** you want to support inside _volatility3/volatility/symbols_.
Symbol table packs for the various operating systems are available for **download** at:
* [https://downloads.volatilityfoundation.org/volatility3/symbols/windows.zip](https://downloads.volatilityfoundation.org/volatility3/symbols/windows.zip)
* [https://downloads.volatilityfoundation.org/volatility3/symbols/mac.zip](https://downloads.volatilityfoundation.org/volatility3/symbols/mac.zip)
* [https://downloads.volatilityfoundation.org/volatility3/symbols/linux.zip](https://downloads.volatilityfoundation.org/volatility3/symbols/linux.zip)
### Volatility2
#### External Profile
You can get the list of supported profiles doing:
```bash
./volatility_2.6_lin64_standalone --info | grep "Profile"
```
If you want to use a **new profile you have downloaded** \(for example a linux one\) you need to create somewhere the following folder structure: _plugins/overlays/linux_ and put inside this folder the zip file containing the profile. Then, get the number of the profiles using:
```text
./vol --plugins=/home/kali/Desktop/ctfs/final/plugins --info
Volatility Foundation Volatility Framework 2.6
Profiles
--------
LinuxCentOS7_3_10_0-123_el7_x86_64_profilex64 - A Profile for Linux CentOS7_3.10.0-123.el7.x86_64_profile x64
VistaSP0x64 - A Profile for Windows Vista SP0 x64
VistaSP0x86 - A Profile for Windows Vista SP0 x86
```
In the previous chunk you can see that the profile is called `LinuxCentOS7_3_10_0-123_el7_x86_64_profilex64` , and you can use it executing something like:
```text
./vol -f image.vmss --plugins=. --profile=LinuxCentOS7_3_10_0-123_el7_x86_64_profilex64 linux_netscan
```
#### Discover Profile
```text
volatility imageinfo -f file.dmp
volatility kdbgscan -f file.dmp
```
2020-12-19 00:07:03 +00:00
#### **Differences between imageinfo and kdbgscan**
As opposed to imageinfo which simply provides profile suggestions, **kdbgscan** is designed to positively identify the correct profile and the correct KDBG address \(if there happen to be multiple\). This plugin scans for the KDBGHeader signatures linked to Volatility profiles and applies sanity checks to reduce false positives. The verbosity of the output and number of sanity checks that can be performed depends on whether Volatility can find a DTB, so if you already know the correct profile \(or if you have a profile suggestion from imageinfo\), then make sure you use it \(from [here](https://www.andreafortuna.org/2017/06/25/volatility-my-own-cheatsheet-part-1-image-identification/)\).
Always take a look in the **number of procceses that kdbgscan has found**. Sometimes imageinfo and kdbgscan can find **more than one** suitable **profile** but only the **valid one will have some process related** \(This is because in order to extract processes the correct KDBG address is needed\)
```text
# GOOD
PsActiveProcessHead : 0xfffff800011977f0 (37 processes)
PsLoadedModuleList : 0xfffff8000119aae0 (116 modules)
```
```text
# BAD
PsActiveProcessHead : 0xfffff800011947f0 (0 processes)
PsLoadedModuleList : 0xfffff80001197ac0 (0 modules)
```
2020-12-19 00:07:03 +00:00
#### KDBG
The **kernel debugger block** \(named KdDebuggerDataBlock of the type \_KDDEBUGGER\_DATA64, or **KDBG** by volatility\) is important for many things that Volatility and debuggers do. For example, it has a reference to the PsActiveProcessHead which is the list head of all processes required for process listing.
## Hashes/Passwords
2020-12-19 15:05:05 +00:00
Extract SAM hashes, [domain cached credentials](../windows/stealing-credentials/credentials-protections.md#cached-credentials) and [lsa secrets](../windows/authentication-credentials-uac-and-efs.md#lsa-secrets).
2020-12-19 15:05:05 +00:00
{% tabs %}
{% tab title="vol3" %}
2020-12-19 00:21:32 +00:00
```bash
2020-12-19 15:05:05 +00:00
./vol.py -f ch2.dmp windows.hashdump.Hashdump #Grab common windows hashes (SAM+SYSTEM)
./vol.py -f ch2.dmp windows.cachedump.Cachedump #Grab domain cache hashes inside the registry
./vol.py -f ch2.dmp windows.lsadump.Lsadump #Grab lsa secrets
```
2020-12-19 15:05:05 +00:00
{% endtab %}
{% tab title="vol2" %}
```bash
volatility --profile=Win7SP1x86_23418 hashdump -f ch2.dmp #Grab common windows hashes (SAM+SYSTEM)
volatility --profile=Win7SP1x86_23418 cachedump -f ch2.dmp #Grab domain cache hashes inside the registry
volatility --profile=Win7SP1x86_23418 lsadump -f ch2.dmp #Grab lsa secrets
```
{% endtab %}
{% endtabs %}
## Memory Dump
The memory dump of a process will **extract everything** of the current status of the process. The **procdump** module will only **extract** the **code**.
```text
volatility -f ch2.dmp --profile=Win7SP1x86 memdump -p 2168 -D conhost/
```
## Processes
### List processes
2020-12-19 15:05:05 +00:00
Try to find **suspicious** processes \(by name\) or **unexpected** child **processes** \(for example a cmd.exe as a child of iexplorer.exe\).
It could be interesting to **compare** the result of pslist with the one of psscan to identify hidden processes.
2020-12-19 15:05:05 +00:00
{% tabs %}
{% tab title="vol3" %}
2020-12-19 00:21:32 +00:00
```bash
2020-12-19 15:05:05 +00:00
python3 vol.py -f file.dmp windows.pstree.PsTree # Get processes tree (not hidden)
python3 vol.py -f file.dmp windows.pslist.PsList # Get process list (EPROCESS)
python3 vol.py -f file.dmp windows.psscan.PsScan # Get hidden process list(malware)
```
2020-12-19 15:05:05 +00:00
{% endtab %}
{% tab title="vol2" %}
```bash
volatility --profile=PROFILE pstree -f file.dmp # Get process tree (not hidden)
volatility --profile=PROFILE pslist -f file.dmp # Get process list (EPROCESS)
volatility --profile=PROFILE psscan -f file.dmp # Get hidden process list(malware)
volatility --profile=PROFILE psxview -f file.dmp # Get hidden process list
```
{% endtab %}
{% endtabs %}
### Dump proc
2020-12-19 15:05:05 +00:00
{% tabs %}
{% tab title="vol3" %}
```bash
./vol.py -f file.dmp windows.dumpfiles.DumpFiles --pid <pid> #Dump the .exe and dlls of the process in the current directory
```
{% endtab %}
{% tab title="vol2" %}
```bash
volatility --profile=Win7SP1x86_23418 procdump --pid=3152 -n --dump-dir=. -f ch2.dmp
```
2020-12-19 15:05:05 +00:00
{% endtab %}
{% endtabs %}
### Command line
2020-12-19 16:43:21 +00:00
Anything suspicious was executed?
2020-12-19 15:05:05 +00:00
{% tabs %}
{% tab title="vol3" %}
```bash
python3 vol.py -f file.dmp windows.cmdline.CmdLine #Display process command-line arguments
```
{% endtab %}
{% tab title="vol2" %}
2020-12-17 15:52:08 +00:00
```bash
volatility --profile=PROFILE cmdline -f DUMP #Display process command-line arguments
volatility --profile=PROFILE consoles -f DUMP #command history by scanning for _CONSOLE_INFORMATION
```
2020-12-19 15:05:05 +00:00
{% endtab %}
{% endtabs %}
2020-12-19 15:05:05 +00:00
Commands entered into cmd.exe are processed by **conhost.exe** \(csrss.exe prior to Windows 7\). So even if an attacker managed to **kill the cmd.exe** **prior** to us obtaining a memory **dump**, there is still a good chance of **recovering history** of the command line session from **conhost.exes memory**. If you find **something weird** \(using the consoles modules\), try to **dump** the **memory** of the **conhost.exe associated** process and **search** for **strings** inside it to extract the command lines.
### Environment
2020-12-19 15:05:05 +00:00
Get the env variables of each running process. There could be some interesting values.
{% tabs %}
{% tab title="vol3" %}
```bash
python3 vol.py -f file.dmp windows.envars.Envars [--pid <pid>] #Display process environment variables
```
2020-12-19 15:05:05 +00:00
{% endtab %}
{% tab title="vol2" %}
```bash
volatility --profile=PROFILE envars -f file.dmp [--pid <pid>] #Display process environment variables
```
{% endtab %}
{% endtabs %}
### Token privileges
2020-12-19 15:05:05 +00:00
Check for privileges tokens in unexpected services.
It could be interesting to list the processes using some privileged token.
2020-12-19 15:05:05 +00:00
{% tabs %}
{% tab title="vol3" %}
```bash
#Get enabled privileges of some processes
python3 vol.py -f file.dmp windows.privileges.Privs [--pid <pid>]
#Get all processes with interesting privileges
python3 vol.py -f file.dmp windows.privileges.Privs | grep "SeImpersonatePrivilege\|SeAssignPrimaryPrivilege\|SeTcbPrivilege\|SeBackupPrivilege\|SeRestorePrivilege\|SeCreateTokenPrivilege\|SeLoadDriverPrivilege\|SeTakeOwnershipPrivilege\|SeDebugPrivilege"
```
{% endtab %}
2020-12-19 15:05:05 +00:00
{% tab title="vol2" %}
2020-12-17 15:52:08 +00:00
```bash
#Get enabled privileges of some processes
volatility --profile=Win7SP1x86_23418 privs --pid=3152 -f file.dmp | grep Enabled
#Get all processes with interesting privileges
2020-12-19 15:05:05 +00:00
volatility --profile=Win7SP1x86_23418 privs -f file.dmp | grep "SeImpersonatePrivilege\|SeAssignPrimaryPrivilege\|SeTcbPrivilege\|SeBackupPrivilege\|SeRestorePrivilege\|SeCreateTokenPrivilege\|SeLoadDriverPrivilege\|SeTakeOwnershipPrivilege\|SeDebugPrivilege"
```
2020-12-19 15:05:05 +00:00
{% endtab %}
{% endtabs %}
### SIDs
2020-12-19 15:05:05 +00:00
Check each SSID owned by a process.
It could be interesting to list the processes using a privileges SID \(and the processes using some service SID\).
2020-12-19 15:05:05 +00:00
{% tabs %}
{% tab title="vol3" %}
2020-12-17 15:52:08 +00:00
```bash
2020-12-19 15:05:05 +00:00
python3 vol.py -f file.dmp windows.getsids.GetSIDs [--pid <pid>] #Get SIDs of processes
python3 vol.py -f file.dmp windows.getservicesids.GetServiceSIDs #Get the SID of services
```
2020-12-19 15:05:05 +00:00
{% endtab %}
{% tab title="vol2" %}
```bash
volatility --profile=Win7SP1x86_23418 getsids -f file.dmp #Get the SID owned by each process
volatility --profile=Win7SP1x86_23418 getservicesids -f file.dmp #Get the SID of each service
```
{% endtab %}
{% endtabs %}
### Handles
Useful to know to which other files, keys, threads, processes... a **process has a handle** for \(has opened\)
2020-12-19 15:05:05 +00:00
{% tabs %}
{% tab title="Plain Text" %}
```bash
vol.py -f file.dmp windows.handles.Handles [--pid <pid>]
```
2020-12-19 15:05:05 +00:00
{% endtab %}
{% tab title="vol2" %}
```bash
volatility --profile=Win7SP1x86_23418 -f file.dmp handles [--pid=<pid>]
```
{% endtab %}
{% endtabs %}
### DLLs
2020-12-19 15:05:05 +00:00
{% tabs %}
{% tab title="vol3" %}
```bash
./vol.py -f file.dmp windows.dlllist.DllList [--pid <pid>] #List dlls used by each
./vol.py -f file.dmp windows.dumpfiles.DumpFiles --pid <pid> #Dump the .exe and dlls of the process in the current directory process
```
{% endtab %}
{% tab title="vol2" %}
```bash
volatility --profile=Win7SP1x86_23418 dlllist --pid=3152 -f file.dmp #Get dlls of a proc
volatility --profile=Win7SP1x86_23418 dlldump --pid=3152 --dump-dir=. -f file.dmp #Dump dlls of a proc
```
{% endtab %}
{% endtabs %}
### Strings per processes
Volatility allows to check to which process does a string belongs to.
{% tabs %}
{% tab title="vol3" %}
```bash
strings -n6 file.dmp > /tmp/strings.txt
./vol.py -f /tmp/file.dmp windows.strings.Strings --strings-file /tmp/strings.txt
```
{% endtab %}
{% tab title="vol2" %}
2020-12-17 15:52:08 +00:00
```bash
2020-12-19 15:05:05 +00:00
strings -n6 file.dmp > /tmp/strings.txt
volatility -f /tmp/file.dmp windows.strings.Strings --strings-file /tmp/strings.txt
```
2020-12-19 15:05:05 +00:00
{% endtab %}
{% endtabs %}
2020-12-19 16:43:21 +00:00
It also allows to search for strings inside a process using the yarascan module:
{% tabs %}
{% tab title="vol3" %}
```bash
./vol.py -f /tmp/file.dmp windows.vadyarascan.VadYaraScan --yara-rules "https://" --pid 3692 3840 3976 3312 3084 2784
./vol.py -f /tmp/file.dmp yarascan.YaraScan --yara-rules "https://"
```
{% endtab %}
{% tab title="vol2" %}
```bash
volatility --profile=Win7SP1x86_23418 yarascan -Y "https://" -p 3692,3840,3976,3312,3084,2784
```
{% endtab %}
{% endtabs %}
## Services
2020-12-17 15:52:08 +00:00
```bash
#Get services and binary path
volatility --profile=Win7SP1x86_23418 svcscan-f ch2.dmp
#Get name of the services and SID (slow)
volatility --profile=Win7SP1x86_23418 getservicesids -f ch2.dmp
```
## Network
2020-12-19 15:05:05 +00:00
{% tabs %}
{% tab title="vol3" %}
```bash
./vol.py -f /tmp/file.dmp windows.netscan.NetScan
```
{% endtab %}
{% tab title="vol2" %}
2020-12-17 15:52:08 +00:00
```bash
volatility --profile=Win7SP1x86_23418 netscan -f ch2.dmp
volatility --profile=Win7SP1x86_23418 connections -f ch2.dmp #XP and 2003 only
volatility --profile=Win7SP1x86_23418 connscan -f ch2.dmp #TCP connections
volatility --profile=Win7SP1x86_23418 sockscan -f ch2.dmp #Open sockets
volatility --profile=Win7SP1x86_23418 sockets -f ch2.dmp #Scanner for tcp socket objects
```
2020-12-19 15:05:05 +00:00
{% endtab %}
{% endtabs %}
2020-12-19 15:05:05 +00:00
## Registry hive
### Print available hives
2020-12-19 15:05:05 +00:00
{% tabs %}
{% tab title="vol3" %}
```bash
./vol.py -f file.dmp windows.registry.hivelist.HiveList #List roots
./vol.py -f file.dmp windows.registry.printkey.PrintKey #List roots and get initial subkeys
```
2020-12-19 15:05:05 +00:00
{% endtab %}
{% tab title="vol2" %}
```bash
volatility --profile=Win7SP1x86_23418 -f file.dmp hivelist #List roots
volatility --profile=Win7SP1x86_23418 -f file.dmp printkey #List roots and get initial subkeys
```
{% endtab %}
{% endtabs %}
### Get a value
2020-12-19 15:05:05 +00:00
{% tabs %}
{% tab title="vol3" %}
```bash
./vol.py -f file.dmp windows.registry.printkey.PrintKey --key "Software\Microsoft\Windows NT\CurrentVersion"
```
{% endtab %}
{% tab title="vol2" %}
2020-12-17 15:52:08 +00:00
```bash
volatility --profile=Win7SP1x86_23418 printkey -K "Software\Microsoft\Windows NT\CurrentVersion" -f ch2.dmp
# Get Run binaries registry value
volatility -f ch2.dmp --profile=Win7SP1x86 printkey -o 0x9670e9d0 -K 'Software\Microsoft\Windows\CurrentVersion\Run'
```
2020-12-19 15:05:05 +00:00
{% endtab %}
{% endtabs %}
### Dump
2020-12-17 15:52:08 +00:00
```bash
#Dump a hive
volatility --profile=Win7SP1x86_23418 hivedump -o 0x9aad6148 -f ch2.dmp #Offset extracted by hivelist
#Dump all hives
volatility --profile=Win7SP1x86_23418 hivedump -f ch2.dmp
```
## Files
### Scan/dump
2020-12-19 16:43:21 +00:00
{% tabs %}
{% tab title="vol3" %}
```bash
./vol.py -f file.dmp windows.filescan.FileScan #Scan for files inside the dump
python3 vol.py -f /home/kali/Desktop/ctfs/atenea/analisis\ de\ memoria/dump/dump.raw windows.dumpfiles.DumpFiles --physaddr <0xAAAAA> #Offset from previous command
```
{% endtab %}
{% tab title="vol2" %}
2020-12-17 15:52:08 +00:00
```bash
volatility --profile=Win7SP1x86_23418 filescan -f ch2.dmp #Scan for files inside the dump
2020-12-19 16:43:21 +00:00
volatility --profile=Win7SP1x86_23418 dumpfiles -n --dump-dir=/tmp -f ch2.dmp #Dump all files
volatility --profile=Win7SP1x86_23418 dumpfiles -n --dump-dir=/tmp -Q 0x000000007dcaa620
```
2020-12-19 16:43:21 +00:00
{% endtab %}
{% endtabs %}
### Master File Table
{% tabs %}
{% tab title="vol3" %}
```bash
# I couldn't find any plugin to extractthis information in volatility3
```
{% endtab %}
{% tab title="vol2" %}
```bash
volatility --profile=Win7SP1x86_23418 mftparser -f file.dmp
```
{% endtab %}
{% endtabs %}
The NTFS file system contains a file called the _master file table_, or MFT. There is at least one entry in the MFT for every file on an NTFS file system volume, including the MFT itself. **All information about a file, including its size, time and date stamps, permissions, and data content**, is stored either in MFT entries, or in space outside the MFT that is described by MFT entries. From [here](https://docs.microsoft.com/en-us/windows/win32/fileio/master-file-table).
### SSL Keys/Certs
Interesting options for this modules are: _--pid, --name, --ssl_
```text
volatility --profile=Win7SP1x86_23418 dumpcerts --dump-dir=. -f ch2.dmp
```
## Malware
```text
volatility --profile=Win7SP1x86_23418 malfind -f ch2.dmp
volatility --profile=Win7SP1x86_23418 apihooks -f ch2.dmp
volatility --profile=Win7SP1x86_23418 driverirp -f ch2.dmp
```
### Scanning with yara
Use this script to download and merge all the yara malware rules from github: [https://gist.github.com/andreafortuna/29c6ea48adf3d45a979a78763cdc7ce9](https://gist.github.com/andreafortuna/29c6ea48adf3d45a979a78763cdc7ce9)
Create the _**rules**_ directory and execute it. This will create a file called _**malware\_rules.yar**_ which contains all the yara rules for malware.
```text
wget https://gist.githubusercontent.com/andreafortuna/29c6ea48adf3d45a979a78763cdc7ce9/raw/4ec711d37f1b428b63bed1f786b26a0654aa2f31/malware_yara_rules.py
mkdir rules
python malware_yara_rules.py
volatility --profile=Win7SP1x86_23418 yarascan -y malware_rules.yar -f ch2.dmp | grep "Rule:" | grep -v "Str_Win32" | sort | uniq
```
## External Plugins
When you use an external plugin **the first parameter** that you have to set is `--plugins`
### Autoruns
Download it from [https://github.com/tomchop/volatility-autoruns](https://github.com/tomchop/volatility-autoruns)
```text
volatility --plugins=volatility-autoruns/ --profile=WinXPSP2x86 -f dump.img autoruns
```
## MISC
2020-12-19 16:43:21 +00:00
### External plugins
If you want to use an external plugins make sure that the plugins related folder is the first parameter used.
{% tabs %}
{% tab title="vol3" %}
```bash
./vol.py --plugin-dirs "/tmp/plugins/" [...]
```
{% endtab %}
{% tab title="vol2" %}
```bash
volatilitye --plugins="/tmp/plugins/" [...]
```
{% endtab %}
{% endtabs %}
### Get clipboard
```text
volatility --profile=Win7SP1x86_23418 clipboard -f ch2.dmp
```
### Get IE history
```text
volatility --profile=Win7SP1x86_23418 iehistory -f ch2.dmp
```
### Get notepad text
```text
volatility --profile=Win7SP1x86_23418 notepad -f ch2.dmp
```
### Screenshot
```text
volatility --profile=Win7SP1x86_23418 screenshot -f ch2.dmp
```
### Mutantscan
```text
volatility --profile=Win7SP1x86_23418 mutantscan -f ch2.dmp
```
### Master Boot Record \(MBR\)
```text
volatility --profile=Win7SP1x86_23418 mbrparser -f ch2.dmp
```
The MBR holds the information on how the logical partitions, containing [file systems](https://en.wikipedia.org/wiki/File_system), are organized on that medium. The MBR also contains executable code to function as a loader for the installed operating system—usually by passing control over to the loader's [second stage](https://en.wikipedia.org/wiki/Second-stage_boot_loader), or in conjunction with each partition's [volume boot record](https://en.wikipedia.org/wiki/Volume_boot_record) \(VBR\). This MBR code is usually referred to as a [boot loader](https://en.wikipedia.org/wiki/Boot_loader). From [here](https://en.wikipedia.org/wiki/Master_boot_record).