Fastjson反序列化漏洞原理分析及复现

Fastjson序列化与反序列化

常规反序列化

Fastjson的序列化与反序列化与常规的java反序列化不同,我们先来看一下正常的java反序列化,使用下面一段代码:

package com.armandhe.javabase;

import java.io.*;

public class Unserialize {
   
    public static void main(String[] args) {
   
        File file = new File("Unserilize.txt");
        try {
   

            //新建一个对象
            UnserializeTest unserializeTest = new UnserializeTest();
            unserializeTest.name = "armandhe";

            //序列化
            FileOutputStream fileOutputStream = new FileOutputStream(file);
            ObjectOutputStream outputStream = new ObjectOutputStream(fileOutputStream);
            outputStream.writeObject(unserializeTest);
            outputStream.close();
//            fileOutputStream.close();

            //反序列化
            FileInputStream fileInputStream = new FileInputStream(file);
            ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream);
            try {
   
                UnserializeTest o = (UnserializeTest) objectInputStream.readObject();
                System.out.println(o.name);
            } catch (ClassNotFoundException e) {
   
                e.printStackTrace();
            }

        } catch (IOException e) {
   
            e.printStackTrace();
        }
    }
}

class UnserializeTest implements Serializable{
   
    public String name;
    private void readObject(ObjectInputStream in) throws IOException,ClassNotFoundException{
   
        in.defaultReadObject();
        System.out.println("执行了readObject函数!!");
        Runtime.getRuntime().exec("calc.exe");
    
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值