Eki's blog Eki's blog
Home
  • Library

    • PHP
    • JAVA
    • Node
    • Python
  • Contest

    • D3CTF 2021 Write Up
    • 虎符CTF2021
    • 2021 红帽 Web Write Up
  • Problem Set

    • Ethernaut Write Up
Pentest
Develop
  • Friends
About
  • Website
  • Tools
  • Categories
  • Tags
  • Archives
GitHub (opens new window)

Eki

Dreamer of Dreams
Home
  • Library

    • PHP
    • JAVA
    • Node
    • Python
  • Contest

    • D3CTF 2021 Write Up
    • 虎符CTF2021
    • 2021 红帽 Web Write Up
  • Problem Set

    • Ethernaut Write Up
Pentest
Develop
  • Friends
About
  • Website
  • Tools
  • Categories
  • Tags
  • Archives
GitHub (opens new window)
  • Catalogue

  • 隐写术
  • PHP

  • protocol
  • Java

    • class
    • JNDI注入
    • serialize
      • JSON
        • Fastjson
        • Jackson
    • springboot
    • misc
  • Node

  • Python

  • Golang

  • Arbitrary Code Execution
  • Shell
  • SQLi
  • SSRF
  • SSTI
  • lfi
  • XSS
  • XXE
  • convert
  • .htaccess文件利用
  • 序列化与反序列化问题小结
  • CTF
  • Java
Eki
2021-05-10
目录

serialize

# java序列化

# JSON

# Fastjson

fastjson 在autoType反序列化时会调用反序列化类的一些is|getter|setter方法,从而触发反序列化

# 参考资料

Fastjson 反序列化漏洞史 https://paper.seebug.org/1192

# Jackson

Jackson是一个非常流行且高效的基于Java的库,用于将Java对象序列化或映射到JSON和XML,也可以将JSON和XML转换为Java对象。在Druid也有对其的依赖。

jaskson有个bug特性

在这个漏洞中利用了Jackson的一个(特性)BUG

这个Bug出在Jackson的两个注释上

  1. @JsonCreator

    在于对用JsonCreator注解修饰的方法来说,方法的所有参数都会解析成CreatorProperty类型,对于没有使用JsonProperty注解修饰的参数来说,会创建一个name为””的CreatorProperty,在用户传入键为””的json对象时就会被解析到对应的参数上。

  2. @JacksonInject 假设json字段有一些缺少的属性,抓换成实体类的时候没有的属性将为null,但是我们在某些需求当中需要将为null的属性都设置为默认值,这时候我们就可以用到这个注解了,它的功能就是在反序列化的时候将没有的字段设置为我们设置好的默认值。

具体可以编写下面的示例代码

package com.example.demo;


import com.fasterxml.jackson.annotation.JacksonInject;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;


public class DemoApplication {

    public static void main(String[] args) throws JsonProcessingException {

        String json= "{\"name\":\"Jack\",\"\":\"Nofield\"}";

        ObjectMapper mapper = new ObjectMapper();
        Student result = mapper.readValue(json, Student.class);
        System.out.print(mapper.writeValueAsString(result));
    }

}

class Student {
    @JsonCreator
    public Student(
            @JsonProperty("name")String name,
            @JacksonInject String id
    ){
        this.name=name;
        this.id=id;
    }

    private String id;
    private String name;
    public String getName() {return name;}

    public String getId() {return id;}
    public void setId(String id) {this.id = id;}

}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41

运行输出

{"name":"Jack","id":"Nofield"}
1

可以看到json串中键为空的值被赋值到了id属性上,这是因为JsonCreator给id设置的键为空,JsonInject将json串中空键对应的值Nofield赋给了id

编辑 (opens new window)
上次更新: 2021/05/11, 08:36:49
JNDI注入
springboot

← JNDI注入 springboot→

最近更新
01
QWB CTF2022 线下赛总决赛部分题解
08-25
02
CISCN2022 总决赛部分题解
08-25
03
DSCTF2022决赛 部分writeup
08-08
更多文章>
Theme by Vdoing | Copyright © 2019-2022 EkiXu | Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License.
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式