Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Harmonize Compatibility Checks #382

Merged
merged 1 commit into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dissect/target/plugins/apps/av/mcafee.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class McAfeePlugin(Plugin):
TABLE_LOG = "log"
TABLE_FIELD = "field"

def check_compatible(self) -> bool:
def check_compatible(self) -> None:
if not list(self.get_log_files()):
raise UnsupportedPluginError("No McAfee Log files found")

Expand Down
2 changes: 1 addition & 1 deletion dissect/target/plugins/apps/av/sophos.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def __init__(self, target: Target) -> None:
super().__init__(target)
self.codepage = self.target.codepage or "ascii"

def check_compatible(self) -> bool:
def check_compatible(self) -> None:
is_compatible = False
for marker in self.LOGS:
if self.target.fs.path(marker).exists():
Expand Down
2 changes: 1 addition & 1 deletion dissect/target/plugins/apps/av/trendmicro.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def __init__(self, target: Target) -> None:
super().__init__(target)
self.codepage = self.target.codepage or "ascii"

def check_compatible(self) -> bool:
def check_compatible(self) -> None:
if not self.target.fs.path(self.LOG_FOLDER).exists():
raise UnsupportedPluginError

Expand Down
6 changes: 4 additions & 2 deletions dissect/target/plugins/apps/containers/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import re
from typing import Iterator

from dissect.target.exceptions import UnsupportedPluginError
from dissect.target.helpers.record import TargetRecordDescriptor
from dissect.target.plugin import Plugin, export

Expand Down Expand Up @@ -49,8 +50,9 @@ class DockerPlugin(Plugin):

DOCKER_PATH = "/var/lib/docker"

def check_compatible(self) -> bool:
return self.target.fs.path(self.DOCKER_PATH).exists()
def check_compatible(self) -> None:
if not self.target.fs.path(self.DOCKER_PATH).exists():
raise UnsupportedPluginError("No Docker path found")

@export(record=DockerImageRecord)
def images(self) -> Iterator[DockerImageRecord]:
Expand Down
2 changes: 1 addition & 1 deletion dissect/target/plugins/apps/remoteaccess/anydesk.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def __init__(self, target):
for logfile in user_details.home_path.glob(log_glob):
self.logfiles.append([logfile, user_details.user])

def check_compatible(self):
def check_compatible(self) -> None:
if not (len(self.logfiles)):
raise UnsupportedPluginError("No Anydesk logs found")

Expand Down
2 changes: 1 addition & 1 deletion dissect/target/plugins/apps/remoteaccess/teamviewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def __init__(self, target):
for logfile in user_details.home_path.glob("appdata/roaming/teamviewer/teamviewer*_logfile.log"):
self.logfiles.append([logfile, user_details.user])

def check_compatible(self):
def check_compatible(self) -> None:
if not len(self.logfiles):
raise UnsupportedPluginError("No Teamviewer logs found")

Expand Down
2 changes: 1 addition & 1 deletion dissect/target/plugins/apps/shell/powershell.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def __init__(self, target):
for history_file in history_path.glob("*_history.txt"):
self._history.append((user_details.user, history_file))

def check_compatible(self):
def check_compatible(self) -> None:
if not self._history:
raise UnsupportedPluginError("No ConsoleHost_history.txt files found")

Expand Down
6 changes: 4 additions & 2 deletions dissect/target/plugins/apps/ssh/openssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from pathlib import Path
from typing import Iterator

from dissect.target.exceptions import UnsupportedPluginError
from dissect.target.helpers.descriptor_extensions import UserRecordDescriptorExtension
from dissect.target.helpers.fsutil import TargetPath
from dissect.target.helpers.record import create_extended_descriptor
Expand Down Expand Up @@ -65,12 +66,13 @@ class OpenSSHPlugin(Plugin):

SSHD_DIRECTORIES = ["/sysvol/ProgramData/ssh", "/etc/ssh"]

def check_compatible(self):
def check_compatible(self) -> None:
ssh_user_dirs = any(
user_details.home_path.joinpath(".ssh").exists()
for user_details in self.target.user_details.all_with_home()
)
return ssh_user_dirs or self.sshd_directory.exists()
if not ssh_user_dirs and not self.sshd_directory.exists():
raise UnsupportedPluginError("No OpenSSH directories found")

@cached_property
def sshd_directory(self) -> TargetPath:
Expand Down
7 changes: 4 additions & 3 deletions dissect/target/plugins/apps/vpns/wireguard.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from os.path import basename
from typing import Iterator, Union

from dissect.target.exceptions import UnsupportedPluginError
from dissect.target.helpers.record import TargetRecordDescriptor
from dissect.target.plugin import Plugin, export

Expand Down Expand Up @@ -79,9 +80,9 @@ def __init__(self, target) -> None:
for cfg in cfgs:
self.configs.append(cfg)

def check_compatible(self) -> bool:
if len(self.configs) > 0:
return True
def check_compatible(self) -> None:
if not len(self.configs):
raise UnsupportedPluginError("No Wireguard configuration files found")

@export(record=[WireGuardInterfaceRecord, WireGuardPeerRecord])
def config(self) -> Iterator[Union[WireGuardInterfaceRecord, WireGuardPeerRecord]]:
Expand Down
7 changes: 4 additions & 3 deletions dissect/target/plugins/apps/webservers/apache.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from typing import Iterator, Optional

from dissect.target import plugin
from dissect.target.exceptions import FileNotFoundError
from dissect.target.exceptions import FileNotFoundError, UnsupportedPluginError
from dissect.target.helpers.fsutil import open_decompress
from dissect.target.plugins.apps.webservers.webservers import WebserverAccessLogRecord
from dissect.target.target import Target
Expand Down Expand Up @@ -63,8 +63,9 @@ def __init__(self, target: Target):
super().__init__(target)
self.log_paths = self.get_log_paths()

def check_compatible(self) -> bool:
return len(self.log_paths) > 0
def check_compatible(self) -> None:
if not len(self.log_paths):
raise UnsupportedPluginError("No Apache directories found")

@plugin.internal
def get_log_paths(self) -> list[Path]:
Expand Down
7 changes: 4 additions & 3 deletions dissect/target/plugins/apps/webservers/caddy.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from dissect.util.ts import from_unix

from dissect.target import plugin
from dissect.target.exceptions import FileNotFoundError
from dissect.target.exceptions import FileNotFoundError, UnsupportedPluginError
from dissect.target.helpers.fsutil import basename, open_decompress
from dissect.target.plugins.apps.webservers.webservers import WebserverAccessLogRecord
from dissect.target.target import Target
Expand All @@ -25,8 +25,9 @@ def __init__(self, target: Target):
super().__init__(target)
self.log_paths = self.get_log_paths()

def check_compatible(self) -> bool:
return len(self.log_paths) > 0
def check_compatible(self) -> None:
if not len(self.log_paths):
raise UnsupportedPluginError("No Caddy paths found")

@plugin.internal
def get_log_paths(self) -> list[Path]:
Expand Down
7 changes: 4 additions & 3 deletions dissect/target/plugins/apps/webservers/nginx.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from typing import Iterator

from dissect.target import plugin
from dissect.target.exceptions import FileNotFoundError
from dissect.target.exceptions import FileNotFoundError, UnsupportedPluginError
from dissect.target.helpers.fsutil import open_decompress
from dissect.target.plugins.apps.webservers.webservers import WebserverAccessLogRecord
from dissect.target.target import Target
Expand All @@ -21,8 +21,9 @@ def __init__(self, target: Target):
super().__init__(target)
self.log_paths = self.get_log_paths()

def check_compatible(self) -> bool:
return len(self.log_paths) > 0
def check_compatible(self) -> None:
if not len(self.log_paths):
raise UnsupportedPluginError("No NGINX directories found")

@plugin.internal
def get_log_paths(self) -> list[Path]:
Expand Down
2 changes: 1 addition & 1 deletion dissect/target/plugins/apps/webservers/webservers.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def __init__(self, target: Target):
except Exception: # noqa
target.log.exception("Failed to load webserver plugin: %s", entry)

def check_compatible(self) -> bool:
def check_compatible(self) -> None:
if not len(self._plugins):
raise UnsupportedPluginError("No compatible webserver plugins found")

Expand Down
2 changes: 1 addition & 1 deletion dissect/target/plugins/browsers/firefox.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def __init__(self, target):
continue
self.users_dirs.append((user_details.user, cur_dir))

def check_compatible(self):
def check_compatible(self) -> None:
if not len(self.users_dirs):
raise UnsupportedPluginError("No Firefox directories found")

Expand Down
2 changes: 1 addition & 1 deletion dissect/target/plugins/browsers/iexplore.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def __init__(self, target: Target):
continue
self.users_dirs.append((user_details.user, cdir))

def check_compatible(self) -> bool:
def check_compatible(self) -> None:
if not len(self.users_dirs):
raise UnsupportedPluginError("No Internet Explorer directories found")

Expand Down
6 changes: 4 additions & 2 deletions dissect/target/plugins/child/esxi.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from dissect.target.exceptions import UnsupportedPluginError
from dissect.target.helpers.record import ChildTargetRecord
from dissect.target.plugin import ChildTargetPlugin

Expand All @@ -7,8 +8,9 @@ class ESXiChildTargetPlugin(ChildTargetPlugin):

__type__ = "esxi"

def check_compatible(self):
return self.target.os == "esxi"
def check_compatible(self) -> None:
if self.target.os != "esxi":
raise UnsupportedPluginError("Not an ESXi operating system")

def list_children(self):
for vm in self.target.vm_inventory():
Expand Down
2 changes: 1 addition & 1 deletion dissect/target/plugins/child/hyperv.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(self, target: Target):
self.data_vmcx = hyperv_path.joinpath("data.vmcx")
self.vm_xml = list(hyperv_path.joinpath("Virtual Machines").glob("*.xml"))

def check_compatible(self):
def check_compatible(self) -> None:
if not self.data_vmcx.exists() and not self.vm_xml:
raise UnsupportedPluginError("No registered VMs and no data.vmcx file found")

Expand Down
6 changes: 4 additions & 2 deletions dissect/target/plugins/child/virtuozzo.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from dissect.target.exceptions import UnsupportedPluginError
from dissect.target.helpers.record import ChildTargetRecord
from dissect.target.plugin import ChildTargetPlugin

Expand All @@ -24,8 +25,9 @@ class VirtuozzoChildTargetPlugin(ChildTargetPlugin):

PATH = "/vz/root"

def check_compatible(self) -> bool:
return self.target.fs.path(self.PATH).exists()
def check_compatible(self) -> None:
if not self.target.fs.path(self.PATH).exists():
raise UnsupportedPluginError("No Virtuozzo path found")

def list_children(self):
for container in self.target.fs.path(self.PATH).iterdir():
Expand Down
6 changes: 4 additions & 2 deletions dissect/target/plugins/child/vmware_workstation.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from flow.record.fieldtypes import path

from dissect.target.exceptions import UnsupportedPluginError
from dissect.target.helpers.record import ChildTargetRecord
from dissect.target.plugin import ChildTargetPlugin

Expand All @@ -20,8 +21,9 @@ def __init__(self, target):
super().__init__(target)
self.inventories = list(find_vm_inventory(target))

def check_compatible(self):
return len(self.inventories) > 0
def check_compatible(self) -> None:
if not len(self.inventories):
raise UnsupportedPluginError("No VMWare inventories found")

def list_children(self):
for inv in self.inventories:
Expand Down
7 changes: 4 additions & 3 deletions dissect/target/plugins/child/wsl.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pathlib import Path
from typing import Iterator

from dissect.target.exceptions import PluginNotFoundError
from dissect.target.exceptions import PluginNotFoundError, UnsupportedPluginError
from dissect.target.helpers.record import ChildTargetRecord
from dissect.target.plugin import ChildTargetPlugin
from dissect.target.target import Target
Expand Down Expand Up @@ -48,8 +48,9 @@ def __init__(self, target: Target):
super().__init__(target)
self.installs = list(find_wsl_installs(target))

def check_compatible(self) -> bool:
return len(self.installs) > 0
def check_compatible(self) -> None:
if not len(self.installs):
raise UnsupportedPluginError("No WSL installs found")

def list_children(self) -> Iterator[ChildTargetRecord]:
for install_path in self.installs:
Expand Down
6 changes: 4 additions & 2 deletions dissect/target/plugins/filesystem/acquire_handles.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import gzip
from typing import Iterator

from dissect.target.exceptions import UnsupportedPluginError
from dissect.target.helpers.record import TargetRecordDescriptor
from dissect.target.plugin import Plugin, export

Expand Down Expand Up @@ -29,8 +30,9 @@ def __init__(self, target):
super().__init__(target)
self.open_handles_file = target.fs.path("$metadata$/open_handles.csv.gz")

def check_compatible(self) -> bool:
return self.open_handles_file.exists()
def check_compatible(self) -> None:
if not self.open_handles_file.exists():
raise UnsupportedPluginError("No open handles found")

@export(record=AcquireOpenHandlesRecord)
def acquire_handles(self) -> Iterator[AcquireOpenHandlesRecord]:
Expand Down
6 changes: 4 additions & 2 deletions dissect/target/plugins/filesystem/acquire_hash.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from flow.record.fieldtypes import posix_path, windows_path

from dissect.target.exceptions import UnsupportedPluginError
from dissect.target.helpers.record import TargetRecordDescriptor
from dissect.target.plugin import Plugin, export

Expand All @@ -23,8 +24,9 @@ def __init__(self, target):
super().__init__(target)
self.hash_file = target.fs.path("$metadata$/file-hashes.csv.gz")

def check_compatible(self):
return self.hash_file.exists()
def check_compatible(self) -> None:
if not self.hash_file.exists():
raise UnsupportedPluginError("No hash file found")

@export(record=AcquireHashRecord)
def acquire_hashes(self):
Expand Down
6 changes: 4 additions & 2 deletions dissect/target/plugins/filesystem/icat.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import dissect.ntfs.exceptions
import dissect.xfs.exceptions

from dissect.target.exceptions import UnsupportedPluginError
from dissect.target.plugin import Plugin, arg, export


Expand All @@ -13,9 +14,10 @@ class ICatPlugin(Plugin):

FS_SUPPORTED = ["ntfs", "xfs", "ext", "virtual"]

def check_compatible(self):
def check_compatible(self) -> None:
filesystems = self.target.filesystems
return any(fs.__fstype__ in self.FS_SUPPORTED for fs in filesystems)
if not any(fs.__fstype__ in self.FS_SUPPORTED for fs in filesystems):
raise UnsupportedPluginError("No supported filesystems found")

@arg("--segment", "--inode", "-i", dest="inum", required=True, type=int, help="MFT segment or inode number")
@arg(
Expand Down
6 changes: 4 additions & 2 deletions dissect/target/plugins/filesystem/ntfs/mft.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from dissect.ntfs.mft import MftRecord
from flow.record.fieldtypes import windows_path

from dissect.target.exceptions import UnsupportedPluginError
from dissect.target.helpers.record import TargetRecordDescriptor
from dissect.target.plugin import Plugin, arg, export
from dissect.target.plugins.filesystem.ntfs.utils import (
Expand Down Expand Up @@ -103,9 +104,10 @@


class MftPlugin(Plugin):
def check_compatible(self):
def check_compatible(self) -> None:
ntfs_filesystems = [fs for fs in self.target.filesystems if fs.__fstype__ == "ntfs"]
return len(ntfs_filesystems) > 0
if not len(ntfs_filesystems):
raise UnsupportedPluginError("No NTFS filesystems found")

@export(
record=[
Expand Down
6 changes: 4 additions & 2 deletions dissect/target/plugins/filesystem/ntfs/mft_timeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from dissect.ntfs.c_ntfs import FILE_RECORD_SEGMENT_IN_USE
from dissect.ntfs.mft import MftRecord

from dissect.target.exceptions import UnsupportedPluginError
from dissect.target.filesystems.ntfs import NtfsFilesystem
from dissect.target.plugin import Plugin, arg, export
from dissect.target.plugins.filesystem.ntfs.utils import (
Expand Down Expand Up @@ -92,9 +93,10 @@ def format_info(


class MftTimelinePlugin(Plugin):
def check_compatible(self):
def check_compatible(self) -> None:
ntfs_filesystems = [fs for fs in self.target.filesystems if fs.__fstype__ == "ntfs"]
return len(ntfs_filesystems) > 0
if not len(ntfs_filesystems):
raise UnsupportedPluginError("No MFT timelines found")

@export(output="yield")
@arg("--ignore-dos", action="store_true", help="ignore DOS file names")
Expand Down
Loading