Skip to content

Commit

Permalink
Fix edge case where unix history path is a directory (#727)
Browse files Browse the repository at this point in the history
  • Loading branch information
JSCU-CNI authored Jun 27, 2024
1 parent c1e384f commit ec9391f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion dissect/target/plugins/os/unix/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def _find_history_files(self) -> List[Tuple[str, TargetPath, UnixUserRecord]]:
for user_details in self.target.user_details.all_with_home():
for shell, history_relative_path in self.COMMAND_HISTORY_RELATIVE_PATHS:
history_path = user_details.home_path.joinpath(history_relative_path)
if history_path.exists():
if history_path.is_file():
history_files.append((shell, history_path, user_details.user))
return history_files

Expand Down
21 changes: 21 additions & 0 deletions tests/plugins/os/unix/test_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from dissect.util.ts import from_unix
from flow.record.fieldtypes import datetime as dt

from dissect.target import Target
from dissect.target.filesystem import VirtualFilesystem
from dissect.target.plugins.os.unix.history import CommandHistoryPlugin


Expand Down Expand Up @@ -214,3 +216,22 @@ def test_commandhistory_database_history(target_unix_users, fs_unix, db_type, db
assert results[i].command == line
assert results[i].shell == db_type
assert results[i].source.as_posix() == f"/root/{db_file}"


def test_commandhistory_is_directory(target_unix_users: Target, fs_unix: VirtualFilesystem) -> None:
commandhistory_data = """test"""

fs_unix.map_file_fh(
"/root/.zsh_history",
BytesIO(textwrap.dedent(commandhistory_data).encode()),
)

fs_unix.makedirs("/root/.bash_history")
results = list(target_unix_users.commandhistory())

assert len(results) == 1

assert results[0].ts is None
assert results[0].command == "test"
assert results[0].shell == "zsh"
assert results[0].source.as_posix() == "/root/.zsh_history"

0 comments on commit ec9391f

Please sign in to comment.