-
Notifications
You must be signed in to change notification settings - Fork 44
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
Add Parallels child detection #855
Open
JSCU-CNI
wants to merge
2
commits into
fox-it:main
Choose a base branch
from
JSCU-CNI:feature/add-parallels-desktop-child-detection
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
2 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 | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,67 @@ | ||||||
from typing import Iterator | ||||||
|
||||||
from dissect.target.exceptions import UnsupportedPluginError | ||||||
from dissect.target.helpers.fsutil import TargetPath | ||||||
from dissect.target.helpers.record import ChildTargetRecord | ||||||
from dissect.target.plugin import ChildTargetPlugin | ||||||
from dissect.target.target import Target | ||||||
|
||||||
PARALLELS_USER_PATHS = [ | ||||||
"Parallels", | ||||||
"Documents/Parallels", | ||||||
"Library/Group Containers/*.com.parallels.desktop.appstore/Shared/Parallels", | ||||||
] | ||||||
|
||||||
PARALLELS_SYSTEM_PATHS = [ | ||||||
"/Users/Shared/Parallels", | ||||||
] | ||||||
|
||||||
|
||||||
def find_pvms(target: Target) -> Iterator[TargetPath]: | ||||||
"""Finds virtual machines located in default folders on a macOS target. | ||||||
|
||||||
Resources: | ||||||
- https://kb.parallels.com/117333 | ||||||
""" | ||||||
for user_details in target.user_details.all_with_home(): | ||||||
for parallels_path in PARALLELS_SYSTEM_PATHS: | ||||||
if (path := target.fs.path(parallels_path)).exists(): | ||||||
yield from iter_vms(path) | ||||||
|
||||||
for parallels_path in PARALLELS_USER_PATHS: | ||||||
if "*" in parallels_path: | ||||||
start_path, pattern = parallels_path.split("*", 1) | ||||||
for path in user_details.home_path.joinpath(start_path).rglob("*" + pattern): | ||||||
yield from iter_vms(path) | ||||||
else: | ||||||
if (path := user_details.home_path.joinpath(parallels_path)).exists(): | ||||||
yield from iter_vms(path) | ||||||
|
||||||
|
||||||
def iter_vms(path: TargetPath) -> Iterator[TargetPath]: | ||||||
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.
Suggested change
|
||||||
"""Glob for .pvm folders in the provided folder.""" | ||||||
for file in path.rglob("*.pvm"): | ||||||
if file.is_dir(): | ||||||
yield file | ||||||
|
||||||
|
||||||
class ParallelsChildTargetPlugin(ChildTargetPlugin): | ||||||
"""Child target plugin that yields Parallels Desktop VM files.""" | ||||||
|
||||||
__type__ = "parallels" | ||||||
|
||||||
def __init__(self, target: Target): | ||||||
super().__init__(target) | ||||||
self.pvms = list(find_pvms(target)) | ||||||
|
||||||
def check_compatible(self) -> None: | ||||||
if not self.pvms: | ||||||
raise UnsupportedPluginError("No Parallels pvm file(s) found") | ||||||
|
||||||
def list_children(self): | ||||||
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.
Suggested change
|
||||||
for pvm in self.pvms: | ||||||
yield ChildTargetRecord( | ||||||
type=self.__type__, | ||||||
path=pvm, | ||||||
_target=self.target, | ||||||
) |
Git LFS file not shown
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,25 @@ | ||
from dissect.target.filesystem import VirtualFilesystem | ||
from dissect.target.plugins.child.parallels import ParallelsChildTargetPlugin | ||
from dissect.target.target import Target | ||
|
||
|
||
def test_parallels_child_detection(target_osx_users: Target, fs_osx: VirtualFilesystem) -> None: | ||
"""test if we correctly find Parallels child VMs on MacOS targets.""" | ||
|
||
fs_osx.makedirs("/Users/dissect/Parallels/Windows 11.pvm") | ||
fs_osx.makedirs("/Users/dissect/Documents/Parallels/Windows 10.pvm") | ||
fs_osx.makedirs( | ||
"/Users/dissect/Library/Group Containers/someversionnumber.com.parallels.desktop.appstore/Shared/Parallels/Windows 8.pvm" | ||
) | ||
fs_osx.makedirs("/Users/Shared/Parallels/Windows 7.pvm") | ||
|
||
target_osx_users.add_plugin(ParallelsChildTargetPlugin) | ||
children = list(target_osx_users.list_children()) | ||
|
||
assert len(children) == 4 | ||
assert [c.path for c in children] == [ | ||
"/Users/Shared/Parallels/Windows 7.pvm", | ||
"/Users/dissect/Parallels/Windows 11.pvm", | ||
"/Users/dissect/Documents/Parallels/Windows 10.pvm", | ||
"/Users/dissect/Library/Group Containers/someversionnumber.com.parallels.desktop.appstore/Shared/Parallels/Windows 8.pvm", | ||
] |
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
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.