Skip to content

Commit 6e90da6

Browse files
authored
Fix duplicate mounting for virtual NTFS (#1464)
1 parent ab0db26 commit 6e90da6

File tree

4 files changed

+20
-7
lines changed

4 files changed

+20
-7
lines changed

dissect/target/target.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -694,14 +694,22 @@ def _mount_others(self) -> None:
694694
counter = 0
695695
path = "/$fs$/fs0"
696696

697+
fake_ntfs = set()
697698
for fs in self.filesystems:
699+
ntfs_obj = getattr(fs, "ntfs", None)
700+
if ntfs_obj in fake_ntfs:
701+
continue
698702
if fs not in root_fs.mounts.values():
699703
# determine mount point
700704
while root_fs.path(path).exists():
701705
counter += 1
702706
path = f"/$fs$/fs{counter}"
703-
704707
root_fs.mount(path, fs)
708+
if ntfs_obj and fs.__type__ != "ntfs":
709+
# A non ntfs filesystem with a "ntfs" object means that add_virtual_ntfs_filesystem was used.
710+
# We use this ntfs object to identify the "fake" ntfs filesystem.
711+
# This functions due to the fake ntfs object is added to the filesystem after its parent.
712+
fake_ntfs.add(ntfs_obj)
705713

706714
def add_plugin(
707715
self,

tests/loaders/test_kape.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ def test_dir(mock_kape_dir: Path) -> None:
6767

6868
# The 3 found drive letter directories + the fake NTFS filesystem
6969
assert len(t.filesystems) == 4
70-
# The 3 found drive letters + sysvol + the fake NTFS filesystem at /$fs$
71-
assert len(t.fs.mounts) == 5
70+
# The 3 found drive letters + sysvol
71+
assert len(t.fs.mounts) == 4
7272
assert len(list(t.fs.mounts["c:"].ntfs.usnjrnl.records())) == 1
7373

7474

tests/loaders/test_tanium.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,6 @@ def test_loader(mock_tanium_dir: Path) -> None:
6464

6565
# The 3 found drive letter directories + the fake NTFS filesystem
6666
assert len(t.filesystems) == 4
67-
# The 3 found drive letters + sysvol + the fake NTFS filesystem at /$fs$
68-
assert len(t.fs.mounts) == 5
67+
# The 3 found drive letters + sysvol
68+
assert len(t.fs.mounts) == 4
6969
assert len(list(t.fs.mounts["c:"].ntfs.usnjrnl.records())) == 1

tests/test_target.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ def mocked_win_volumes_fs() -> Iterator[tuple[Mock, Mock, Mock]]:
224224
mock_good_volume.drive_letter = "W"
225225

226226
mock_good_fs = Mock(name="good-fs")
227+
mock_good_fs.__type__ = "mock"
227228
mock_good_fs.iter_subfs.return_value = []
228229

229230
def mock_filesystem_open(volume: Mock) -> Mock:
@@ -581,7 +582,9 @@ def test_empty_volume_log(target_bare: Target, caplog: pytest.LogCaptureFixture)
581582
@pytest.mark.parametrize("nr_of_fs", [1, 2])
582583
def test_fs_mount_others(target_unix: Target, nr_of_fs: int) -> None:
583584
for _ in range(nr_of_fs):
584-
target_unix.filesystems.add(Mock())
585+
fs = Mock()
586+
fs.__type__ = "mock"
587+
target_unix.filesystems.add(fs)
585588

586589
target_unix._mount_others()
587590

@@ -595,7 +598,9 @@ def test_fs_mount_others(target_unix: Target, nr_of_fs: int) -> None:
595598
@pytest.mark.parametrize("nr_of_fs", [1, 2])
596599
def test_fs_mount_already_there(target_unix: Target, nr_of_fs: int) -> None:
597600
for idx in range(nr_of_fs):
598-
target_unix.filesystems.add(Mock())
601+
fs = Mock()
602+
fs.__type__ = "mock"
603+
target_unix.filesystems.add(fs)
599604
target_unix._mount_others()
600605

601606
assert f"/$fs$/fs{idx}" in target_unix.fs.mounts

0 commit comments

Comments
 (0)