Skip to content

Commit 03fbaeb

Browse files
Change log path to /var/run/log to match modification made in fox-it#1509
1 parent bcd8648 commit 03fbaeb

File tree

4 files changed

+26
-34
lines changed

4 files changed

+26
-34
lines changed

dissect/target/plugins/os/unix/esxi/esxi_log/__init__.py

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -54,23 +54,15 @@ def get_esxi_log_path(target: Target, logname: str) -> Iterator[Path]:
5454
- https://knowledge.broadcom.com/external/article/306962/location-of-esxi-log-files.html
5555
:return:
5656
"""
57-
# Depending on collection method, log are not always located at the same location
58-
# In tech support logs are in /var/run/log
59-
# In live collection in /scratch/log
60-
# On live disk, symlink must have be made from os data
61-
# We stop to the first existing folder with files to prevent duplicate
62-
# /var/log usually contains only uncompressed log file, thus this entry is the last one checked
63-
files_found = False
64-
for log_location in ["/scratch/log", "/var/run/log", "/var/log"]:
65-
if target.fs.path(log_location).exists():
66-
for path in target.fs.path(log_location).glob(f"{logname}.*"):
67-
try:
68-
yield path.resolve(strict=True)
69-
files_found = True
70-
except FilesystemError as e: # noqa PERF203
71-
target.info.warning("Fail to resolve path to %s : %s", path, str(e))
72-
if files_found:
73-
break
57+
# Esxi/loaders should ensure that logs are symlinked to /var/run/log, as on a live ESXi hosts.
58+
if (var_run_log := target.fs.path("/var/run/log")).exists():
59+
print("HERE")
60+
for path in var_run_log.glob(f"{logname}.*"):
61+
try:
62+
yield path.resolve(strict=True)
63+
except FilesystemError as e: # noqa PERF203
64+
target.info.warning("Fail to resolve path to %s : %s", path, str(e))
65+
return
7466

7567

7668
def yield_log_records(

tests/plugins/os/unix/esxi/esxi_log/test_auth.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
def test_esxi_6_log_auth(target_esxi: Target, fs_esxi: VirtualFilesystem) -> None:
1616
"""Test with log from an ESXi6"""
1717
data_file = absolute_path("_data/plugins/os/unix/esxi/log/esxi6/auth.log.gz")
18-
fs_esxi.map_file("/var/log/auth.log.gz", data_file)
18+
fs_esxi.map_file("/var/run/log/auth.log.gz", data_file)
1919

2020
target_esxi.add_plugin(EsxiAuthPlugin)
2121

@@ -33,13 +33,13 @@ def test_esxi_6_log_auth(target_esxi: Target, fs_esxi: VirtualFilesystem) -> Non
3333
assert results[12].log_level is None
3434
assert results[12].pid == 2099486
3535
assert results[12].message == "Accepted keyboard-interactive/pam for root from 192.168.56.1 port 46932 ssh2"
36-
assert results[12].source == "/var/log/auth.log.gz"
36+
assert results[12].source == "/var/run/log/auth.log.gz"
3737

3838

3939
def test_esxi_7_log_auth(target_esxi: Target, fs_esxi: VirtualFilesystem) -> None:
4040
"""Test with log from an ESXi7"""
4141
data_file = absolute_path("_data/plugins/os/unix/esxi/log/esxi7/auth.log.gz")
42-
fs_esxi.map_file("/scratch/log/auth.log.gz", data_file)
42+
fs_esxi.map_file("/var/run/log/auth.log.gz", data_file)
4343

4444
target_esxi.add_plugin(EsxiAuthPlugin)
4545

@@ -51,7 +51,7 @@ def test_esxi_7_log_auth(target_esxi: Target, fs_esxi: VirtualFilesystem) -> Non
5151
assert results[0].log_level is None
5252
assert results[0].pid == 2102622
5353
assert results[0].message == "FIPS mode initialized"
54-
assert results[0].source == "/scratch/log/auth.log.gz"
54+
assert results[0].source == "/var/run/log/auth.log.gz"
5555

5656
assert results[4].ts == dt("2024-12-06T10:58:46.944Z")
5757
assert results[4].application == "sshd"
@@ -62,7 +62,7 @@ def test_esxi_7_log_auth(target_esxi: Target, fs_esxi: VirtualFilesystem) -> Non
6262
'`"&& mkdir "` echo /var/core/ansible-tmp-1733482726.6630323-32096-231798679827098 `" && '
6363
"echo ansible-tmp-1733482726.6630323-32096-231798679827098=\"'"
6464
)
65-
assert results[4].source == "/scratch/log/auth.log.gz"
65+
assert results[4].source == "/var/run/log/auth.log.gz"
6666

6767

6868
def test_esxi_9_log_auth(target_esxi: Target, fs_esxi: VirtualFilesystem) -> None:
@@ -71,7 +71,7 @@ def test_esxi_9_log_auth(target_esxi: Target, fs_esxi: VirtualFilesystem) -> Non
7171
In ESXi8+, logs seems to be nearly empty/useless
7272
"""
7373
data_file = absolute_path("_data/plugins/os/unix/esxi/log/esxi9/auth.log.gz")
74-
fs_esxi.map_file("/scratch/log/auth.log.gz", data_file)
74+
fs_esxi.map_file("/var/run/log/auth.log.gz", data_file)
7575

7676
target_esxi.add_plugin(EsxiAuthPlugin)
7777

@@ -83,4 +83,4 @@ def test_esxi_9_log_auth(target_esxi: Target, fs_esxi: VirtualFilesystem) -> Non
8383
assert results[0].log_level == "In(38)"
8484
assert results[0].pid == 132774
8585
assert results[0].message == "/etc/ssh/sshd_config line 14: Deprecated option fipsmode"
86-
assert results[0].source == "/scratch/log/auth.log.gz"
86+
assert results[0].source == "/var/run/log/auth.log.gz"

tests/plugins/os/unix/esxi/esxi_log/test_hostd.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def test_esxi_6_log_hostd(target_esxi: Target, fs_esxi: VirtualFilesystem) -> No
5757
def test_esxi_7_log_hostd(target_esxi: Target, fs_esxi: VirtualFilesystem) -> None:
5858
"""Test with log from an ESXi 7"""
5959
data_file = absolute_path("_data/plugins/os/unix/esxi/log/esxi7/hostd.0.gz")
60-
fs_esxi.map_file("/scratch/log/hostd.0.gz", data_file)
60+
fs_esxi.map_file("/var/run/log/hostd.0.gz", data_file)
6161

6262
target_esxi.add_plugin(HostdPlugin)
6363

@@ -87,7 +87,7 @@ def test_esxi_7_log_hostd(target_esxi: Target, fs_esxi: VirtualFilesystem) -> No
8787
assert results[29].application == "hostd"
8888
assert results[29].log_level == "info"
8989
assert results[29].pid == 2100292
90-
assert results[29].source == "/scratch/log/hostd.0.gz"
90+
assert results[29].source == "/var/run/log/hostd.0.gz"
9191
assert (
9292
results[29].message
9393
== "VmkVprobSource::Post event: (vim.event.EventEx) {\n key = 90,\n chainId = -1,\n createdTime = "
@@ -103,7 +103,7 @@ def test_esxi_7_log_hostd(target_esxi: Target, fs_esxi: VirtualFilesystem) -> No
103103
def test_esxi_8_log_hostd(target_esxi: Target, fs_esxi: VirtualFilesystem) -> None:
104104
"""Test with log from an ESXi 7"""
105105
data_file = absolute_path("_data/plugins/os/unix/esxi/log/esxi8/hostd.1.gz")
106-
fs_esxi.map_file("/var/log/hostd.1.gz", data_file)
106+
fs_esxi.map_file("/var/run/log/hostd.1.gz", data_file)
107107

108108
target_esxi.add_plugin(HostdPlugin)
109109

@@ -132,7 +132,7 @@ def test_esxi_8_log_hostd(target_esxi: Target, fs_esxi: VirtualFilesystem) -> No
132132
def test_esxi_9_log_hostd(target_esxi: Target, fs_esxi: VirtualFilesystem) -> None:
133133
"""Test with log from an ESXi 9"""
134134
data_file = absolute_path("_data/plugins/os/unix/esxi/log/esxi9/hostd.0.gz")
135-
fs_esxi.map_file("/var/log/hostd.0.gz", data_file)
135+
fs_esxi.map_file("/var/run/log/hostd.0.gz", data_file)
136136

137137
target_esxi.add_plugin(HostdPlugin)
138138

@@ -152,7 +152,7 @@ def test_esxi_9_log_hostd(target_esxi: Target, fs_esxi: VirtualFilesystem) -> No
152152
assert results[2377].application == "Hostd"
153153
assert results[2377].log_level == "Er(163)"
154154
assert results[2377].pid == 132123
155-
assert results[2377].source == "/var/log/hostd.0.gz"
155+
assert results[2377].source == "/var/run/log/hostd.0.gz"
156156
assert results[2377].message == (
157157
"Failed to load event type <EventType>\n"
158158
" "

tests/plugins/os/unix/esxi/esxi_log/test_shell_log.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
def test_esxi_6_log_shell(target_esxi: Target, fs_esxi: VirtualFilesystem) -> None:
1616
"""Test with log from an ESXi6"""
1717
data_file = absolute_path("_data/plugins/os/unix/esxi/log/esxi6/shell.log.gz")
18-
fs_esxi.map_file("/var/log/shell.log.gz", data_file)
18+
fs_esxi.map_file("/var/run/log/shell.log.gz", data_file)
1919

2020
target_esxi.add_plugin(ShellLogPlugin)
2121

@@ -35,13 +35,13 @@ def test_esxi_6_log_shell(target_esxi: Target, fs_esxi: VirtualFilesystem) -> No
3535
assert results[13].pid == 2099491
3636
assert results[13].message == "./uac --profile full -f zip ."
3737
assert results[13].user == "root"
38-
assert results[13].source == "/var/log/shell.log.gz"
38+
assert results[13].source == "/var/run/log/shell.log.gz"
3939

4040

4141
def test_esxi_7_log_shell(target_esxi: Target, fs_esxi: VirtualFilesystem) -> None:
4242
"""Test with log from an ESXi6"""
4343
data_file = absolute_path("_data/plugins/os/unix/esxi/log/esxi7/shell.log.gz")
44-
fs_esxi.map_file("/var/log/shell.log.gz", data_file)
44+
fs_esxi.map_file("/var/run/log/shell.log.gz", data_file)
4545

4646
target_esxi.add_plugin(ShellLogPlugin)
4747

@@ -66,7 +66,7 @@ def test_esxi_7_log_shell(target_esxi: Target, fs_esxi: VirtualFilesystem) -> No
6666
def test_esxi_8_log_shell(target_esxi: Target, fs_esxi: VirtualFilesystem) -> None:
6767
"""Test with log from an ESXi6"""
6868
data_file = absolute_path("_data/plugins/os/unix/esxi/log/esxi8/shell.log.gz")
69-
fs_esxi.map_file("/var/log/shell.log.gz", data_file)
69+
fs_esxi.map_file("/var/run/log/shell.log.gz", data_file)
7070

7171
target_esxi.add_plugin(ShellLogPlugin)
7272

@@ -109,7 +109,7 @@ def test_esxi_8_log_shell(target_esxi: Target, fs_esxi: VirtualFilesystem) -> No
109109
def test_esxi_9_log_shell(target_esxi: Target, fs_esxi: VirtualFilesystem) -> None:
110110
"""Test with log from an ESXi6"""
111111
data_file = absolute_path("_data/plugins/os/unix/esxi/log/esxi9/shell.log.gz")
112-
fs_esxi.map_file("/var/log/shell.log.gz", data_file)
112+
fs_esxi.map_file("/var/run/log/shell.log.gz", data_file)
113113

114114
target_esxi.add_plugin(ShellLogPlugin)
115115

0 commit comments

Comments
 (0)