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

Make Mssql errorlog plugin more robust #978

Merged
merged 5 commits into from
Jan 2, 2025
Merged
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
21 changes: 7 additions & 14 deletions dissect/target/plugins/os/windows/log/mssql.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

__namespace__ = "mssql"

MSSQL_KEY = "HKLM\\SOFTWARE\\Microsoft\\Microsoft SQL Server"
MSSQL_KEY_GLOB = "HKLM\\SOFTWARE\\Microsoft\\Microsoft SQL Server\\MSSQL*.*"
FILE_GLOB = "ERRORLOG*"

def __init__(self, target: Target):
Expand All @@ -44,7 +44,7 @@

def check_compatible(self) -> None:
if not self.instances:
raise UnsupportedPluginError("System does not seem to be running SQL Server")
raise UnsupportedPluginError("No Microsoft SQL Server instances have been found")

Check warning on line 47 in dissect/target/plugins/os/windows/log/mssql.py

View check run for this annotation

Codecov / codecov/patch

dissect/target/plugins/os/windows/log/mssql.py#L47

Added line #L47 was not covered by tests

@export(record=MssqlErrorlogRecord)
def errorlog(self) -> Iterator[MssqlErrorlogRecord]:
Expand Down Expand Up @@ -89,15 +89,8 @@

buf += line

def _find_instances(self) -> list[str, TargetPath]:
instances = []

for subkey in self.target.registry.key(self.MSSQL_KEY).subkeys():
if subkey.name.startswith("MSSQL") and "." in subkey.name:
instances.append(
(
subkey.name,
self.target.fs.path(subkey.subkey("SQLServerAgent").value("ErrorLogFile").value).parent,
)
)
return instances
def _find_instances(self) -> set[str, TargetPath]:
return {
(subkey.name, self.target.fs.path(subkey.subkey("SQLServerAgent").value("ErrorLogFile").value).parent)
for subkey in self.target.registry.glob_ext(self.MSSQL_KEY_GLOB)
}
Loading