88
99from dissect .target .exceptions import UnsupportedPluginError
1010from dissect .target .helpers .record import DynamicDescriptor , TargetRecordDescriptor
11- from dissect .target .plugin import Plugin , export
11+ from dissect .target .plugin import Plugin , arg , export
1212
1313if TYPE_CHECKING :
1414 from collections .abc import Iterator
2222
2323
2424class VelociraptorRecordBuilder :
25- def __init__ (self , artifact_name : str ):
25+ def __init__ (self , artifact_name : str , extract_nested : bool ):
2626 self ._create_event_descriptor = lru_cache (4096 )(self ._create_event_descriptor )
2727 self .record_name = f"velociraptor/{ artifact_name } "
28+ self .extract_nested = extract_nested
2829
2930 def build (self , object : dict , target : Target ) -> TargetRecordDescriptor :
3031 """Builds a Velociraptor record."""
@@ -52,8 +53,12 @@ def build(self, object: dict, target: Target) -> TargetRecordDescriptor:
5253 elif isinstance (value , str ):
5354 record_type = "string"
5455 elif isinstance (value , dict ):
55- record_type = "record"
56- value = self .build (value , target )
56+ if self .extract_nested :
57+ record_type = "record"
58+ value = self .build (value , target )
59+ else :
60+ # Skip nested objects that contain additional metadata
61+ continue
5762 else :
5863 record_type = "dynamic"
5964
@@ -82,9 +87,20 @@ def check_compatible(self) -> None:
8287 raise UnsupportedPluginError ("No Velociraptor artifacts found" )
8388
8489 @export (record = DynamicDescriptor (["datetime" ]))
85- def results (self ) -> Iterator [Record ]:
90+ @arg (
91+ "--extract-nested" ,
92+ action = "store_true" ,
93+ help = "extracts JSON objects from the artifacts" ,
94+ )
95+ def results (
96+ self ,
97+ extract_nested : bool = False ,
98+ ) -> Iterator [Record ]:
8699 """Return Rapid7 Velociraptor artifacts.
87100
101+ By default JSON objects are not extracted from the artifacts,
102+ this can be done with the argument ``--extract-nested``.
103+
88104 References:
89105 - https://docs.velociraptor.app/docs/vql/artifacts/
90106 """
@@ -93,7 +109,7 @@ def results(self) -> Iterator[Record]:
93109 artifact_name = (
94110 urllib .parse .unquote (artifact .name .removesuffix (".json" )).split ("/" )[0 ].lower ().replace ("." , "_" )
95111 )
96- record_builder = VelociraptorRecordBuilder (artifact_name )
112+ record_builder = VelociraptorRecordBuilder (artifact_name , extract_nested = extract_nested )
97113
98114 for line in artifact .open ("rt" ):
99115 if not (line := line .strip ()):
0 commit comments