当前位置:网站首页>[fastjson1.2.24 deserialization vulnerability principle code analysis]
[fastjson1.2.24 deserialization vulnerability principle code analysis]
2022-07-26 07:59:00 【Half a lamp of time, long old dreams】
Chapter one fastjson1.2.24 Deserialization vulnerability principle code analysis
@ author Hongniao safety
List of articles
Preface
FastJson Vulnerability code analysis , In order to understand the vulnerability more deeply , It also paves the way for tapping common vulnerabilities in the future , Improve code audit capability , Accumulate more knowledge .
One 、FastJson
FastJson Alibaba open source Java Objects and JSON Tool library for fast conversion of format string , For standard Google Of Gson.
advantage :
- Fast
- Widely used
- Easy to use
Two 、FastJson Use
1.maven Project direct reference jar
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version> Version according to your needs </version>
</dependency>
3、 ... and 、 Build a loophole environment
1.Idea newly build maven Document structure of the project

2.pom.xml introduce fastjson1.2.24jar package
<?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. newly build Person class
First in Java Create a new package under the directory com.trancers.test, Then create a new... In the package Person class
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. New main function TestMain
- Simple in construction payload, Let's take a look at the calling procedure
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);
}
}
- First of all to enter
JONObjectClass callparseMethod

- Call static parse The method with the same name is passed in
testandDEFAULT_PARSER_FEATURETwo parameters

DEFAULT_PARSER_FEATUREIn the load JSON Class loads the static code block at the same time and calculates the value989

- Create a
DefaultJSONParserObject willJSONToken.LBRACEAssign a value to((JSONLexerBase) lexer).token

- to glance at parser What does the attribute contain , And then call parse Method

- Before making a judgment in the method, it has been assigned a value in the previous method
lexer.tokenSo I will go toLBRACE

- Created a
hashmapobject


- call
parseObjectMethod

- Do lexical analysis and take out key value , And key Corresponding value value

- because @type Into this judgment , Implemented class reflection ,@type Value is the path of the package, so according to
com.trancers.test.PersonDirectly load classes


- Then serialize , Take out all the properties of the class , And the incoming text Match , The property name of the class is the same as key The same value is assigned .

Four 、 summary
A brief analysis of fastjson Causes of deserialization vulnerability 、 Call procedures and trigger points .
Hongniao only wants to have wings together Point wings flying thousands of miles

``
边栏推荐
- QT listview add controls and pictures
- Jmeter性能测试之将每次接口请求的结果保存到文件中
- The difference between abstract classes and interfaces
- OVS underlying implementation principle
- “尝鲜”元宇宙,周杰伦最佳拍档方文山将于7月25日官宣《华流元宇宙》
- Summary of common methods of string
- 20220209 create a basic Servlet
- 为啥谷歌的内部工具不适合你?
- Lambda and stream
- Quantitative perception training in tensorflow2.x and x86 end evaluation of tflite
猜你喜欢

DCN (deep cross network) Trilogy

动态性能视图概述

PyTorch
![[classic thesis of recommendation system (10)] Alibaba SDM model](/img/a5/3ae37b847042ffb34e436720f61d17.png)
[classic thesis of recommendation system (10)] Alibaba SDM model

什么是消息订阅和发布?

要不你给我说说什么是长轮询吧?

table 固定特定行

Machine learning related competition website

No valid host was found when setting up openstack to create an instance There are not enough hosts available. code:500

A tutorial for mastering MySQL database audit characteristics, implementation scheme and audit plug-in deployment
随机推荐
Crawler - > tpimgspider
Next item recommendations in short sessions
Distributed system and distributed database system (Introduction)
"Door lock" ignites a heated discussion on the safety of living alone. The new poster picture is suffocating
【 fastjson1.2.24反序列化漏洞原理代码分析】
Establishment and use of openstack cloud platform
Copy pcap file with producer consumer model
Use of JMeter performance test to store response content to file listener
ARIMA model for time series analysis and prediction
Tensorflow learning diary tflearn
Shardingjdbc pit record
Master slave database deployment
给项目日志加上traceid
utils 连接池
table 固定特定行
DADNN: Multi-Scene CTR Prediction via Domain-Aware Deep Neural Network
Jmeter性能测试之将每次接口请求的结果保存到文件中
万字长文 | 深入理解 OpenFeign 的架构原理
NFS service and Samba service deployment
数据库基础