Skip to content

Commit 6f7f128

Browse files
committed
Fix bug with PAGE_SHIFT that wasn't shifted, also greatly increases performance
Use black Better logging
1 parent 7c82da4 commit 6f7f128

File tree

3 files changed

+29
-11
lines changed

3 files changed

+29
-11
lines changed

volatility3/framework/layers/intel.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,11 @@ def _mask(value: int, high_bit: int, low_bit: int) -> int:
110110
def _page_is_valid(entry: int) -> bool:
111111
"""Returns whether a particular page is valid based on its entry."""
112112
return bool(entry & 1)
113-
113+
114114
@staticmethod
115115
def _page_is_dirty(entry: int) -> bool:
116116
"""Returns whether a particular page is dirty based on its entry."""
117-
return bool(entry & (1<<6))
117+
return bool(entry & (1 << 6))
118118

119119
def canonicalize(self, addr: int) -> int:
120120
"""Canonicalizes an address by performing an appropiate sign extension on the higher addresses"""
@@ -267,7 +267,7 @@ def is_valid(self, offset: int, length: int = 1) -> bool:
267267
def is_dirty(self, offset: int) -> bool:
268268
"""Returns whether the page at offset is marked dirty"""
269269
return self._page_is_dirty(self._translate_entry(offset)[0])
270-
270+
271271
def mapping(
272272
self, offset: int, length: int, ignore_errors: bool = False
273273
) -> Iterable[Tuple[int, int, int, int, str]]:

volatility3/framework/plugins/linux/malfind.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@
33
#
44

55
from typing import List
6-
6+
import logging
77
from volatility3.framework import constants, interfaces
88
from volatility3.framework import renderers
99
from volatility3.framework.configuration import requirements
1010
from volatility3.framework.objects import utility
1111
from volatility3.framework.renderers import format_hints
1212
from volatility3.plugins.linux import pslist
1313

14+
vollog = logging.getLogger(__name__)
15+
1416

1517
class Malfind(interfaces.plugins.PluginInterface):
1618
"""Lists process memory ranges that potentially contain injected code."""
@@ -47,7 +49,14 @@ def _list_injections(self, task):
4749
proc_layer = self.context.layers[proc_layer_name]
4850

4951
for vma in task.mm.get_vma_iter():
50-
if vma.is_suspicious(proc_layer) and vma.get_name(self.context, task) != "[vdso]":
52+
vma_name = vma.get_name(self.context, task)
53+
vollog.debug(
54+
f"Injections : processing PID {task.pid} : VMA {vma_name} : {hex(vma.vm_start)}-{hex(vma.vm_end)}"
55+
)
56+
if (
57+
vma.is_suspicious(proc_layer)
58+
and vma.get_name(self.context, task) != "[vdso]"
59+
):
5160
data = proc_layer.read(vma.vm_start, 64, pad=True)
5261
yield vma, data
5362

volatility3/framework/symbols/linux/extensions/__init__.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ def get_name(self, context, task):
578578
return fname
579579

580580
# used by malfind
581-
def is_suspicious(self, proclayer):
581+
def is_suspicious(self, proclayer=None):
582582
ret = False
583583

584584
flags_str = self.get_protection()
@@ -587,15 +587,24 @@ def is_suspicious(self, proclayer):
587587
ret = True
588588
elif flags_str == "r-x" and self.vm_file.dereference().vol.offset == 0:
589589
ret = True
590-
elif "x" in flags_str:
591-
for i in range(self.vm_start,self.vm_end,constants.linux.PAGE_SHIFT):
590+
elif proclayer and "x" in flags_str:
591+
for i in range(self.vm_start, self.vm_end, 1 << constants.linux.PAGE_SHIFT):
592592
try:
593593
if proclayer.is_dirty(i):
594-
vollog.warning(f"Found malicious (dirty+exec) page at {hex(i)} !")
594+
vollog.warning(
595+
f"Found malicious (dirty+exec) page at {hex(i)} !"
596+
)
597+
# We do not attempt to find other dirty+exec pages once we have found one
595598
ret = True
596599
break
597-
except (exceptions.PagedInvalidAddressException, exceptions.InvalidAddressException):
598-
pass
600+
except (
601+
exceptions.PagedInvalidAddressException,
602+
exceptions.InvalidAddressException,
603+
) as excp:
604+
vollog.debug(f"Unable to translate address {hex(i)} : {excp}")
605+
# Abort as it is likely that other addresses in the same range will also fail
606+
ret = False
607+
break
599608
return ret
600609

601610

0 commit comments

Comments
 (0)