Skip to content

Commit

Permalink
Split runkey path as command components (#688)
Browse files Browse the repository at this point in the history
* Use command type for runkeys
* Enable --hash for command types
  • Loading branch information
Miauwkeru authored May 3, 2024
1 parent b1bcb0d commit 90fa8ae
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
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

0 comments on commit 90fa8ae

Please sign in to comment.