mirror of
https://github.com/volatilityfoundation/volatility3.git
synced 2026-08-24 07:02:23 +02:00
91 lines
4.5 KiB
Python
91 lines
4.5 KiB
Python
# This file is Copyright 2019 Volatility Foundation and licensed under the Volatility Software License 1.0
|
|
# which is available at https://www.volatilityfoundation.org/license/vsl-v1.0
|
|
#
|
|
|
|
import logging
|
|
from typing import Iterable, List, Tuple
|
|
|
|
from volatility.framework import interfaces, renderers
|
|
from volatility.framework.configuration import requirements
|
|
from volatility.framework.renderers import format_hints
|
|
from volatility.plugins import yarascan
|
|
from volatility.plugins.windows import pslist
|
|
|
|
vollog = logging.getLogger(__name__)
|
|
|
|
try:
|
|
import yara
|
|
except ImportError:
|
|
vollog.info("Python Yara module not found, plugin (and dependent plugins) not available")
|
|
|
|
|
|
class VadYaraScan(interfaces.plugins.PluginInterface):
|
|
"""Scans all the Virtual Address Descriptor memory maps using yara."""
|
|
_version = (1, 0, 0)
|
|
|
|
@classmethod
|
|
def get_requirements(cls) -> List[interfaces.configuration.RequirementInterface]:
|
|
return [
|
|
requirements.TranslationLayerRequirement(name = 'primary',
|
|
description = "Memory layer for the kernel",
|
|
architectures = ["Intel32", "Intel64"]),
|
|
requirements.SymbolTableRequirement(name = "nt_symbols", description = "Windows kernel symbols"),
|
|
requirements.BooleanRequirement(name = "wide",
|
|
description = "Match wide (unicode) strings",
|
|
default = False,
|
|
optional = True),
|
|
requirements.StringRequirement(name = "yara_rules",
|
|
description = "Yara rules (as a string)",
|
|
optional = True),
|
|
requirements.URIRequirement(name = "yara_file", description = "Yara rules (as a file)", optional = True),
|
|
requirements.IntRequirement(name = "max_size",
|
|
default = 0x40000000,
|
|
description = "Set the maximum size (default is 1GB)",
|
|
optional = True),
|
|
requirements.PluginRequirement(name = 'pslist', plugin = pslist.PsList, version = (1, 0, 0)),
|
|
requirements.VersionRequirement(name = 'yarascanner', component = yarascan.YaraScanner,
|
|
version = (2, 0, 0)),
|
|
requirements.ListRequirement(name = 'pid',
|
|
element_type = int,
|
|
description = "Process IDs to include (all other processes are excluded)",
|
|
optional = True)
|
|
]
|
|
|
|
def _generator(self):
|
|
|
|
rules = yarascan.YaraScan.process_yara_options(dict(self.config))
|
|
|
|
filter_func = pslist.PsList.create_pid_filter(self.config.get('pid', None))
|
|
|
|
for task in pslist.PsList.list_processes(context = self.context,
|
|
layer_name = self.config['primary'],
|
|
symbol_table = self.config['nt_symbols'],
|
|
filter_func = filter_func):
|
|
layer_name = task.add_process_layer()
|
|
layer = self.context.layers[layer_name]
|
|
for offset, rule_name, name, value in layer.scan(context = self.context,
|
|
scanner = yarascan.YaraScanner(rules = rules),
|
|
sections = self.get_vad_maps(task)):
|
|
yield 0, (format_hints.Hex(offset), task.UniqueProcessId, rule_name, name, value)
|
|
|
|
@staticmethod
|
|
def get_vad_maps(task: interfaces.objects.ObjectInterface) -> Iterable[Tuple[int, int]]:
|
|
"""Creates a map of start/end addresses within a virtual address
|
|
descriptor tree.
|
|
|
|
Args:
|
|
task: The EPROCESS object of which to traverse the vad tree
|
|
|
|
Returns:
|
|
An iterable of tuples containing start and end addresses for each descriptor
|
|
"""
|
|
vad_root = task.get_vad_root()
|
|
for vad in vad_root.traverse():
|
|
end = vad.get_end()
|
|
start = vad.get_start()
|
|
yield (start, end - start)
|
|
|
|
def run(self):
|
|
return renderers.TreeGrid([('Offset', format_hints.Hex), ('Pid', int), ('Rule', str), ('Component', str),
|
|
('Value', bytes)], self._generator())
|