dissect.target.filesystems.config#

Module Contents#

Classes#

ConfigurationFilesystem

A special Filesystem class that allows you to browse and interact with configuration files

ConfigurationEntry

A Special filesystem entry.

Attributes#

log

dissect.target.filesystems.config.log#
class dissect.target.filesystems.config.ConfigurationFilesystem(target: dissect.target.Target, path: str, **kwargs)#

Bases: dissect.target.filesystem.VirtualFilesystem

A special Filesystem class that allows you to browse and interact with configuration files as directories and files by parsing the file into key/value pairs.

Depending on the value of a configuration file’s key, it will act like a directory or file:
  • When the key contains sub-values (dictionary), it will act like a directory.

  • Otherwise it will act like a file.

Examples

>>> fs = ConfigurationFilesystem(target, "/etc")
>>> entry = fs.get("xattr.conf")
<ConfigurationEntry path=/etc/xattr.conf value=<dissect.target.helpers.configutil.Default object at 0x115683280>
>>> entry.listdir() # listed entries are the keys in the configuration file
[...
'system.posix_acl_access',
'system.posix_acl_default',
'trusted.SGI_ACL_DEFAULT',
'trusted.SGI_ACL_FILE',
...]
>>> entry.get("system.posix_acl_access") # returns the value of the key
<ConfigurationEntry path=/etc/xattr.conf/system.posix_acl_access value=permissions>
>>> entry.get("system.posix_acl_access").open().read() # returns the raw value of the key
b'permissions\n'
__type__: str = 'META:configuration'#
get(path: str, relentry: dissect.target.filesystem.FilesystemEntry | None = None, *args, **kwargs) dissect.target.filesystem.FilesystemEntry | ConfigurationEntry#

Retrieve a ConfigurationEntry or FilesystemEntry relative to the root or relentry.

Raises:

FileNotFoundError – if it could not find the entry.

class dissect.target.filesystems.config.ConfigurationEntry(fs: dissect.target.filesystem.Filesystem, path: str, entry: dissect.target.filesystem.FilesystemEntry, parser_items: dict | dissect.target.helpers.configutil.ConfigurationParser | str | list | None = None)#

Bases: dissect.target.filesystem.FilesystemEntry

A Special filesystem entry.

Behaves like a directory when parser_items is a ConfigurationParser or a dict. Behaves like a file otherwise.

parser_items#

A dict-like object containing all configuration entries and values. In most cases this is either a ConfigurationParser or dict. Otherwise, its the entry’s value

Examples

>>> fs = ConfigurationFilesystem(target, "/etc")
>>> entry = fs.get("xattr.conf")
<ConfigurationEntry path=/etc/xattr.conf value=<dissect.target.helpers.configutil.Default object at 0x115683280>
>>> entry.listdir() # listed entries are the keys in the configuration file
[...
'system.posix_acl_access',
'system.posix_acl_default',
'trusted.SGI_ACL_DEFAULT',
'trusted.SGI_ACL_FILE',
...]
>>> entry.as_dict()
{
    ...
    "system.posix_acl_access" : "...",
    ...
}
>>> entry.get("system.posix_acl_access") # returns the value of the key
<ConfigurationEntry path=/etc/xattr.conf/system.posix_acl_access value=permissions>
>>> entry.get("system.posix_acl_access").open().read() # returns the raw value of the key
b'permissions\n'
__getitem__(item: str) ConfigurationEntry#
__repr__() str#

Return repr(self).

get(key, default: Any | None = None) ConfigurationEntry | Any | None#

Gets the dictionary key that belongs to this entry using key. Behaves like dictionary.get().

Parameters:
  • key – A dictionary key that is inside parser_items.

  • default – The default value to return if key is not inside this entry.

Returns:

a ConfigurationEntry when key is present, otherwise its default.

open() BinaryIO#

Open this ConfigurationEntry.

If parser_items is a ConfigurationParser, it will open the underlying entry.

Returns:

A file-like object holding a byte representation of parser_items.

iterdir() Iterator[str]#

Iterate over the contents of a directory, return them as strings.

Returns:

An iterator of directory entries as path strings.

scandir() Iterator[ConfigurationEntry]#

Return the items inside parser_items as ConfigurationEntries.

is_file(follow_symlinks: bool = True) bool#

Determine if this entry is a file.

Parameters:

follow_symlinks – Whether to resolve the entry if it is a symbolic link.

Returns:

True if the entry is a file or a symbolic link to a file, return False otherwise. If follow_symlinks is False, return True only if the entry is a file (without following symlinks).

is_dir(follow_symlinks: bool = True) bool#

Returns whether this ConfigurationEntry can be considered a directory.

Return whether this ConfigurationEntry is a symlink or not.

Returns:

False, as ConfigurationEntries are never symlinks.

exists(key: str) bool#

Return whether the underlying FilesystemEntry entry and supplied key exists inside this ConfigurationEntry.

Returns:

Whether the entry and key exists

stat(follow_symlinks: bool = True) dissect.target.helpers.fsutil.stat_result#

Returns the stat from the underlying FilesystemEntry entry.

lstat() dissect.target.helpers.fsutil.stat_result#

Returns the lstat from the underlying FilesystemEntry entry.

as_dict() dict#

Returns parser_items as a dictionary.