google / tsunami-security-scanner

Tsunami is a general purpose network security scanner with an extensible plugin system for detecting high severity vulnerabilities with high confidence.
Apache License 2.0
8.27k stars 889 forks source link

Additional RCE payloads for Tsunami scanner payload generator #110

Closed dawidg-doyen closed 2 months ago

dawidg-doyen commented 9 months ago

Hi Tsunami Team,

This PR adds 4 additional RCE payloads to the Tsunami scanner payload generator:

Testbeds

I created the following docker testbeds for testing purposes:

Example use of the payloads in detectors

linux_root_crontab

  private static final String RCE_CRON_PATH = "/etc/cron.d/tsunami_rce_cron";

  PayloadGeneratorConfig config =
        PayloadGeneratorConfig.newBuilder()
            .setVulnerabilityType(PayloadGeneratorConfig.VulnerabilityType.ARBITRARY_FILE_WRITE)
            .setInterpretationEnvironment(
                PayloadGeneratorConfig.InterpretationEnvironment.LINUX_ROOT_CRONTAB)
            .setExecutionEnvironment(
                PayloadGeneratorConfig.ExecutionEnvironment.EXEC_INTERPRETATION_ENVIRONMENT)
            .build();

 Payload payload = this.payloadGenerator.generate(config);
 String crontabEntry = payload.getPayload();

 if (payload.getPayloadAttributes().getUsesCallbackServer()) {
      // Save cron payload in /etc/cron.d/ and wait for RCE
      var unused = writeContentsToFile(networkService, RCE_CRON_PATH, crontabEntry);

      // The CRON job should execute after 1 min
      logger.atInfo().log("Waiting for RCE callback from the cronjob.");
      try {
        Thread.sleep(65000);
      } catch (InterruptedException e) {
        logger.atWarning().withCause(e).log("Failed to wait for RCE result");
      }
      return payload.checkIfExecuted();
    }

linux_curl_trace_read


   private static final String CURL_TRACE_PATH = "/tmp/tsunami-rce";

    PayloadGeneratorConfig config =
        PayloadGeneratorConfig.newBuilder()
            .setVulnerabilityType(PayloadGeneratorConfig.VulnerabilityType.BLIND_RCE_FILE_READ)
            .setInterpretationEnvironment(
                PayloadGeneratorConfig.InterpretationEnvironment.LINUX_SHELL)
            .setExecutionEnvironment(
                PayloadGeneratorConfig.ExecutionEnvironment.EXEC_INTERPRETATION_ENVIRONMENT)
            .build();

    Payload payload = this.payloadGenerator.generate(config);
    String curlPayload = payload.getPayload();
    String fileContents = "";

    // Confirm RCE with curl trace file write + read when callback server is disabled
    if (!payload.getPayloadAttributes().getUsesCallbackServer()) {

      // execute curl --trace command to inject RCE detection string into the trace log
      var unused = executeCommand(networkService, curlPayload);

      // The curl trace log should contain RCE detection string
      fileContents = readFileContents(networkService, CURL_TRACE_PATH);
      return payload.checkIfExecuted(fileContents);
    }

Both of the payloads can be tested on the provided testbeds.

Best Regards, Dawid Golunski