-
Notifications
You must be signed in to change notification settings - Fork 89
feat: Refactor fstab parsing and add plugins for /etc/fstab and /proc/mounts #1613
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
Open
Yld2004
wants to merge
14
commits into
fox-it:main
Choose a base branch
from
Yld2004:mount-and-fstab
base: main
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.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
224cede
added a plugin to parser /proc/<pid>/maps
Yld2004 3ef99b3
added test for mount plugin
Yld2004 8c40c10
added plugin that parsers /etc/fstab
Yld2004 e2e5cf9
added test for the fstab plugin
Yld2004 a1b4154
Merge branch 'main' into mount-and-fstab
Yld2004 98394fe
Apply suggestions from code review
Yld2004 83d42cb
Merge branch 'fox-it:main' into mount-and-fstab
Yld2004 1cb43ba
CR fix
Yld2004 aadae5f
ruff fix
Yld2004 4a25b21
more fixes
Yld2004 0374b3a
more ruff fixes
Yld2004 724f7ac
Apply suggestions from code review
Yld2004 8815eca
more CR fixes
Yld2004 e5735ad
Merge branch 'main' into mount-and-fstab
Yld2004 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 hidden or 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 hidden or 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,68 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from typing import TYPE_CHECKING | ||
|
|
||
| from dissect.target.exceptions import UnsupportedPluginError | ||
| from dissect.target.helpers.record import TargetRecordDescriptor | ||
| from dissect.target.plugin import Plugin, export | ||
| from dissect.target.plugins.os.unix._os import parse_fstab_entry | ||
|
|
||
| if TYPE_CHECKING: | ||
| from collections.abc import Iterator | ||
|
|
||
| FstabRecord = TargetRecordDescriptor( | ||
| "linux/etc/fstab", | ||
| [ | ||
| ("string", "device_path"), | ||
| ("string", "mount_path"), | ||
| ("string", "fs_type"), | ||
| ("string[]", "options"), | ||
| ("boolean", "is_dump"), | ||
| ("varint", "pass_num"), | ||
| ], | ||
| ) | ||
|
|
||
|
|
||
| class FstabPlugin(Plugin): | ||
| """Linux fstab file plugin.""" | ||
|
|
||
| __namespace__ = "etc" | ||
|
|
||
| def check_compatible(self) -> None: | ||
| if not self.target.fs.exists("/etc/fstab"): | ||
| raise UnsupportedPluginError("No fstab file found on target") | ||
|
|
||
| @export(record=FstabRecord) | ||
| def fstab(self) -> Iterator[FstabRecord]: | ||
| """Return the mount entries from ``/etc/fstab``. | ||
|
|
||
| Yields ``FstabRecord`` with the following fields: | ||
|
|
||
| . code-block:: text | ||
|
|
||
| device_path (string): The device path. | ||
| mount_path (string): The mount path. | ||
| fs_type (string): The filesystem type. | ||
| options (string[]): The mount options. | ||
| is_dump (boolean): The dump frequency flag. | ||
| pass_num (varint): The pass number. | ||
| """ | ||
| fstab_path = self.target.fs.path("/etc/fstab") | ||
| with fstab_path.open("rt") as fstab_file: | ||
| for line in fstab_file: | ||
| try: | ||
| entry = parse_fstab_entry(line) | ||
| except ValueError as e: | ||
| self.target.log.warning("Failed to parse fstab entry: %s", e) | ||
| continue | ||
|
|
||
| fs_spec, mount_point, fs_type, options, is_dump, pass_num = entry | ||
| yield FstabRecord( | ||
| device_path=fs_spec, | ||
| mount_path=mount_point, | ||
| fs_type=fs_type, | ||
| options=options.split(","), | ||
| is_dump=is_dump, | ||
| pass_num=pass_num, | ||
| _target=self.target, | ||
| ) |
This file contains hidden or 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,56 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from typing import TYPE_CHECKING | ||
|
|
||
| from dissect.target.exceptions import UnsupportedPluginError | ||
| from dissect.target.helpers.record import TargetRecordDescriptor | ||
| from dissect.target.plugin import Plugin, export | ||
| from dissect.target.plugins.os.unix.etc.fstab import FstabRecord | ||
|
|
||
| if TYPE_CHECKING: | ||
| from collections.abc import Iterator | ||
|
|
||
| MountRecord = TargetRecordDescriptor( | ||
| "linux/proc/mounts", | ||
| [ | ||
| ("varint", "pid"), | ||
| *FstabRecord.target_fields, | ||
| ], | ||
| ) | ||
|
|
||
|
|
||
| class MountsPlugin(Plugin): | ||
| """Linux volatile proc mounts plugin.""" | ||
|
|
||
| def check_compatible(self) -> None: | ||
| if not self.target.has_function("proc"): | ||
| raise UnsupportedPluginError("proc filesystem not available") | ||
|
|
||
| @export(record=MountRecord) | ||
| def mounts(self) -> Iterator[MountRecord]: | ||
| """Return the mount points for all processes. | ||
|
|
||
| Yields ``MountRecord`` with the following fields: | ||
|
|
||
| . code-block:: text | ||
|
|
||
| pid (varint): The process id (pid) of the process. | ||
| device_path (string): The device path. | ||
| mount_path (string): The mount path. | ||
| fs_type (string): The filesystem type. | ||
| options (string[]): The mount options. | ||
| is_dump (boolean): The dump frequency flag. | ||
| pass_num (varint): The pass number. | ||
| """ | ||
| for process in self.target.proc.processes(): | ||
| for mount_entry in process.mounts(): | ||
| yield MountRecord( | ||
| pid=process.pid, | ||
| device_path=mount_entry.fs_spec, | ||
| mount_path=mount_entry.mount_path, | ||
| fs_type=mount_entry.fs_type, | ||
| options=mount_entry.options, | ||
| is_dump=mount_entry.is_dump, | ||
| pass_num=mount_entry.pass_num, | ||
| _target=self.target, | ||
| ) |
This file contains hidden or 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
Git LFS file not shown
This file contains hidden or 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
Empty file.
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.
I meant more something like this:
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.
I wanted to do it but below it will sum up into 5 tabs Don't you think it will be too much tabs?
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.
It's fine. We have a 120 width line limit. Plenty of space :)