dissect.target.plugin¶
Dissect plugin system.
See dissect/target/plugins/general/example.py for an example plugin.
Module Contents¶
Classes¶
Sortable and serializible string-based enum. |
|
Base class for plugins. |
|
Base class for OS plugins. |
|
A Child target is a special plugin that can list more Targets. |
|
A namespace plugin provides services to access functionality from a group of subplugins. |
|
Parent class for internal plugins. |
|
A namespace plugin provides services to access functionality from a group of subplugins. |
Functions¶
Decorator to be used on Plugin functions that should be exported. |
|
Decorator to be used on plugin functions that should be internal only. |
|
Decorator to be used on Plugin functions that accept additional command line arguments. |
|
Decorator to be used on |
|
Clone the given attribute to an alias in the provided class. |
|
Register a plugin, and put related data inside |
|
Walk the plugin registry and return plugin descriptors. |
|
Retrieve all OS plugin descriptors. |
|
Retrieve all child plugin descriptors. |
|
Retrieve all function descriptors. |
|
Lookup a function descriptor by function name. |
|
Helper function that loads a plugin from a given function or plugin descriptor. |
|
Check if a plugin descriptor is compatible with the target OS. |
|
Return all plugins that failed to load. |
|
Finds exported plugin functions that match the target and the patterns. |
|
Find functions that yield records with a specific field type. |
|
Internal function to generate the list of available plugins. |
|
Load a module from |
|
Loads a module from a file indicated by |
|
Iterate over the |
|
Return a list of external plugin directories. |
|
Return additional plugin directories specified by the |
Attributes¶
The base module path to the in-tree plugins. |
|
The different output types supported by |
|
The plugin registry. |
|
- dissect.target.plugin.log¶
- dissect.target.plugin.MODULE_PATH = 'dissect.target.plugins'¶
The base module path to the in-tree plugins.
- dissect.target.plugin.OS_MODULE_PATH = 'dissect.target.plugins.os'¶
- dissect.target.plugin.OUTPUTS = ('default', 'record', 'yield', 'none')¶
The different output types supported by
@export.
- class dissect.target.plugin.OperatingSystem¶
Bases:
dissect.target.helpers.utils.StrEnumSortable and serializible string-based enum.
- ANDROID = 'android'¶
- BSD = 'bsd'¶
- CITRIX = 'citrix-netscaler'¶
- ESXI = 'esxi'¶
- FORTIOS = 'fortios'¶
- IOS = 'ios'¶
- LINUX = 'linux'¶
- MACOS = 'macos'¶
- OSX = 'osx'¶
- PROXMOX = 'proxmox'¶
- UNIX = 'unix'¶
- VYOS = 'vyos'¶
- WINDOWS = 'windows'¶
- class dissect.target.plugin.PluginDescriptor¶
- module: str¶
- qualname: str¶
- namespace: str¶
- path: str¶
- findable: bool¶
- functions: list[str]¶
- exports: list[str]¶
- class dissect.target.plugin.FunctionDescriptor¶
- name: str¶
- namespace: str¶
- path: str¶
- exported: bool¶
- internal: bool¶
- findable: bool¶
- alias: bool¶
- output: str¶
- method_name: str¶
- module: str¶
- qualname: str¶
- property func: collections.abc.Callable[Ellipsis, Any]¶
- property record: flow.record.RecordDescriptor | list[flow.record.RecordDescriptor] | None¶
- property args: list[tuple[list[str], dict[str, Any]]]¶
- class dissect.target.plugin.PluginDescriptorLookup¶
- __regular__: dict[str, PluginDescriptor]¶
- __os__: dict[str, PluginDescriptor]¶
- __child__: dict[str, PluginDescriptor]¶
- class dissect.target.plugin.FunctionDescriptorLookup¶
- __regular__: dict[str, dict[str, FunctionDescriptor]]¶
- __os__: dict[str, dict[str, FunctionDescriptor]]¶
- __child__: dict[str, dict[str, FunctionDescriptor]]¶
- class dissect.target.plugin.PluginRegistry¶
- __plugins__: PluginDescriptorLookup¶
- __functions__: FunctionDescriptorLookup¶
- __ostree__: _OSTree¶
- __failed__: list[FailureDescriptor] = []¶
- dissect.target.plugin.PLUGINS: PluginRegistry¶
The plugin registry.
Note: It’s very important that all values in this dictionary are serializable. The plugin registry can be stored in a file and loaded later. Plain Python syntax is used to store the registry. An exception is made for
FailureDescriptor,FunctionDescriptorandPluginDescriptor.
- dissect.target.plugin.GENERATED = False¶
- dissect.target.plugin.export(*args, **kwargs) collections.abc.Callable[Ellipsis, Any]¶
Decorator to be used on Plugin functions that should be exported.
- Supported keyword arguments:
- property (bool): Whether this export should be regarded as a property.
Properties are implicitly cached.
cache (bool): Whether the result of this function should be cached.
- record (RecordDescriptor): The
flow.record.RecordDescriptorfor the records that this function yields. If multiple record types are yielded, specificy each descriptor in a list or tuple. If the records are dynamically made, use
dissect.target.helpers.record.DynamicDescriptor()instead.
output (str): The output type of this function. Must be one of: - default: Single return value - record: Yields records. Implicit when record argument is given. - yield: Yields printable values. - none: No return value. Plugin is responsible for output formatting and should return
None.
The
exportdecorator adds some additional private attributes to an exported method or property: -__output__: The output type to expect for this function, this is the same asoutput. -__record__: The type of record to expect, this value is the same asrecord. -__exported__: set toTrueto indicate the method or property is exported.- Raises:
ValueError – if there was an invalid output type.
- Returns:
An exported function from a plugin.
- dissect.target.plugin.internal(*args, **kwargs) collections.abc.Callable[Ellipsis, Any]¶
Decorator to be used on plugin functions that should be internal only.
Making a plugin internal means that it’s only callable from the Python API and not through
target-query.This decorator adds the
__internal__private attribute to a method or property. The attribute is always set toTrue, to tellregister()that it is an internal method or property.
- dissect.target.plugin.arg(*args, **kwargs) collections.abc.Callable[Ellipsis, Any]¶
Decorator to be used on Plugin functions that accept additional command line arguments.
Command line arguments can be added using the
@argdecorator. Arguments to this decorator are directly forwarded to theArgumentParser.add_argumentfunction ofargparse. Resulting arguments are passed to the function using kwargs. The keyword argument name must match the argparse argument name.This decorator adds the
__args__private attribute to a method or property. This attribute holds all the command line arguments that were added to the plugin function.
- dissect.target.plugin.alias(*args, **kwargs: dict[str, Any]) collections.abc.Callable[Ellipsis, Any]¶
Decorator to be used on
Pluginfunctions to register an alias of that function.
- dissect.target.plugin.clone_alias(cls: type, attr: collections.abc.Callable[Ellipsis, Any], alias: str) None¶
Clone the given attribute to an alias in the provided class.
- class dissect.target.plugin.Plugin(target: dissect.target.target.Target)¶
Base class for plugins.
Plugins can optionally be namespaced by specifying the
__namespace__class attribute. Namespacing results in your plugin needing to be prefixed with this namespace when being called. For example, if your plugin has specifiedtestas namespace and a function calledexample, you must call your plugin withtest.example.A
Pluginclass has the following private class attributes:__namespace____record_descriptors__
With the following two being assigned in
register():__functions____exports__
Additionally, the methods and attributes of
Pluginreceive more private attributes by using decorators.The
export()decorator adds the following private attributes__exported____output__: Set with theexport()decorator.__record__: Set with theexport()decorator.
The
internal()decorator andInternalPluginset the__internal__attribute. Finally.args()decorator sets the__args__attribute.The
alias()decorator populates the__aliases__private attribute ofPluginmethods. Resulting clones of thePluginare populated with the boolean__alias__attribute set toTrue.- Parameters:
target – The
Targetobject to load the plugin for.
- __namespace__: str = None¶
Defines the plugin namespace.
- __record_descriptors__: list[flow.record.RecordDescriptor] = None¶
Defines a list of
RecordDescriptorof the exported plugin functions.
- __register__: bool = True¶
Determines whether this plugin will be registered.
- __findable__: bool = True¶
Determines whether this plugin will be revealed when using search patterns.
Some (meta)-plugins are not very suitable for wild cards on CLI or plugin searches, because they will produce duplicate records or results. For instance a plugin that offers the same functions as subplugins will produce redundant results when used with a wild card (browser.* -> browser.history + browser.*.history).
- __functions__: list[str]¶
Internal. A list of all method names decorated with
@internalor@export.
- __exports__: list[str]¶
Internal. A list of all method names decorated with
@export.
- classmethod __init_subclass__(**kwargs)¶
- target¶
- __getattr__(name: str, /) Any¶
- is_compatible() bool¶
Perform a compatibility check with the target.
- abstract check_compatible() None¶
Perform a compatibility check with the target.
This function should return
Noneif the plugin is compatible with the current target (self.target). For example, check if a certain file exists. Otherwise it should raise anUnsupportedPluginError.- Raises:
UnsupportedPluginError – If the plugin could not be loaded.
- __call__(*args, **kwargs) collections.abc.Iterator[flow.record.Record | Any]¶
Return the records of all exported methods.
- Raises:
PluginError – If the subclass is not a namespace plugin.
- get_paths() collections.abc.Iterator[pathlib.Path]¶
- dissect.target.plugin.register(plugincls: type[Plugin]) None¶
Register a plugin, and put related data inside
PLUGINS.- This function uses the following private attributes that are set using decorators:
__exported__: Set inexport().__internal__: Set ininternal().
- Additionally,
registersets the following private attributes on the plugincls: __functions__: A list of all the methods and properties that are__internal__or__exported__.__exports__: A list of all the methods or properties that were explicitly exported.
If a plugincls
__register__attribute is set toFalse, the plugin will not be registered, but the plugin will still be processed for the private attributes mentioned above.- Parameters:
plugincls – A plugin class to register.
- Raises:
ValueError – If
pluginclsis not a subclass ofPlugin.
- dissect.target.plugin.plugins(osfilter: type[OSPlugin] | None = None, *, index: str = '__regular__') collections.abc.Iterator[PluginDescriptor]¶
Walk the plugin registry and return plugin descriptors.
If
osfilteris specified, only plugins related to the provided OSPlugin, or plugins with no OS relation are returned. IfosfilterisNone, all plugins will be returned.One exception to this is if the
osfilteris a (sub-)class ofDefaultOSPlugin, then plugins are returned as if noosfilterwas specified.The
indexparameter can be used to specify the index to return plugins from. By default, this is set to return regular plugins. Other possible values are__os__and__child__. These returnOSPluginandChildTargetPluginrespectively.- Parameters:
osfilter – The optional
OSPluginto filter the returned plugins on.index – The plugin index to return plugins from. Defaults to regular plugins.
- Yields:
Plugin descriptors in the plugin registry based on the given filter criteria.
- dissect.target.plugin.os_plugins() collections.abc.Iterator[PluginDescriptor]¶
Retrieve all OS plugin descriptors.
- dissect.target.plugin.child_plugins() collections.abc.Iterator[PluginDescriptor]¶
Retrieve all child plugin descriptors.
- dissect.target.plugin.functions(osfilter: type[OSPlugin] | None = None, *, index: str = '__regular__') collections.abc.Iterator[FunctionDescriptor]¶
Retrieve all function descriptors.
- Parameters:
osfilter – The optional
OSPluginto filter the returned functions on.index – The plugin index to return functions from. Defaults to regular functions.
- Yields:
Function descriptors in the plugin registry based on the given filter criteria.
- dissect.target.plugin.lookup(function_name: str, osfilter: type[OSPlugin] | None = None, *, index: str = '__regular__') collections.abc.Iterator[FunctionDescriptor]¶
Lookup a function descriptor by function name.
- Parameters:
func_name – Function name to lookup.
osfilter – The optional
OSPluginto filter results with for compatibility.index – The plugin index to return plugins from. Defaults to regular functions.
- Yields:
Function descriptors that match the given function name and filter criteria.
- dissect.target.plugin.load(desc: FunctionDescriptor | PluginDescriptor) type[Plugin]¶
Helper function that loads a plugin from a given function or plugin descriptor.
- Parameters:
desc – Function descriptor as returned by
plugin.lookup()or plugin descriptor as returned byplugin.plugins().- Returns:
The plugin class.
- Raises:
PluginError – Raised when any other exception occurs while trying to load the plugin.
- dissect.target.plugin.os_match(target: dissect.target.target.Target, descriptor: PluginDescriptor) bool¶
Check if a plugin descriptor is compatible with the target OS.
- Parameters:
target – The target to check compatibility with.
descriptor – The plugin descriptor to check compatibility for.
- dissect.target.plugin.failed() list[FailureDescriptor]¶
Return all plugins that failed to load.
- dissect.target.plugin.find_functions(patterns: str, target: dissect.target.target.Target | None = None, compatibility: bool = False, ignore_load_errors: bool = False, show_hidden: bool = False) tuple[list[FunctionDescriptor], set[str]]¶
Finds exported plugin functions that match the target and the patterns.
Given a target, a comma separated list of patterns and an optional compatibility flag, this function finds matching plugins, optionally checking compatibility.
- Returns:
A tuple containing a list of matching function descriptors and a set of invalid patterns.
- dissect.target.plugin.find_functions_by_record_field_type(field_types: str | list[str], target: dissect.target.target.Target | None = None, compatibility: bool = False, ignore_load_errors: bool = False) collections.abc.Iterator[FunctionDescriptor]¶
Find functions that yield records with a specific field type.
- Parameters:
field_types – The field type to search for.
target – The target to check compatibility with.
compatibility – Whether to check compatibility with the target.
ignore_load_errors – Whether to ignore load errors.
- dissect.target.plugin.generate() dict[str, Any]¶
Internal function to generate the list of available plugins.
Walks the plugins directory and imports any
.pyfiles in there. Plugins will be automatically registered.- Returns:
The global
PLUGINSdictionary.
- dissect.target.plugin.load_module_from_name(module_path: str) None¶
Load a module from
module_path.
- dissect.target.plugin.load_module_from_file(path: pathlib.Path, base_path: pathlib.Path) None¶
Loads a module from a file indicated by
pathrelative tobase_path.The module is added to
sys.modulesso it can be found everywhere.- Parameters:
path – The file to load as module.
base_path – The base directory of the module.
- dissect.target.plugin.load_modules_from_paths(paths: list[pathlib.Path]) None¶
Iterate over the
pathsand load all.pyfiles.
- dissect.target.plugin.get_external_module_paths(path_list: list[pathlib.Path]) list[pathlib.Path]¶
Return a list of external plugin directories.
- dissect.target.plugin.environment_variable_paths() list[pathlib.Path]¶
Return additional plugin directories specified by the
DISSECT_PLUGINSenvironment variable.
- class dissect.target.plugin.OSPlugin(target: dissect.target.target.Target)¶
Bases:
PluginBase class for OS plugins.
This provides a base class for certain common functions of OS’s, which each OS plugin has to implement separately.
For example, it provides an interface for retrieving the hostname and users of a target.
All derived classes MUST implement ALL the classmethods and exported methods with the same
@classmethodor@export(...)annotation.- classmethod __init_subclass__(**kwargs)¶
- check_compatible() bool¶
OSPlugin’s use a different compatibility check, override the one from the
Pluginclass.- Returns:
This function always returns
True.
- classmethod detect(fs: dissect.target.filesystem.Filesystem) dissect.target.filesystem.Filesystem | None¶
- Abstractmethod:
Provide detection of this OSPlugin on a given filesystem.
- Parameters:
fs –
Filesystemto detect the OS on.- Returns:
The root filesystem / sysvol when found.
- classmethod create(target: dissect.target.target.Target, sysvol: dissect.target.filesystem.Filesystem) typing_extensions.Self¶
- Abstractmethod:
Initiate this OSPlugin with the given target and detected filesystem.
- Parameters:
target – The
Targetobject.sysvol – The filesystem that was detected in the
detect()function.
- Returns:
An instantiated version of the OSPlugin.
- abstract hostname() str | None¶
Return the target’s hostname.
- Returns:
The hostname as string.
- abstract ips() list[str]¶
Return the IP addresses configured in the target.
- Returns:
The IPs as list.
- abstract version() str | None¶
Return the target’s OS version.
- Returns:
The OS version as string.
- abstract users() list[flow.record.Record]¶
Return the users available in the target.
- Returns:
A list of user records.
- abstract os() str¶
Return a slug of the target’s OS name.
- Returns:
A slug of the OS name, e.g. ‘windows’ or ‘linux’.
- abstract misc_user_paths() collections.abc.Iterator[tuple[str, tuple[str, str] | None]]¶
Yields miscellaneous user paths and user keys.
Example
(“c:/Windows/ServiceProfiles/LocalService”, (“sid”, “S-1-5-19”))
- abstract architecture() str | None¶
Return a slug of the target’s OS architecture.
- Returns:
A slug of the OS architecture, e.g. ‘x86_32-unix’, ‘MIPS-linux’ or ‘AMD64-win32’, or ‘unknown’ if the architecture is unknown.
- class dissect.target.plugin.ChildTargetPlugin(target: dissect.target.target.Target)¶
Bases:
PluginA Child target is a special plugin that can list more Targets.
For example,
ESXiChildTargetPlugincan list all of the Virtual Machines on the host.- __type__ = None¶
- abstract list_children() collections.abc.Iterator[dissect.target.helpers.record.ChildTargetRecord]¶
Yield
ChildTargetRecordrecords of all possible child targets on this target.
- class dissect.target.plugin.NamespacePlugin(target: dissect.target.target.Target)¶
Bases:
PluginA namespace plugin provides services to access functionality from a group of subplugins.
Support is currently limited to shared exported functions with output type
recordandyield.- classmethod __init_subclass__(**kwargs)¶
- __init_subclass_subplugin__(**kwargs) None¶
- check_compatible() None¶
Perform a compatibility check with the target.
This function should return
Noneif the plugin is compatible with the current target (self.target). For example, check if a certain file exists. Otherwise it should raise anUnsupportedPluginError.- Raises:
UnsupportedPluginError – If the plugin could not be loaded.
- dissect.target.plugin.__INTERNAL_PLUGIN_METHOD_NAMES__¶
- class dissect.target.plugin.InternalPlugin(target: dissect.target.target.Target)¶
Bases:
PluginParent class for internal plugins.
InternalPlugin marks all non-private methods internal by default (same as
@internaldecorator).- classmethod __init_subclass__(**kwargs)¶
- class dissect.target.plugin.InternalNamespacePlugin(target: dissect.target.target.Target)¶
Bases:
NamespacePlugin,InternalPluginA namespace plugin provides services to access functionality from a group of subplugins.
Support is currently limited to shared exported functions with output type
recordandyield.