From 941e40c368b79a36ee59a2cdf860aad83d489d15 Mon Sep 17 00:00:00 2001 From: Andrew Case Date: Fri, 31 Jan 2025 22:59:32 +0000 Subject: [PATCH 1/4] Fix get_name API, fix malfind --- volatility3/framework/plugins/linux/elfs.py | 2 +- volatility3/framework/plugins/linux/malfind.py | 8 +++++--- volatility3/framework/plugins/linux/proc.py | 2 +- .../framework/symbols/linux/extensions/__init__.py | 8 +++++++- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/volatility3/framework/plugins/linux/elfs.py b/volatility3/framework/plugins/linux/elfs.py index 0d1c9c2dda..b9dcc3cca7 100644 --- a/volatility3/framework/plugins/linux/elfs.py +++ b/volatility3/framework/plugins/linux/elfs.py @@ -177,7 +177,7 @@ def _generator(self, tasks): name, format_hints.Hex(vma.vm_start), format_hints.Hex(vma.vm_end), - path, + path or renderers.NotAvailableValue(), file_output, ), ) diff --git a/volatility3/framework/plugins/linux/malfind.py b/volatility3/framework/plugins/linux/malfind.py index e45688e975..a6e739bbfe 100644 --- a/volatility3/framework/plugins/linux/malfind.py +++ b/volatility3/framework/plugins/linux/malfind.py @@ -56,10 +56,10 @@ def _list_injections(self, task): ) if ( vma.is_suspicious(proc_layer) - and vma.get_name(self.context, task) != "[vdso]" + and vma_name != "[vdso]" ): data = proc_layer.read(vma.vm_start, 64, pad=True) - yield vma, data + yield vma, vma_name, data def _generator(self, tasks): # determine if we're on a 32 or 64 bit kernel @@ -71,7 +71,7 @@ def _generator(self, tasks): for task in tasks: process_name = utility.array_to_string(task.comm) - for vma, data in self._list_injections(task): + for vma, vma_name, data in self._list_injections(task): if is_32bit_arch: architecture = "intel" else: @@ -88,6 +88,7 @@ def _generator(self, tasks): process_name, format_hints.Hex(vma.vm_start), format_hints.Hex(vma.vm_end), + vma_name or renderers.NotAvailableValue(), vma.get_protection(), format_hints.HexBytes(data), disasm, @@ -103,6 +104,7 @@ def run(self): ("Process", str), ("Start", format_hints.Hex), ("End", format_hints.Hex), + ("Path", str), ("Protection", str), ("Hexdump", format_hints.HexBytes), ("Disasm", interfaces.renderers.Disassembly), diff --git a/volatility3/framework/plugins/linux/proc.py b/volatility3/framework/plugins/linux/proc.py index 23d6605b70..5acba65944 100644 --- a/volatility3/framework/plugins/linux/proc.py +++ b/volatility3/framework/plugins/linux/proc.py @@ -246,7 +246,7 @@ def vma_filter_function(x: interfaces.objects.ObjectInterface) -> bool: major, minor, inode_num, - path, + path or renderers.NotAvailableValue(), file_output, ), ) diff --git a/volatility3/framework/symbols/linux/extensions/__init__.py b/volatility3/framework/symbols/linux/extensions/__init__.py index 8893e6e52f..5ac391da17 100644 --- a/volatility3/framework/symbols/linux/extensions/__init__.py +++ b/volatility3/framework/symbols/linux/extensions/__init__.py @@ -1056,7 +1056,7 @@ def get_page_offset(self) -> int: parent_layer = self._context.layers[self.vol.layer_name] return self.vm_pgoff << parent_layer.page_shift - def get_name(self, context, task): + def _do_get_name(self, context, task) -> str: if self.vm_file != 0: fname = linux.LinuxUtilities.path_for_file(context, task, self.vm_file) elif self.vm_start <= task.mm.start_brk and self.vm_end >= task.mm.brk: @@ -1072,6 +1072,12 @@ def get_name(self, context, task): fname = "Anonymous Mapping" return fname + def get_name(self, context, task) -> Optional[str]: + try: + return self._do_get_name(context, task) + except exceptions.InvalidAddressException: + return None + # used by malfind def is_suspicious(self, proclayer=None): ret = False From b81d2a27810681ebe810490afff9638d6b3c4d1d Mon Sep 17 00:00:00 2001 From: Andrew Case Date: Fri, 31 Jan 2025 23:03:43 +0000 Subject: [PATCH 2/4] Fix get_name API, fix malfind --- volatility3/framework/plugins/linux/malfind.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/volatility3/framework/plugins/linux/malfind.py b/volatility3/framework/plugins/linux/malfind.py index a6e739bbfe..7d8dd7f180 100644 --- a/volatility3/framework/plugins/linux/malfind.py +++ b/volatility3/framework/plugins/linux/malfind.py @@ -54,10 +54,7 @@ def _list_injections(self, task): vollog.debug( f"Injections : processing PID {task.pid} : VMA {vma_name} : {hex(vma.vm_start)}-{hex(vma.vm_end)}" ) - if ( - vma.is_suspicious(proc_layer) - and vma_name != "[vdso]" - ): + if vma.is_suspicious(proc_layer) and vma_name != "[vdso]": data = proc_layer.read(vma.vm_start, 64, pad=True) yield vma, vma_name, data From 6100d7756f4919ffb6679564bfeee784b7eeadf2 Mon Sep 17 00:00:00 2001 From: Andrew Case Date: Fri, 7 Feb 2025 13:05:41 -0600 Subject: [PATCH 3/4] Add function typing --- volatility3/framework/plugins/linux/malfind.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/volatility3/framework/plugins/linux/malfind.py b/volatility3/framework/plugins/linux/malfind.py index 7d8dd7f180..85cfaed31c 100644 --- a/volatility3/framework/plugins/linux/malfind.py +++ b/volatility3/framework/plugins/linux/malfind.py @@ -2,7 +2,7 @@ # which is available at https://www.volatilityfoundation.org/license/vsl-v1.0 # -from typing import List +from typing import List, Tuple, Optional import logging from volatility3.framework import interfaces from volatility3.framework import renderers, symbols @@ -39,7 +39,7 @@ def get_requirements(cls) -> List[interfaces.configuration.RequirementInterface] ), ] - def _list_injections(self, task): + def _list_injections(self, task) -> Tuple[interfaces.objects.ObjectInterface, Optional[str], bytes]: """Generate memory regions for a process that may contain injected code.""" From ac8eeec52e0eb0118091e8db04b233b387e8c29b Mon Sep 17 00:00:00 2001 From: Andrew Case Date: Fri, 7 Feb 2025 13:17:10 -0600 Subject: [PATCH 4/4] Fixes for black --- volatility3/framework/plugins/linux/malfind.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/volatility3/framework/plugins/linux/malfind.py b/volatility3/framework/plugins/linux/malfind.py index 85cfaed31c..2971168909 100644 --- a/volatility3/framework/plugins/linux/malfind.py +++ b/volatility3/framework/plugins/linux/malfind.py @@ -39,7 +39,9 @@ def get_requirements(cls) -> List[interfaces.configuration.RequirementInterface] ), ] - def _list_injections(self, task) -> Tuple[interfaces.objects.ObjectInterface, Optional[str], bytes]: + def _list_injections( + self, task + ) -> Tuple[interfaces.objects.ObjectInterface, Optional[str], bytes]: """Generate memory regions for a process that may contain injected code."""