JAVA反序列化漏洞

JAVA反序列化漏洞

原文资料 :xiu--》xiu博客

文章目录

idea

类继承

复制代码
public class Person {
    public int age;
    public String name;
    public void talk(){
    System.out.println("Person 说话了");
}
public class Student extends Person{
    public int score;
    public void talk(){
    System.out.println("Student说话了");
}
public class Test {
    public static void main (String[] args) {
    Student stul = new Student();
    stul.talk();
}

数据前五个字节

rO0AB java序列化base64编码数据

aced 16进制java序列化

复制代码
序列化:
ObjectOutputStream --> writeObject()
反序列化: 
ObjectInputStream --> readObject()  

反序列化漏洞

person类
复制代码
import java.io.I0Exception;
import java.io.0bjectInputStream;
import java.io.Serializable;

public classPerson implements Serializable {

    public int age;
    public String name;
    private void readobject (ObjectInputStream in)throws IOException, ClassNotFoundException {

    Runtime.getRuntime().exec("calc");
    // 默认的反序列化操作
    in.defaultReadObject();
    }
}
Test类
复制代码
import java.io.*;

public class Test {
    public static void main (String[] args) throws IOException,  ClassNotFoundException {
   
        Person p=new Person();
        p.age=18;
        p.name="xiu";
        serialize (p,"xiu.bin");
        System.out.println("反序列化结果:"+
        deserialize("xiu.bin"));
     }
     
    public static void serialize (Object obj, string filePath) throws IOException {
    
        try ( FileOutputStream file0ut = new File0utputStream(filePath);
        	  Object0utputStream objectOut = new Object0utputStream(fileOut)
        	){ objectOut.write0bject(obj);}
    }
    
    public static Object deserialize(String filePath) throws IOException, ClassNotFoundException {
    try (FileInputstream fileIn = new FileInputstream(filePath);
        ObjectInputstream objectIn = new ObjectInputstream(fileIn)) {
            return objectIn.read0bject();
        }
    }
}

什么是反序列化漏洞

PHP的反序列化和java的反序列化是两种不同的类型,序列化和反序列化本身没有漏洞点,只是为了实现数据的完整高效的传输,

PHP反序列漏洞是由于类里面的魔术方法调用了某个函数,该危险函数又调用了别的函数,最终执行到了危险函数的位置

JAVA反序列化漏洞是由于开发者重写了readObject方法,该readObject方法方法调用了别的方法,最终执行到了例如Transfrom方法的危险方法

相关推荐
皮皮林5511 小时前
Java性能调优黑科技!1行代码实现毫秒级耗时追踪,效率飙升300%!
java
冰_河1 小时前
QPS从300到3100:我靠一行代码让接口性能暴涨10倍,系统性能原地起飞!!
java·后端·性能优化
桦说编程4 小时前
从 ForkJoinPool 的 Compensate 看并发框架的线程补偿思想
java·后端·源码阅读
躺平大鹅6 小时前
Java面向对象入门(类与对象,新手秒懂)
java
初次攀爬者7 小时前
RocketMQ在Spring Boot上的基础使用
java·spring boot·rocketmq
花花无缺7 小时前
搞懂@Autowired 与@Resuorce
java·spring boot·后端
Derek_Smart8 小时前
从一次 OOM 事故说起:打造生产级的 JVM 健康检查组件
java·jvm·spring boot
NE_STOP9 小时前
MyBatis-mybatis入门与增删改查
java
孟陬12 小时前
国外技术周刊 #1:Paul Graham 重新分享最受欢迎的文章《创作者的品味》、本周被划线最多 YouTube《如何在 19 分钟内学会 AI》、为何我不
java·前端·后端