-
Notifications
You must be signed in to change notification settings - Fork 457
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Linux: Address limitations in determining KASLR shifts by introducing VMCoreInfo support #1332
Open
gcmoreira
wants to merge
3
commits into
volatilityfoundation:develop
Choose a base branch
from
gcmoreira:linux_vmcoreinfo_aslr_and_plugin
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+260
−4
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,8 +76,12 @@ def stack( | |
isf_url=isf_path, | ||
) | ||
context.symbol_space.append(table) | ||
|
||
kaslr_shift, aslr_shift = cls.find_aslr( | ||
context, table_name, layer_name, progress_callback=progress_callback | ||
context, | ||
table_name, | ||
layer_name, | ||
progress_callback=progress_callback, | ||
) | ||
|
||
layer_class: Type = intel.Intel | ||
|
@@ -118,15 +122,25 @@ def stack( | |
return None | ||
|
||
@classmethod | ||
def find_aslr( | ||
def find_aslr_classic( | ||
cls, | ||
context: interfaces.context.ContextInterface, | ||
symbol_table: str, | ||
layer_name: str, | ||
progress_callback: constants.ProgressCallback = None, | ||
) -> Tuple[int, int]: | ||
"""Determines the offset of the actual DTB in physical space and its | ||
symbol offset.""" | ||
symbol offset. | ||
|
||
Args: | ||
context: The context to retrieve required elements (layers, symbol tables) from | ||
symbol_table: The name of the kernel module on which to operate | ||
layer_name: The layer within the context in which the module exists | ||
progress_callback: A function that takes a percentage (and an optional description) that will be called periodically | ||
|
||
Returns: | ||
kaslr_shirt and aslr_shift | ||
""" | ||
init_task_symbol = symbol_table + constants.BANG + "init_task" | ||
init_task_json_address = context.symbol_space.get_symbol( | ||
init_task_symbol | ||
|
@@ -184,6 +198,58 @@ def find_aslr( | |
vollog.debug("Scanners could not determine any ASLR shifts, using 0 for both") | ||
return 0, 0 | ||
|
||
@classmethod | ||
def find_aslr_vmcoreinfo( | ||
cls, | ||
context: interfaces.context.ContextInterface, | ||
layer_name: str, | ||
progress_callback: constants.ProgressCallback = None, | ||
) -> Optional[Tuple[int, int]]: | ||
"""Determines the ASLR offsets using the VMCOREINFO ELF note | ||
|
||
Args: | ||
context: The context to retrieve required elements (layers, symbol tables) from | ||
layer_name: The layer within the context in which the module exists | ||
progress_callback: A function that takes a percentage (and an optional description) that will be called periodically | ||
|
||
Returns: | ||
kaslr_shirt and aslr_shift | ||
""" | ||
|
||
for ( | ||
_vmcoreinfo_offset, | ||
vmcoreinfo, | ||
) in linux.VMCoreInfo.search_vmcoreinfo_elf_note( | ||
context=context, | ||
layer_name=layer_name, | ||
progress_callback=progress_callback, | ||
): | ||
|
||
phys_base_str = vmcoreinfo.get("NUMBER(phys_base)") | ||
if phys_base_str is None: | ||
# We are in kernel (x86) < 4.10 401721ecd1dcb0a428aa5d6832ee05ffbdbffbbe where it was SYMBOL(phys_base) | ||
# It's the symbol address instead of the value itself, which is useless for calculating the physical address. | ||
continue | ||
|
||
kerneloffset_str = vmcoreinfo.get("KERNELOFFSET") | ||
if kerneloffset_str is None: | ||
# KERNELOFFSET: (x86) kernels < 3.13 b6085a865762236bb84934161273cdac6dd11c2d | ||
continue | ||
|
||
aslr_shift = int(kerneloffset_str, 16) | ||
kaslr_shift = int(phys_base_str) + aslr_shift | ||
|
||
vollog.debug( | ||
"Linux ASLR shift values found in VMCOREINFO ELF note: physical 0x%x virtual 0x%x", | ||
kaslr_shift, | ||
aslr_shift, | ||
) | ||
|
||
return kaslr_shift, aslr_shift | ||
|
||
vollog.debug("The vmcoreinfo scanner could not determine any ASLR shifts") | ||
return None | ||
|
||
@classmethod | ||
def virtual_to_physical_address(cls, addr: int) -> int: | ||
"""Converts a virtual linux address to a physical one (does not account | ||
|
@@ -192,6 +258,41 @@ def virtual_to_physical_address(cls, addr: int) -> int: | |
return addr - 0xFFFFFFFF80000000 | ||
return addr - 0xC0000000 | ||
|
||
@classmethod | ||
def find_aslr( | ||
cls, | ||
context: interfaces.context.ContextInterface, | ||
symbol_table: str, | ||
layer_name: str, | ||
progress_callback: constants.ProgressCallback = None, | ||
) -> Tuple[int, int]: | ||
"""Determines the offset of the actual DTB in physical space and its | ||
symbol offset. | ||
Args: | ||
context: The context to retrieve required elements (layers, symbol tables) from | ||
symbol_table: The name of the kernel module on which to operate | ||
layer_name: The layer within the context in which the module exists | ||
progress_callback: A function that takes a percentage (and an optional description) that will be called periodically | ||
|
||
Returns: | ||
kaslr_shirt and aslr_shift | ||
""" | ||
|
||
aslr_shifts = cls.find_aslr_vmcoreinfo( | ||
context, layer_name, progress_callback=progress_callback | ||
) | ||
if aslr_shifts: | ||
kaslr_shift, aslr_shift = aslr_shifts | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does the rest of the automagic ever validate these values in any way? If not, perhaps they should (checking for an ELF signature or mapping the virtual kernel to the physical one and checking a number of bytes match, just something to make sure the map works correctly)? |
||
else: | ||
# Fallback to the traditional scanner method | ||
kaslr_shift, aslr_shift = cls.find_aslr_classic( | ||
context, | ||
symbol_table, | ||
layer_name, | ||
progress_callback=progress_callback, | ||
) | ||
return kaslr_shift, aslr_shift | ||
|
||
|
||
class LinuxSymbolFinder(symbol_finder.SymbolFinder): | ||
"""Linux symbol loader based on uname signature strings.""" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# This file is Copyright 2024 Volatility Foundation and licensed under the Volatility Software License 1.0 | ||
# which is available at https://www.volatilityfoundation.org/license/vsl-v1.0 | ||
# | ||
|
||
from typing import List | ||
|
||
from volatility3.framework import renderers, interfaces | ||
from volatility3.framework.configuration import requirements | ||
from volatility3.framework.interfaces import plugins | ||
from volatility3.framework.symbols import linux | ||
from volatility3.framework.renderers import format_hints | ||
|
||
|
||
class VMCoreInfo(plugins.PluginInterface): | ||
"""Enumerate VMCoreInfo tables""" | ||
|
||
_required_framework_version = (2, 11, 0) | ||
_version = (1, 0, 0) | ||
|
||
@classmethod | ||
def get_requirements(cls) -> List[interfaces.configuration.RequirementInterface]: | ||
return [ | ||
requirements.TranslationLayerRequirement( | ||
name="primary", description="Memory layer to scan" | ||
), | ||
requirements.VersionRequirement( | ||
name="VMCoreInfo", component=linux.VMCoreInfo, version=(1, 0, 0) | ||
), | ||
] | ||
|
||
def _generator(self): | ||
layer_name = self.config["primary"] | ||
for ( | ||
vmcoreinfo_offset, | ||
vmcoreinfo, | ||
) in linux.VMCoreInfo.search_vmcoreinfo_elf_note( | ||
context=self.context, | ||
layer_name=layer_name, | ||
): | ||
for key, value in vmcoreinfo.items(): | ||
yield 0, (format_hints.Hex(vmcoreinfo_offset), key, value) | ||
|
||
def run(self): | ||
headers = [ | ||
("Offset", format_hints.Hex), | ||
("Key", str), | ||
("Value", str), | ||
] | ||
return renderers.TreeGrid(headers, self._generator()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SInce this is versioned separately, we should check the version above (and bail gracefully) if it's different to what we expected. That'll allow addition only bumps and major breaking bumps just fine.