当前位置:网站首页>[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

``
边栏推荐
- Sort: merge sort and quick sort
- DADNN: Multi-Scene CTR Prediction via Domain-Aware Deep Neural Network
- Model pruning 3: learning structured sparsity in deep neural networks
- Parameterization of JMeter performance test using CSV file
- Matlab drawing black spots on two / three-dimensional drawings
- Lnmp+wordpress to quickly build a personal website
- Leetcode 206. reverse chain list (2022.07.25)
- “尝鲜”元宇宙,周杰伦最佳拍档方文山将于7月25日官宣《华流元宇宙》
- 音视频学习(十)——ps流
- Rack server expansion memory
猜你喜欢

Parameterization of JMeter performance test using CSV file

万字长文 | 深入理解 OpenFeign 的架构原理

System architecture & microservices

Establishment and use of openstack cloud platform

【uniapp】多种支付方式封装

FTP service
![[xshell7 free download and installation]](/img/1f/7ac3e2c40c1b3ef2e7ce7403541972.png)
[xshell7 free download and installation]

Unity metaverse (II), mixamo & animator hybrid tree and animation fusion

Network ()

Deep learning model deployment
随机推荐
以太网交换安全
Logical volume management (LVM)
The difference between equals() and = =
2022.7.22DAY612
2019 ZTE touyue · model compression scheme
Devaxpress.xtraeditors.datanavigator usage
Use js to count the number of occurrences of each string in the string array, and format it into an object array.
C # use log4net to record logs (basic chapter)
Traversal mode of list, set, map, queue, deque, stack
Matlab-二/三维图上绘制黑点
Common methods of string: construction method, other methods
The difference between ArrayList and LinkedList
20220209 create a basic Servlet
Sort: merge sort and quick sort
JWT快速入门
2022-07-09 group 5 Gu Xiangquan's learning notes day02
The difference between abstract classes and interfaces
Model pruning 3: learning structured sparsity in deep neural networks
How to close the high-level port
《门锁》引爆独居安全热议 全新海报画面令人窒息