dissect.target.filesystems.config¶
Module Contents¶
Classes¶
A special |
|
A Special filesystem entry. |
Attributes¶
- dissect.target.filesystems.config.log¶
- class dissect.target.filesystems.config.ConfigurationFilesystem(target: dissect.target.target.Target, path: str, **kwargs)¶
Bases:
dissect.target.filesystem.VirtualFilesystemA special
Filesystemclass that allows you to browse and interact with configuration files asdirectoriesandfilesby parsing the file into key/value pairs.- Depending on the
valueof a configuration file’skey, it will act like adirectoryorfile: When the
keycontains sub-values (dictionary), it will act like adirectory.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'¶
A short string identifying the type of filesystem.
- get(path: str, relentry: dissect.target.filesystem.FilesystemEntry | None = None, *args, **kwargs) ConfigurationEntry¶
Retrieve a
ConfigurationEntryrelative to the root orrelentry.- Raises:
FileNotFoundError – if it could not find the entry.
- Depending on the
- class dissect.target.filesystems.config.ConfigurationEntry(fs: ConfigurationFilesystem, path: str, entry: dissect.target.filesystem.FilesystemEntry, parser_items: dict | dissect.target.helpers.configutil.ConfigurationParser | str | list | None = None)¶
Bases:
dissect.target.filesystem.FilesystemEntryA Special filesystem entry.
Behaves like a
directorywhenparser_itemsis aConfigurationParseror adict. Behaves like afileotherwise.- Parameters:
parser_items – A dict-like object containing all configuration entries and values. In most cases this is either a
ConfigurationParserordict. 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'
- parser_items = None¶
- __getitem__(item: str) ConfigurationEntry¶
- __repr__() str¶
- get(key: str, default: Any | None = None) ConfigurationEntry | Any | None¶
Gets the dictionary key that belongs to this entry using
key. Behaves likedictionary.get().- Parameters:
key – A dictionary key that is inside
parser_items.default – The default value to return if
keyis not inside this entry.
- Returns:
a
ConfigurationEntrywhenkeyis present, otherwise itsdefault.
- open() BinaryIO¶
Open this
ConfigurationEntry.If
parser_itemsis aConfigurationParser, it willopenthe underlying entry.- Returns:
A file-like object holding a byte representation of
parser_items.
- iterdir() collections.abc.Iterator[str]¶
Iterate over the contents of a directory, return them as strings.
- Returns:
An iterator of directory entries as path strings.
- scandir() collections.abc.Iterator[ConfigurationEntry]¶
Return the items inside
parser_itemsasConfigurationEntries.
- 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:
Trueif the entry is a file or a symbolic link to a file, returnFalseotherwise. Iffollow_symlinksisFalse, returnTrueonly if the entry is a file (without following symlinks).
- is_dir(follow_symlinks: bool = True) bool¶
Returns whether this
ConfigurationEntrycan be considered a directory.
- is_symlink() bool¶
Return whether this
ConfigurationEntryis a symlink or not.- Returns:
False, as
ConfigurationEntriesare never symlinks.
- exists(key: str) bool¶
Return whether the underlying
FilesystemEntryentryand suppliedkeyexists inside thisConfigurationEntry.- Returns:
Whether the
entryandkeyexists
- stat(follow_symlinks: bool = True) dissect.target.helpers.fsutil.stat_result¶
Returns the stat from the underlying
FilesystemEntryentry.
- lstat() dissect.target.helpers.fsutil.stat_result¶
Returns the lstat from the underlying
FilesystemEntryentry.
- as_dict() dict¶
Returns
parser_itemsas a dictionary.