当前位置:网站首页>【 fastjson1.2.24反序列化漏洞原理代码分析】
【 fastjson1.2.24反序列化漏洞原理代码分析】
2022-07-26 07:57:00 【半盏时光、旧梦悠长】
第一章 fastjson1.2.24反序列化漏洞原理代码分析
@ author 鸿鸟安全
文章目录
前言
FastJson漏洞代码分析,为了对漏洞理解更深入,也是为以后挖掘通用漏洞作铺垫,提升代码审计能力,积累更多的知识。
一、FastJson
FastJson是阿里巴巴开源的Java对象和JSON格式字符串的快速转换的工具库,对标Google的Gson。
优点:
- 速度快
- 使用广泛
- 使用简单
二、FastJson使用
1.maven工程直接引用jar
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>版本根据自己需要</version>
</dependency>
三、漏洞环境搭建
1.Idea新建maven工程的文件结构

2.pom.xml引入fastjson1.2.24jar包
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.fastjson</groupId>
<artifactId>fastajson</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.24</version>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
</project>
3.新建Person类
先在Java目录下新建包com.trancers.test,然后在包中新建Person类
package com.trancers.test;
import java.io.IOException;
public class Person {
private String name;
private Integer age;
public String getName() {
System.out.println("call getname");
return name;
}
public void setName(String name) throws IOException {
System.out.println("call setname");
Runtime.getRuntime().exec(name);
this.name = name;
}
public Integer getAge() {
System.out.println("call getage");
return age;
}
public void setAge(Integer age) {
System.out.println("call setage");
this.age = age;
}
}
3.新建主函数TestMain
- 构造简单的payload,下面看一下调用过程
package com.trancers.test;
import com.alibaba.fastjson.JSONObject;
public class TestMain {
public static void main(String[] args) {
String str = "{\"@type\":\"com.trancers.test.Person\",\"age\":20,\"name\":\"calc\"}";
Object obj1 = JSONObject.parse(str);
System.out.println(obj1);
}
}
- 首先进入
JONObject类调用parse方法

- 调用静态parse同名方法传入
test和DEFAULT_PARSER_FEATURE两个参数

DEFAULT_PARSER_FEATURE在加载JSON类同时加载静态代码块计算出数值989

- 创建一个
DefaultJSONParser对象将JSONToken.LBRACE赋值给((JSONLexerBase) lexer).token

- 看一下parser属性包含哪些,然后调用parse方法

- 方法里做了一个判断之前在上个方法中已经赋值
lexer.token所以会走到LBRACE

- 创建了一个
hashmap对象


- 调用
parseObject方法

- 做词法分析取出key值,及key对应value值

- 因为@type走进了这个判断里,执行了类反射,@type值又是包的路径所以根据
com.trancers.test.Person直接去加载类


- 然后进行序列化操作,取出类的所有属性,以及传入的text进行匹配,类的属性名与key值相同进行赋值。

四、总结
简单分析一下fastjson反序列化漏洞的成因、调用过程和触发点。
鸿鸟只思羽翼齐 点翅飞腾千万里

``
边栏推荐
- Enterprise private network construction and operation and maintenance
- Abstract classes and interfaces
- 《门锁》引爆独居安全热议 全新海报画面令人窒息
- 【uniapp】多种支付方式封装
- Shardingjdbc pit record
- Distributed system and distributed database system (Introduction)
- Leetcode sword finger offer special (I) integer
- LeetCode剑指offer专项(一)整数
- Tensorflow learning diary tflearn
- The difference between overloading and rewriting
猜你喜欢

Basic knowledge of convolutional neural network

Shardingjdbc pit record

“尝鲜”元宇宙,周杰伦最佳拍档方文山将于7月25日官宣《华流元宇宙》

IDEA settings设置快捷键实现字符串中的英文字母转大小写
![[classic thesis of recommendation system (10)] Alibaba SDM model](/img/a5/3ae37b847042ffb34e436720f61d17.png)
[classic thesis of recommendation system (10)] Alibaba SDM model

音视频学习(十)——ps流

Kdd2022 | uncover the mystery of Kwai short video recommendation re ranking, and recommend the new SOTA

Installation of Baidu flying paste deep learning framework tutorial in Anaconda
![[daily question 1] 919. Complete binary tree inserter](/img/a2/2ff77ccdfb78bb1812b989342c2331.png)
[daily question 1] 919. Complete binary tree inserter

Learning Efficient Convolutional Networks Through Network Slimming
随机推荐
Regular expression rules and common regular expressions
力扣(LeetCode)206. 反转链表(2022.07.25)
Brief description of hystrix configuration
Meta universe infrastructure: analysis of the advantages of Web 3.0 chain33
基于Thinkphp的开源管理系统
微服务feign调用时候,token丢失问题解决方案
The difference between overloading and rewriting
Add traceid to the project log
Shardingsphere data slicing
utils 连接池
Program environment and pretreatment
Pycharm common shortcut keys
Machine learning related competition website
Hcip--- MPLS detailed explanation and BGP route filtering
LeetCode剑指offer专项(一)整数
Jmeter性能测试之使用存储响应内容到文件监听器
Deep learning model deployment
Yaml language-01 (data type, array, object)
总结软件测试岗的那些常见高频面试题
Common database commands (special for review)