Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split runkey path as command components #688

Merged
merged 3 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion dissect/target/helpers/record_modifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,16 @@ def _hash_path_records(field_name: str, resolved_path: TargetPath) -> Record:

def _resolve_path_types(target: Target, record: Record) -> Iterator[tuple[str, TargetPath]]:
for field_name, field_type in record._field_types.items():
if not issubclass(field_type, fieldtypes.path):
if not issubclass(field_type, (fieldtypes.path, fieldtypes.command)):
continue

path = getattr(record, field_name, None)
if path is None:
continue

if isinstance(path, fieldtypes.command):
path = path.executable

yield field_name, target.resolve(str(path))


Expand Down
10 changes: 6 additions & 4 deletions dissect/target/plugins/os/windows/regf/runkeys.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Iterator

from dissect.target.exceptions import UnsupportedPluginError
from dissect.target.helpers.descriptor_extensions import (
RegistryRecordDescriptorExtension,
Expand All @@ -11,7 +13,7 @@
[
("datetime", "ts"),
("wstring", "name"),
("string", "path"),
("command", "command"),
("string", "key"),
],
)
Expand Down Expand Up @@ -48,7 +50,7 @@ def check_compatible(self) -> None:
raise UnsupportedPluginError("No registry run key found")

@export(record=RunKeyRecord)
def runkeys(self):
def runkeys(self) -> Iterator[RunKeyRecord]:
"""Iterate various run key locations. See source for all locations.

Run keys (Run and RunOnce) are registry keys that make a program run when a user logs on. a Run key runs every
Expand All @@ -63,7 +65,7 @@ def runkeys(self):
domain (string): The target domain.
ts (datetime): The registry key last modified timestamp.
name (string): The run key name.
path (string): The run key path.
command (command): The run key command.
key (string): The source key for this run key.
"""
for key in self.KEYS:
Expand All @@ -73,7 +75,7 @@ def runkeys(self):
yield RunKeyRecord(
ts=r.ts,
name=entry.name,
path=entry.value,
command=entry.value,
key=key,
_target=self.target,
_key=r,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ dependencies = [
"dissect.regf>=3.3.dev,<4.0.dev",
"dissect.util>=3.0.dev,<4.0.dev",
"dissect.volume>=3.0.dev,<4.0.dev",
"flow.record~=3.14.0",
"flow.record~=3.15.0",
"structlog",
]
dynamic = ["version"]
Expand Down
3 changes: 2 additions & 1 deletion tests/helpers/test_modifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import pytest
from flow.record import Record
from flow.record.fieldtypes import digest, path
from flow.record.fieldtypes import command, digest, path

from dissect.target import Target
from dissect.target.exceptions import FileNotFoundError, IsADirectoryError
Expand Down Expand Up @@ -32,6 +32,7 @@ def resolve_function() -> ModifierFunc:
({"name": path}, 2),
({"name": path, "test": path}, 3),
({"name": path, "test": str}, 2),
({"name": command}, 2),
],
)
@patch("flow.record.Record")
Expand Down