Skip to content

Commit 2dfc393

Browse files
authored
Fix an issue where the ESXiPlugin shows a confusing warning when constructing the local fs (#1332)
The following warning was logged every time that the local_tgz tar file was successfully decrypted > "local.tgz is encrypted but static decryption failed and no dynamic decryption available!" Now this warning is moved so it only shows when it isn't run on a local target.
1 parent cb26a4e commit 2dfc393

File tree

3 files changed

+45
-12
lines changed

3 files changed

+45
-12
lines changed

dissect/target/plugins/os/unix/esxi/_os.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -287,20 +287,22 @@ def _create_local_fs(target: Target, local_tgz_ve: TargetPath, encryption_info:
287287
else:
288288
target.log.debug("Skipping static decryption because of missing crypto module")
289289

290-
if not local_tgz and target.name == "local":
290+
if local_tgz is None:
291+
if target.name != "local":
292+
target.log.warning(
293+
"local.tgz is encrypted but static decryption failed and no dynamic decryption available!"
294+
)
295+
return None
296+
291297
target.log.info(
292298
"local.tgz is encrypted but static decryption failed, attempting dynamic decryption using crypto-util"
293299
)
294300
local_tgz = _decrypt_crypto_util(local_tgz_ve)
295301

296302
if local_tgz is None:
297303
target.log.warning("Dynamic decryption of %s failed", local_tgz_ve)
298-
else:
299-
target.log.warning("local.tgz is encrypted but static decryption failed and no dynamic decryption available!")
300304

301-
if local_tgz:
302-
return tar.TarFilesystem(local_tgz)
303-
return None
305+
return tar.TarFilesystem(local_tgz) if local_tgz else None
304306

305307

306308
def _mount_filesystems(target: Target, sysvol: Filesystem, cfg: dict[str, str]) -> None:

tests/plugins/os/unix/esxi/test__os.py

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import logging
34
from io import BytesIO
45
from typing import TYPE_CHECKING
56
from unittest.mock import patch
@@ -10,35 +11,54 @@
1011
from tests._utils import absolute_path
1112

1213
if TYPE_CHECKING:
14+
import pytest
15+
1316
from dissect.target.target import Target
1417

1518

16-
def test__create_tar_fs_no_envelope(target_linux: Target, fs_unix: VirtualFilesystem) -> None:
19+
def test__create_local_fs_local_no_envelope(
20+
target_linux: Target, fs_unix: VirtualFilesystem, caplog: pytest.LogCaptureFixture
21+
) -> None:
1722
with (
1823
patch("dissect.target.plugins.os.unix.esxi._os.HAS_ENVELOPE", False),
1924
patch("dissect.target.plugins.os.unix.esxi._os.tar") as mocked_tar,
2025
patch("dissect.target.plugins.os.unix.esxi._os._decrypt_crypto_util") as decrypt_func,
26+
caplog.at_level(logging.DEBUG),
2127
):
2228
target_linux._name = "local"
2329
_create_local_fs(target_linux, fs_unix.path("local.tgz.ve"), fs_unix.path("encryption.info"))
2430

31+
assert len(caplog.messages) == 2
32+
assert "Skipping static decryption because of missing crypto module" in caplog.messages[0]
33+
assert (
34+
"local.tgz is encrypted but static decryption failed, attempting dynamic decryption using crypto-util"
35+
in caplog.messages[1]
36+
)
37+
2538
decrypt_func.assert_called()
2639
mocked_tar.TarFilesystem.assert_called()
2740

2841

29-
def test__create_tar_fs_envelope(target_linux: Target, fs_unix: VirtualFilesystem) -> None:
42+
def test__create_local_fs_envelope(
43+
target_linux: Target, fs_unix: VirtualFilesystem, caplog: pytest.LogCaptureFixture
44+
) -> None:
3045
with (
3146
patch("dissect.target.plugins.os.unix.esxi._os.HAS_ENVELOPE", True),
3247
patch("dissect.target.plugins.os.unix.esxi._os.tar") as mocked_tar,
3348
patch("dissect.target.plugins.os.unix.esxi._os._decrypt_envelope") as decrypt_func,
49+
caplog.at_level(logging.WARNING, target_linux.log.name),
3450
):
3551
_create_local_fs(target_linux, fs_unix.path("local.tgz.ve"), fs_unix.path("encryption.info"))
3652

53+
assert (
54+
"local.tgz is encrypted but static decryption failed and no dynamic decryption available!"
55+
not in caplog.text
56+
)
3757
decrypt_func.assert_called()
3858
mocked_tar.TarFilesystem.assert_called()
3959

4060

41-
def test__create_tar_fs_failed_envelope(target_linux: Target, fs_unix: VirtualFilesystem) -> None:
61+
def test__create_local_fs_failed_envelope(target_linux: Target, fs_unix: VirtualFilesystem) -> None:
4262
with (
4363
patch("dissect.target.plugins.os.unix.esxi._os.HAS_ENVELOPE", True),
4464
patch("dissect.target.plugins.os.unix.esxi._os.tar") as mocked_tar,
@@ -52,13 +72,19 @@ def test__create_tar_fs_failed_envelope(target_linux: Target, fs_unix: VirtualFi
5272
mocked_tar.TarFilesystem.assert_called()
5373

5474

55-
def test__decrypt_crypto_not_local(target_linux: Target, fs_unix: VirtualFilesystem) -> None:
75+
def test__create_local_fs_non_local_target(
76+
target_linux: Target, fs_unix: VirtualFilesystem, caplog: pytest.LogCaptureFixture
77+
) -> None:
5678
target_linux._name = "not_local"
57-
with patch("dissect.target.plugins.os.unix.esxi._os.HAS_ENVELOPE", False):
79+
with (
80+
patch("dissect.target.plugins.os.unix.esxi._os.HAS_ENVELOPE", False),
81+
caplog.at_level(logging.WARNING, target_linux.log.name),
82+
):
5883
assert _create_local_fs(target_linux, fs_unix.path(""), fs_unix.path("")) is None
84+
assert "local.tgz is encrypted but static decryption failed and no dynamic decryption available!" in caplog.text
5985

6086

61-
def test__decrypt_crypto_local(fs_unix: VirtualFilesystem) -> None:
87+
def test__decrypt_crypto_util(fs_unix: VirtualFilesystem) -> None:
6288
with patch("dissect.target.plugins.os.unix.esxi._os.subprocess.run") as mocked_run:
6389
mocked_run.return_value.stdout = b"data"
6490

tests/plugins/os/unix/test_ips.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from dissect.target.plugins.os.unix.linux._os import LinuxPlugin
1111
from dissect.target.plugins.os.unix.linux.network_managers import NetworkManager
1212
from dissect.target.tools.query import main as target_query
13+
from dissect.target.tools.utils.logging import configure_logging
1314
from tests._utils import absolute_path
1415

1516
if TYPE_CHECKING:
@@ -94,8 +95,12 @@ def test_ips_dhcp_arg(
9495
if flag:
9596
argv.append(flag)
9697

98+
def noop(*args, **kwargs) -> None:
99+
pass
100+
97101
with patch("dissect.target.Target.open_all", return_value=[target_unix]), monkeypatch.context() as m:
98102
m.setattr("sys.argv", argv)
103+
m.setattr(configure_logging, "__code__", noop.__code__)
99104
target_query()
100105
out, _ = capsys.readouterr()
101106
assert expected_out in out

0 commit comments

Comments
 (0)