Skip to content

Commit 1f983ac

Browse files
authored
Merge pull request #1585 from volatilityfoundation/issues/issue1577
Expose and use `get_pefile_obj` rather than having local copies
2 parents b51acfd + 2d0856f commit 1f983ac

File tree

2 files changed

+13
-43
lines changed

2 files changed

+13
-43
lines changed

volatility3/framework/plugins/windows/pe_symbols.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ class PESymbols(interfaces.plugins.PluginInterface):
244244

245245
_required_framework_version = (2, 7, 0)
246246

247-
_version = (1, 0, 1)
247+
_version = (1, 1, 0)
248248

249249
# used for special handling of the kernel PDB file. See later notes
250250
os_module_name = "ntoskrnl.exe"
@@ -292,8 +292,9 @@ def get_requirements(cls) -> List:
292292
),
293293
]
294294

295-
@staticmethod
296-
def _get_pefile_obj(
295+
@classmethod
296+
def get_pefile_obj(
297+
cls,
297298
context: interfaces.context.ContextInterface,
298299
pe_table_name: str,
299300
layer_name: str,
@@ -486,7 +487,7 @@ def _get_exported_symbols(
486487
module_start = module_info[1]
487488

488489
# we need a valid PE with an export table
489-
pe_module = PESymbols._get_pefile_obj(
490+
pe_module = PESymbols.get_pefile_obj(
490491
context, pe_table_name, layer_name, module_start
491492
)
492493
if not pe_module:

volatility3/framework/plugins/windows/skeleton_key_check.py

Lines changed: 8 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,21 @@
1111
#
1212
# https://volatility-labs.blogspot.com/2021/10/memory-forensics-r-illustrated.html
1313

14-
import io
1514
import logging
1615
from typing import Iterable, Tuple, List, Optional
1716

1817
import pefile
1918

2019
from volatility3.framework import interfaces, symbols, exceptions
21-
from volatility3.framework import renderers, constants
20+
from volatility3.framework import renderers
2221
from volatility3.framework.configuration import requirements
2322
from volatility3.framework.layers import scanners
2423
from volatility3.framework.objects import utility
2524
from volatility3.framework.renderers import format_hints
2625
from volatility3.framework.symbols import intermed
2726
from volatility3.framework.symbols.windows import pdbutil
2827
from volatility3.framework.symbols.windows.extensions import pe
29-
from volatility3.plugins.windows import pslist, vadinfo
28+
from volatility3.plugins.windows import pslist, vadinfo, pe_symbols
3029

3130
try:
3231
import capstone
@@ -61,43 +60,11 @@ def get_requirements(cls):
6160
requirements.VersionRequirement(
6261
name="pdbutil", component=pdbutil.PDBUtility, version=(1, 0, 0)
6362
),
63+
requirements.VersionRequirement(
64+
name="pe_symbols", component=pe_symbols.PESymbols, version=(1, 1, 0)
65+
),
6466
]
6567

66-
def _get_pefile_obj(
67-
self, pe_table_name: str, layer_name: str, base_address: int
68-
) -> pefile.PE:
69-
"""
70-
Attempts to pefile object from the bytes of the PE file
71-
72-
Args:
73-
pe_table_name: name of the pe types table
74-
layer_name: name of the lsass.exe process layer
75-
base_address: base address of cryptdll.dll in lsass.exe
76-
77-
Returns:
78-
the constructed pefile object
79-
"""
80-
pe_data = io.BytesIO()
81-
82-
try:
83-
dos_header = self.context.object(
84-
pe_table_name + constants.BANG + "_IMAGE_DOS_HEADER",
85-
offset=base_address,
86-
layer_name=layer_name,
87-
)
88-
89-
for offset, data in dos_header.reconstruct():
90-
pe_data.seek(offset)
91-
pe_data.write(data)
92-
93-
pe_ret = pefile.PE(data=pe_data.getvalue(), fast_load=True)
94-
95-
except exceptions.InvalidAddressException:
96-
vollog.debug("Unable to reconstruct cryptdll.dll in memory")
97-
pe_ret = None
98-
99-
return pe_ret
100-
10168
def _check_for_skeleton_key_vad(
10269
self,
10370
csystem: interfaces.objects.ObjectInterface,
@@ -497,7 +464,9 @@ def _find_csystems_with_export(
497464
self.context, self.config_path, "windows", "pe", class_types=pe.class_types
498465
)
499466

500-
cryptdll = self._get_pefile_obj(pe_table_name, proc_layer_name, cryptdll_base)
467+
cryptdll = pe_symbols.PESymbols.get_pefile_obj(
468+
self.context, pe_table_name, proc_layer_name, cryptdll_base
469+
)
501470
if not cryptdll:
502471
return None
503472

0 commit comments

Comments
 (0)