|
| 1 | +# This file is Copyright 2024 Volatility Foundation and licensed under the Volatility Software License 1.0 |
| 2 | +# which is available at https://www.volatilityfoundation.org/license/vsl-v1.0 |
| 3 | +# |
| 4 | + |
| 5 | +import logging |
| 6 | +from typing import List, Iterator |
| 7 | + |
| 8 | +from volatility3.framework import renderers, interfaces |
| 9 | +from volatility3.framework.constants import architectures |
| 10 | +from volatility3.framework.objects import utility |
| 11 | +from volatility3.framework.configuration import requirements |
| 12 | +from volatility3.framework.interfaces import plugins |
| 13 | +from volatility3.plugins.linux import pslist |
| 14 | + |
| 15 | +vollog = logging.getLogger(__name__) |
| 16 | + |
| 17 | + |
| 18 | +class Ptrace(plugins.PluginInterface): |
| 19 | + """Enumerates ptrace's tracer and tracee tasks""" |
| 20 | + |
| 21 | + _required_framework_version = (2, 10, 0) |
| 22 | + _version = (1, 0, 0) |
| 23 | + |
| 24 | + @classmethod |
| 25 | + def get_requirements(cls) -> List[interfaces.configuration.RequirementInterface]: |
| 26 | + return [ |
| 27 | + requirements.ModuleRequirement( |
| 28 | + name="kernel", |
| 29 | + description="Linux kernel", |
| 30 | + architectures=architectures.LINUX_ARCHS, |
| 31 | + ), |
| 32 | + requirements.PluginRequirement( |
| 33 | + name="pslist", plugin=pslist.PsList, version=(2, 2, 0) |
| 34 | + ), |
| 35 | + ] |
| 36 | + |
| 37 | + @classmethod |
| 38 | + def enumerate_ptrace_tasks( |
| 39 | + cls, |
| 40 | + context: interfaces.context.ContextInterface, |
| 41 | + vmlinux_module_name: str, |
| 42 | + ) -> Iterator[interfaces.objects.ObjectInterface]: |
| 43 | + """Enumerates ptrace's tracer and tracee tasks |
| 44 | +
|
| 45 | + Args: |
| 46 | + context: The context to retrieve required elements (layers, symbol tables) from |
| 47 | + vmlinux_module_name: The name of the kernel module on which to operate |
| 48 | +
|
| 49 | + Yields: |
| 50 | + A task_struct object |
| 51 | + """ |
| 52 | + |
| 53 | + tasks = pslist.PsList.list_tasks( |
| 54 | + context, |
| 55 | + vmlinux_module_name, |
| 56 | + filter_func=pslist.PsList.create_pid_filter(), |
| 57 | + include_threads=True, |
| 58 | + ) |
| 59 | + |
| 60 | + for task in tasks: |
| 61 | + if task.is_being_ptraced or task.is_ptracing: |
| 62 | + yield task |
| 63 | + |
| 64 | + def _generator(self, vmlinux_module_name): |
| 65 | + for task in self.enumerate_ptrace_tasks(self.context, vmlinux_module_name): |
| 66 | + task_comm = utility.array_to_string(task.comm) |
| 67 | + user_pid = task.tgid |
| 68 | + user_tid = task.pid |
| 69 | + tracer_tid = task.get_ptrace_tracer_tid() or renderers.NotAvailableValue() |
| 70 | + tracee_tids = task.get_ptrace_tracee_tids() or [ |
| 71 | + renderers.NotAvailableValue() |
| 72 | + ] |
| 73 | + flags = task.get_ptrace_tracee_flags() or renderers.NotAvailableValue() |
| 74 | + |
| 75 | + for level, tracee_tid in enumerate(tracee_tids): |
| 76 | + fields = [ |
| 77 | + task_comm, |
| 78 | + user_pid, |
| 79 | + user_tid, |
| 80 | + tracer_tid, |
| 81 | + tracee_tid, |
| 82 | + flags, |
| 83 | + ] |
| 84 | + yield (level, fields) |
| 85 | + |
| 86 | + def run(self): |
| 87 | + vmlinux_module_name = self.config["kernel"] |
| 88 | + |
| 89 | + headers = [ |
| 90 | + ("Process", str), |
| 91 | + ("PID", int), |
| 92 | + ("TID", int), |
| 93 | + ("Tracer TID", int), |
| 94 | + ("Tracee TID", int), |
| 95 | + ("Flags", str), |
| 96 | + ] |
| 97 | + return renderers.TreeGrid(headers, self._generator(vmlinux_module_name)) |
0 commit comments