WebLogic 任意文件上传漏洞(CVE-2018-2894)复现与原理分析

近日,Oracle 7月更新中,修复了Weblogic Web Service TestPage中一处任意文件上传漏洞 (CVE-2018-2894),并得到了厂商的确认,危害程度评分高达9.8分,鉴于近期厂商已进行了安全修复,现对漏洞情况进行简单说明和复现分析。

WebLogic 任意文件上传漏洞(CVE-2018-2894)复现与原理分析

一、 事件分析

WebLogic管理端未授权的两个页面存在任意上传getshell漏洞,可直接获取权限。两个页面分别为/ws_utc/begin.do,/ws_utc/config.do。

二、影响范围

受影响版本:

WebLogic 10.3.6.0

WebLogic 12.1.3.0

WebLogic 12.2.1.2

WebLogic 12.2.1.3

三、攻击过程概述

1. 环境信息:

  • 操作系统:kali
  • weblogic版本:12.2.1.3.0

下载地址:

http://download.oracle.com/otn/nt/middleware/12c/12213/fmw_12.2.1.3.0_wls_quick_Disk1_1of1.zip

2. 漏洞复现

此次的漏洞触发需要两个条件:

  • 需要知道部署应用的web目录
  • ws_utc/config.do在开发模式下无需认证,在生产模式下需要认证。具体可见Oracle® Fusion Middleware Administering Web Services

1)启用Web 服务测试页

环境启动后,访问

http://192.168.42.129:7001/console,即可看到后台登录页面。

WebLogic 任意文件上传漏洞(CVE-2018-2894)复现与原理分析

Weblogic/RLC0KtTF

登录后台页面,点击base_domain的配置,在“高级”中开启“启用 Web 服务测试页”选项:

WebLogic 任意文件上传漏洞(CVE-2018-2894)复现与原理分析

2)设置工作目录

访问

http://192.168.42.129:7001/ws_utc/config.do

WebLogic 任意文件上传漏洞(CVE-2018-2894)复现与原理分析

设置Work Home Dir为/u01/oracle/user_projects/domains/base_domain/servers/AdminServer/tmp/_WL_internal/com.oracle.webservices.wls.ws-testclient-app-wls/4mcj4y/war/css

将目录设置为ws_utc应用的静态文件css目录,访问这个目录是无需权限的,这一点很重要。

WebLogic 任意文件上传漏洞(CVE-2018-2894)复现与原理分析

3)上传webshell

点击安全 -> 增加,然后上传webshell:

WebLogic 任意文件上传漏洞(CVE-2018-2894)复现与原理分析

上传后,查看返回的数据包,其中有时间戳:

WebLogic 任意文件上传漏洞(CVE-2018-2894)复现与原理分析

1532346451711bshell.jspv

上传到服务器的文件路径为:

ws_utc/css/config/keystore/[时间戳]_[文件名],

抓包获取到时间戳为1532346451711,则上传到的位置为:

ws_utc/css/config/keystore/1532346451711_shell.jsp

Webshell地址为:

http://192.168.42.129:7001/ws_utc/css/config/keystore/1532346451711_shell.jsp

访问即可执行webshell。

WebLogic 任意文件上传漏洞(CVE-2018-2894)复现与原理分析

3. 漏洞分析

在ws-testpage-impl.jar!/com/oracle/webservices/testclient/setting/TestClientWorkDirManager.class:59:

public void changeWorkDir(String path) {

String[] oldPaths = this.getRelatedPaths();

if (this.testPageProvider.getWsImplType() == ImplType.JRF) {

this.isWorkDirChangeable = false;

this.isWorkDirWritable = isDirWritable(path);

this.isWorkDirChangeable = true;

this.setTestClientWorkDir(path);

} else {

this.persistWorkDir(path);

this.init();

}

if (this.isWorkDirWritable) {

String[] newPaths = this.getRelatedPaths();

moveDirs(oldPaths, newPaths);

} else {

Logger.fine("[INFO] Newly specified TestClient Working Dir is readonly. Won't move the configuration stuff to new path.");

}

}

此函数用于改变工作目录,但其中并未做任何检测。

在ws-testpage-impl.jar!/com/oracle/webservices/testclient/ws/res/SettingResource.class:181中:

@Path("/keystore")

@POST

@Produces({"application/xml", "application/json"})

@Consumes({"multipart/form-data"})

public Response editKeyStoreSettingByMultiPart(FormDataMultiPart formPartParams){

if (!RequestUtil.isRequstedByAdmin(this.request)) {

return Response.status(Status.FORBIDDEN).build();

} else {

if (TestClientRT.isVerbose()) {

Logger.fine("calling SettingResource.addKeyStoreSettingByMultiPart");

}

String currentTimeValue = "" + (new Date()).getTime();

KeyValuesMap formParams = RSDataHelper.getInstance().convertFormDataMultiPart(formPartParams,

true, TestClientRT.getKeyStorePath(), currentTimeValue);

....

}

}

跟入ws-testpage-impl.jar!/com/oracle/webservices/testclient/core/ws/cdf/config/parameter/TestClientRT.class:31

publicstatic String getKeyStorePath(){

return getConfigDir() + File.separator + "keystore";

}

得到要写入的路径storePath。

在ws-testpage-impl.jar!/com/oracle/webservices/testclient/ws/util/RSDataHelper.class:145:

public KeyValuesMap convertFormDataMultiPart(FormDataMultiPart formPartParams, boolean isExtactAttachment, String path, String fileNamePrefix) {

...

if (attachName != null && attachName.trim().length() > 0) {

if (attachName != null && attachName.trim().length() != 0) {

attachName = this.refactorAttachName(attachName);

if (fileNamePrefix == null) {

fileNamePrefix = key;

}

String filename = (new File(storePath, fileNamePrefix + "_" + attachName)).getAbsolutePath();

kvMap.addValue(key, filename);

if (isExtactAttachment) {

this.saveAttachedFile(filename, (InputStream)bodyPart.getValueAs(InputStream.class));

}

}

}

...

}

把上传文件的内容传到了storePath目录里,文件名满足fileNamePrefix + "_" + attachName。这过程没有任何过滤和检查:)...

四、安全防护建议

建议相关受影响厂商和组织及时更新产品版本,安装安全补丁,参考oracle官方信息:

http://www.oracle.com/technetwork/security-advisory/cpujul2018-4258247.html#AppendixFMW

参考链接:

http://www.oracle.com/technetwork/security-advisory/cpujul2018-4258247.html

https://xz.aliyun.com/t/2458

https://github.com/vulhub/vulhub/blob/master/weblogic/CVE-2018-2894

WebLogic 任意文件上传漏洞(CVE-2018-2894)复现与原理分析


分享到:


相關文章: