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

``
边栏推荐
- MySQL之执行计划
- Common methods of string: construction method, other methods
- Hystrix配置简单说明
- DADNN: Multi-Scene CTR Prediction via Domain-Aware Deep Neural Network
- 2022-07-08 group 5 Gu Xiangquan's learning notes day01
- Practice of online question feedback module (XIV): realize online question answering function
- Wrong Addition
- PyTorch
- Implementation class under map interface
- Dynamic performance view overview
猜你喜欢
随机推荐
系统架构&微服务
Practice of online question feedback module (XIV): realize online question answering function
爬虫->TpImgspider
Summary of distributed related interview questions
数据库基础
LeetCode剑指offer专项(一)整数
Web page basic label
Leetcode sword finger offer special (I) integer
万字长文 | 深入理解 OpenFeign 的架构原理
utils 连接池
Excel file parsing
The analysis, solution and development of the problem of router dropping frequently
Table fix specific rows
The idea of stack simulating queue
Selenium: detailed explanation of browser crawler use (I)
The difference between FileInputStream and bufferedinputstream
C # use log4net to record logs (basic chapter)
Rack server expansion memory
[uniapp] encapsulation of multiple payment methods
How to determine the authenticity of the website you visit -- certificate system








