Below is a proof‑of‑concept Python wrapper which shows two ways you can automate Volatility 3 to
- dump your process tree
- list loaded DLLs
- enumerate registry hives + dump a key
- dump the network state
- hunt for in‑memory malware artifacts (malfind)
- (bonus) drive Volshell under the hood
Feel free to adapt it to your environment, add error‑checking, logging, etc.
1. Pre‑reqs
- Python 3.7+
- volatility3 installed (
pip install volatility3)
- A Windows memory image file, e.g.
win10x64.raw
2. Approach A – direct Volatility API calls
Volatility 3 is fully scriptable. You can import your plugins and invoke their run() methods directly. Below is a skeleton:
#!/usr/bin/env python3
import os
from volatility3.framework import contexts, interfaces
from volatility3.framework.configuration import requirements, ConfigurationManager
from volatility3.framework.automagic import stackers
from volatility3.framework.layers import managers as layer_managers
from volatility3.cli import text_renderer
# import the windows plugins we need
from volatility3.plugins.windows.pslist import PsList
from volatility3.plugins.windows.dlllist import DllList
from volatility3.plugins.windows.registry.hivelist import HiveList
from volatility3.plugins.windows.registry.printkey import PrintKey
from volatility3.plugins.windows.netstat import Netstat
from volatility3.plugins.windows.malfind import Malfind
def setup_context(memory_image_path, symbol_path=None):
"""Create a Volatility context, configure layers, symbol tables, etc."""
ctx = contexts.Context()
config = ctx.config
# 1) register your image file as the primary layer
config['automagic.LayerStacker.single_location'] = memory_image_path
# 2) let Volatility pick up the correct kernel symbols
if symbol_path:
config['automagic.StackerSymbolTable'] = symbol_path
# 3) run the automagic to build the layer‐stack & tables
stackers = [
requirements.automagic(sequence=requirements.automagic[0]),
requirements.automagic(sequence=requirements.automagic[1])
]
for auto in requirements.automagic:
auto().run(ctx, config)
return ctx, config
def run_plugin(ctx, config, plugin_cls, plugin_args=None, output_name=None):
"""Generic helper to invoke a plugin and print/save its TreeGrid."""
plugin_args = plugin_args or {}
plugin_name = plugin_cls.__name__
print(f"\n=== RUNNING {plugin_name} ===\n")
# instantiate the plugin
plugin = plugin_cls(ctx, config, **plugin_args)
# run and render
text_out = text_renderer.TextRenderer()
for result in plugin.run():
for formatted in text_out.render(result):
print(formatted) # you could redirect to a file here
if __name__ == "__main__":
MEMORY_IMAGE = "/path/to/win10x64.raw"
SYMBOL_PATH = None # or "/path/to/Microsoft-Symbol-Server"
ctx, config = setup_context(MEMORY_IMAGE, SYMBOL_PATH)
# 1) Process tree
run_plugin(ctx, config, PsList, plugin_args={'tree': True})
# 2) Loaded DLLs
run_plugin(ctx, config, DllList)
# 3) Hive list + dump a specific key (e.g. SOFTWARE)
run_plugin(ctx, config, HiveList)
run_plugin(ctx, config, PrintKey, plugin_args={'key': r"\\SOFTWARE"})
# 4) Network connections
run_plugin(ctx, config, Netstat)
# 5) Malfind (in‑memory IOC hunting)
run_plugin(ctx, config, Malfind)
Notes
- We use the built‑in
TextRenderer to emit human‑readable output on stdout.
- You can swap in the JSON or CSV renderers if you want machine‑parseable output.
3. Approach B – driving Volshell via pexpect
If you prefer to reuse the Volshell plugin (e.g. for ad‑hoc exploration or complex chained commands), you can spawn Volshell as a subprocess and feed it commands:
#!/usr/bin/env python3
import pexpect
import sys
VOL_PATH = "vol.py" # or full path to your `vol.py` script
IMAGE = "/path/to/win10x64.raw"
PROFILE = "windows.10.x64_18362" # adjust if needed
commands = [
"pslist", # processes
"dlllist", # DLLs
"hivelist", # registry hives
"printkey -K \\SOFTWARE", # dump SOFTWARE hive
"netstat", # network
"malfind", # memory IOC
"exit" # end the volshell session
]
def run_volshell():
# spawn volshell
child = pexpect.spawn(f"{VOL_PATH} -f {IMAGE} --plugins windows.volshell.Volshell --profile={PROFILE}")
child.expect_exact("> ") # wait for the volshell prompt
for cmd in commands:
print(f">>> {cmd}")
child.sendline(cmd)
child.expect_exact("> ")
# print the text that appeared before the prompt
output = child.before.decode('utf-8', errors='ignore')
print(output)
child.close()
if __name__ == "__main__":
run_volshell()
What this does:
- Launches
vol.py … windows.volshell.Volshell
- Sends a sequence of commands (
pslist, dlllist, …)
- Captures their outputs and prints them in your Python driver
4. Putting it all together
- Pick Approach A if you want tight integration and maximum performance.
- Pick Approach B if you have an existing Volshell script or you prefer the interactive plugin’s command set.
Either way, you can now automate your memory‑forensic triage, dump your hive, enumerate network sockets, hunt for suspicious code with malfind, and output all of that in one go. Good luck, and happy IR hunting! 🕵️♂️