当前位置:网站首页>【 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反序列化漏洞的成因、调用过程和触发点。
鸿鸟只思羽翼齐 点翅飞腾千万里

``
边栏推荐
- 分布式相关面试题总结
- Utils connection pool
- JWT快速入门
- 【uniapp】多种支付方式封装
- The difference between abstract classes and interfaces
- OVSDB
- No valid host was found when setting up openstack to create an instance There are not enough hosts available. code:500
- 2022.7.22DAY612
- Sort: merge sort and quick sort
- The difference between overloading and rewriting
猜你喜欢

Use of JMeter performance test to store response content to file listener
![[classic thesis of recommendation system (10)] Alibaba SDM model](/img/a5/3ae37b847042ffb34e436720f61d17.png)
[classic thesis of recommendation system (10)] Alibaba SDM model

QT listview add controls and pictures

Practice of online question feedback module (XIV): realize online question answering function

NFS service and Samba service deployment

Table fix specific rows

Simulation of transfer function step response output of botu PLC first-order lag system (SCL)

记一次路由器频繁掉线问题的分析、解决与发展

PyTorch

Enterprise private network construction and operation and maintenance
随机推荐
What are the differences between FileInputStream and bufferedinputstream?
Wrong Addition
Network ()
MySQL implementation plan
Introduction to C language (8)
From boosting to lamdamart
C # use log4net to record logs (basic chapter)
No valid host was found when setting up openstack to create an instance There are not enough hosts available. code:500
PostgreSQL UUID fuzzy search UUID string type conversion SQL error [42883] explicit type casts
Copy pcap file with producer consumer model
Command line execution and test report generation of JMeter performance test
Read and write of zip file
C语言关键字extern
Brief description of hystrix configuration
Wrong Addition
分布式相关面试题总结
1. MySQL Architecture [MySQL advanced]
Solution to the problem of token loss when microservice feign is called
QT listview add controls and pictures
一文掌握mysql数据库审计特点、实现方案及审计插件部署教程