From 9643cc5b8b94c891fbf4dea9e32bc694c586b598 Mon Sep 17 00:00:00 2001 From: Roel de Jong <12800443+twiggler@users.noreply.github.com> Date: Wed, 25 Jun 2025 13:15:50 +0200 Subject: [PATCH 1/2] Use new api in dissect.target for home paths --- acquire/acquire.py | 53 +--------------------------------------------- 1 file changed, 1 insertion(+), 52 deletions(-) diff --git a/acquire/acquire.py b/acquire/acquire.py index 4ce43a27..a71e1cb6 100644 --- a/acquire/acquire.py +++ b/acquire/acquire.py @@ -101,64 +101,13 @@ logging.lastResort = None logging.raiseExceptions = False - -def misc_windows_user_homes(target: Target) -> Iterator[fsutil.TargetPath]: - misc_dirs = { - ("Windows/ServiceProfiles/LocalService", False), - ("Windows/ServiceProfiles/NetworkService", False), - ("Windows/System32/config/systemprofile", False), - ("Users", True), - ("Documents and Settings", True), - } - - for fs in target.fs.path().iterdir(): - if fs.name.lower() == "c:": - continue - - for misc_dir, get_subdirs in misc_dirs: - misc_path = fs.joinpath(misc_dir) - - if not misc_path.exists(): - continue - - if get_subdirs: - for entry in misc_path.iterdir(): - if entry.is_dir(): - yield entry - else: - yield misc_path - - -def misc_unix_user_homes(target: Target) -> Iterator[fsutil.TargetPath]: - user_dirs = ["root", "home/*"] - - home_dirs = (target.fs.path("/").glob(path) for path in user_dirs) - yield from itertools.chain.from_iterable(home_dirs) - - -def misc_macos_user_homes(target: Target) -> Iterator[fsutil.TargetPath]: - yield from itertools.chain(target.fs.path("/Users/").glob("*"), misc_unix_user_homes(target)) - - -MISC_MAPPING = { - "macos": misc_macos_user_homes, - "windows": misc_windows_user_homes, -} - - def from_user_home(target: Target, path: str) -> Iterator[str]: try: - for user_details in target.user_details.all_with_home(): - yield user_details.home_path.joinpath(path).as_posix() + return (user_home.joinpath(path).as_posix() for user_home in target.user_details.all_home_dirs()) except Exception as e: log.warning("Error occurred when requesting all user homes") log.debug("", exc_info=e) - misc_user_homes = MISC_MAPPING.get(target.os, misc_unix_user_homes) - for user_dir in misc_user_homes(target): - yield user_dir.joinpath(path).as_posix() - - def iter_ntfs_filesystems(target: Target) -> Iterator[tuple[ntfs.NtfsFilesystem, str | None, str, str]]: mount_lookup = defaultdict(list) for mount, fs in target.fs.mounts.items(): From 752f4648bda12583c2fe1fb8df279533737088d4 Mon Sep 17 00:00:00 2001 From: Roel de Jong <12800443+twiggler@users.noreply.github.com> Date: Thu, 26 Jun 2025 13:20:43 +0200 Subject: [PATCH 2/2] Use target misc_homes functionality --- acquire/acquire.py | 4 +++- tests/test_misc_users.py | 51 ---------------------------------------- 2 files changed, 3 insertions(+), 52 deletions(-) delete mode 100644 tests/test_misc_users.py diff --git a/acquire/acquire.py b/acquire/acquire.py index a71e1cb6..626a5e47 100644 --- a/acquire/acquire.py +++ b/acquire/acquire.py @@ -101,13 +101,15 @@ logging.lastResort = None logging.raiseExceptions = False + def from_user_home(target: Target, path: str) -> Iterator[str]: try: - return (user_home.joinpath(path).as_posix() for user_home in target.user_details.all_home_dirs()) + return (user_home.joinpath(path).as_posix() for user_home in target.user_details.all_home_paths) except Exception as e: log.warning("Error occurred when requesting all user homes") log.debug("", exc_info=e) + def iter_ntfs_filesystems(target: Target) -> Iterator[tuple[ntfs.NtfsFilesystem, str | None, str, str]]: mount_lookup = defaultdict(list) for mount, fs in target.fs.mounts.items(): diff --git a/tests/test_misc_users.py b/tests/test_misc_users.py deleted file mode 100644 index 001d2477..00000000 --- a/tests/test_misc_users.py +++ /dev/null @@ -1,51 +0,0 @@ -from __future__ import annotations - -from typing import TYPE_CHECKING - -from acquire.acquire import misc_macos_user_homes, misc_unix_user_homes - -if TYPE_CHECKING: - from dissect.target import Target - from dissect.target.filesystem import VirtualFilesystem - - -def test_misc_osx_user_homes(mock_target: Target, mock_fs: VirtualFilesystem) -> None: - mock_target.os = "osx" - expected_results = [] - for user in ["Foo", "Bar"]: - mock_fs.makedirs(f"/Users/{user}") - mock_fs.map_file_entry(f"/Users/{user}/application", None) - expected_results.append(f"/Users/{user}") - - assert [str(home) for home in misc_macos_user_homes(mock_target)] == expected_results - - -def test_misc_macos_user_homes(mock_target: Target, mock_fs: VirtualFilesystem) -> None: - mock_target.os = "macos" - expected_results = [] - for user in ["Foo", "Bar"]: - mock_fs.makedirs(f"/Users/{user}") - mock_fs.map_file_entry(f"/Users/{user}/application", None) - expected_results.append(f"/Users/{user}") - - assert [str(home) for home in misc_macos_user_homes(mock_target)] == expected_results - - -def test_misc_macos_from_user_home(mock_target: Target, mock_fs: VirtualFilesystem) -> None: - mock_fs.makedirs("/root") - expected_results = ["/root"] - for user in ["Foo", "Bar"]: - mock_fs.makedirs(f"/home/{user}") - expected_results.append(f"/home/{user}") - - assert [str(home) for home in misc_macos_user_homes(mock_target)] == expected_results - - -def test_misc_unix_user_homes(mock_target: Target, mock_fs: VirtualFilesystem) -> None: - mock_fs.makedirs("/root") - expected_results = ["/root"] - for user in ["Foo", "Bar"]: - mock_fs.makedirs(f"/home/{user}") - expected_results.append(f"/home/{user}") - - assert [str(home) for home in misc_unix_user_homes(mock_target)] == expected_results