diff --git a/openbas-api/src/main/java/io/openbas/injectors/openbas/OpenBASInjector.java b/openbas-api/src/main/java/io/openbas/injectors/openbas/OpenBASInjector.java index 22961f2bb0..c9d80ad72b 100644 --- a/openbas-api/src/main/java/io/openbas/injectors/openbas/OpenBASInjector.java +++ b/openbas-api/src/main/java/io/openbas/injectors/openbas/OpenBASInjector.java @@ -20,7 +20,7 @@ public class OpenBASInjector { private static final String OPENBAS_INJECTOR_ID = "49229430-b5b5-431f-ba5b-f36f599b0144"; private String dlUri(OpenBASConfig openBASConfig, String platform, String arch) { - return openBASConfig.getBaseUrl() + "/api/implant/openbas/" + platform + "/" + arch; + return openBASConfig.getBaseUrlForAgent() + "/api/implant/openbas/" + platform + "/" + arch; } @SuppressWarnings("SameParameterValue") @@ -31,7 +31,7 @@ private String dlVar(OpenBASConfig openBASConfig, String platform, String arch) @Autowired public OpenBASInjector(InjectorService injectorService, OpenBASImplantContract contract, OpenBASConfig openBASConfig) { String tokenVar = "token=\"" + openBASConfig.getAdminToken() + "\""; - String serverVar = "server=\"" + openBASConfig.getBaseUrl() + "\""; + String serverVar = "server=\"" + openBASConfig.getBaseUrlForAgent() + "\""; Map executorCommands = new HashMap<>(); executorCommands.put(Endpoint.PLATFORM_TYPE.Windows.name() + "." + Endpoint.PLATFORM_ARCH.x86_64, "$x=\"#{location}\";$location=$x.Replace(\"\\obas-agent-caldera.exe\", \"\");[Environment]::CurrentDirectory = $location;$filename=\"obas-implant-#{inject}.exe\";$" + tokenVar + ";$" + serverVar + ";" + dlVar(openBASConfig, "windows", "x86_64") + ";$wc=New-Object System.Net.WebClient;$data=$wc.DownloadData($url);[io.file]::WriteAllBytes($filename,$data) | Out-Null;Remove-NetFirewallRule -DisplayName \"Allow OpenBAS Inbound\";New-NetFirewallRule -DisplayName \"Allow OpenBAS Inbound\" -Direction Inbound -Program \"$location\\$filename\" -Action Allow | Out-Null;Remove-NetFirewallRule -DisplayName \"Allow OpenBAS Outbound\";New-NetFirewallRule -DisplayName \"Allow OpenBAS Outbound\" -Direction Outbound -Program \"$location\\$filename\" -Action Allow | Out-Null;Start-Process -FilePath \"$location\\$filename\" -ArgumentList \"--uri $server --token $token --inject-id #{inject}\" -WindowStyle hidden;"); executorCommands.put(Endpoint.PLATFORM_TYPE.Linux.name() + "." + Endpoint.PLATFORM_ARCH.x86_64, "x=\"#{location}\";location=$(echo \"$x\" | sed \"s#/openbas-caldera-agent##\");filename=obas-implant-#{inject};" + serverVar + ";" + tokenVar + ";curl -s -X GET " + dlUri(openBASConfig, "linux", "x86_64") + " > $location/$filename;chmod +x $location/$filename;$location/$filename --uri $server --token $token --inject-id #{inject} &"); diff --git a/openbas-api/src/main/java/io/openbas/rest/settings/response/PlatformSettings.java b/openbas-api/src/main/java/io/openbas/rest/settings/response/PlatformSettings.java index 09bb9d53fd..00fc74e828 100644 --- a/openbas-api/src/main/java/io/openbas/rest/settings/response/PlatformSettings.java +++ b/openbas-api/src/main/java/io/openbas/rest/settings/response/PlatformSettings.java @@ -3,14 +3,16 @@ import com.fasterxml.jackson.annotation.JsonProperty; import io.openbas.rest.settings.form.PolicyInput; import io.openbas.rest.settings.form.ThemeInput; -import lombok.*; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import static java.util.Optional.ofNullable; import static lombok.AccessLevel.NONE; @Setter @@ -25,6 +27,9 @@ public class PlatformSettings { @JsonProperty("platform_base_url") private String platformBaseUrl; + @JsonProperty("platform_agent_url") + private String platformAgentUrl; + @JsonProperty("platform_theme") private String platformTheme; diff --git a/openbas-api/src/main/java/io/openbas/service/PlatformSettingsService.java b/openbas-api/src/main/java/io/openbas/service/PlatformSettingsService.java index dd64898741..df3982e46a 100644 --- a/openbas-api/src/main/java/io/openbas/service/PlatformSettingsService.java +++ b/openbas-api/src/main/java/io/openbas/service/PlatformSettingsService.java @@ -192,6 +192,7 @@ public PlatformSettings findSettings() { ofNullable(dbSettings.get(PLATFORM_NAME.key())).map(Setting::getValue).orElse(PLATFORM_NAME.defaultValue()) ); platformSettings.setPlatformBaseUrl(openBASConfig.getBaseUrl()); + platformSettings.setPlatformAgentUrl(openBASConfig.getBaseUrlForAgent()); platformSettings.setXtmOpenctiEnable(openCTIConfig.getEnable()); platformSettings.setXtmOpenctiUrl(openCTIConfig.getUrl()); platformSettings.setAiEnabled(aiConfig.isEnabled()); diff --git a/openbas-framework/src/main/java/io/openbas/asset/EndpointService.java b/openbas-framework/src/main/java/io/openbas/asset/EndpointService.java index 6252443368..8d1242915a 100644 --- a/openbas-framework/src/main/java/io/openbas/asset/EndpointService.java +++ b/openbas-framework/src/main/java/io/openbas/asset/EndpointService.java @@ -108,7 +108,7 @@ public String getFileOrDownloadFromJfrog(String platform, String file, String ad in = new BufferedInputStream(new URL(JFROG_BASE + resourcePath + filename).openStream()); } return IOUtils.toString(in, StandardCharsets.UTF_8) - .replace("${OPENBAS_URL}", openBASConfig.getBaseUrl()) + .replace("${OPENBAS_URL}", openBASConfig.getBaseUrlForAgent()) .replace("${OPENBAS_TOKEN}", adminToken); } diff --git a/openbas-framework/src/main/java/io/openbas/config/OpenBASConfig.java b/openbas-framework/src/main/java/io/openbas/config/OpenBASConfig.java index 6d79cdc6c5..91ccbe2d40 100644 --- a/openbas-framework/src/main/java/io/openbas/config/OpenBASConfig.java +++ b/openbas-framework/src/main/java/io/openbas/config/OpenBASConfig.java @@ -2,11 +2,14 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; +import jakarta.validation.constraints.NotBlank; import lombok.Data; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; +import static org.springframework.util.StringUtils.hasText; + @Component @ConfigurationProperties(prefix = "openbas") @Data @@ -64,8 +67,20 @@ public class OpenBASConfig { @JsonIgnore private boolean cookieSecure = false; - public String getBaseUrl() { - return baseUrl.endsWith("/") ? baseUrl.substring(0, baseUrl.length() - 1) : baseUrl; + return url(baseUrl); + } + + @JsonProperty("application_agent_url") + private String agentUrl; + + public String getBaseUrlForAgent() { + return hasText(agentUrl) ? url(agentUrl) :url(baseUrl); + } + + // -- PRIVATE -- + + private String url(@NotBlank final String url) { + return url.endsWith("/") ? url.substring(0, url.length() - 1) : url; } } diff --git a/openbas-front/src/admin/components/agents/Agents.tsx b/openbas-front/src/admin/components/agents/Agents.tsx index db26aff757..0183bc2ac8 100644 --- a/openbas-front/src/admin/components/agents/Agents.tsx +++ b/openbas-front/src/admin/components/agents/Agents.tsx @@ -226,8 +226,8 @@ MD5: d604c952bb3c6d96621594d39992c499 SHA1: 5b6087f87f5f2ae129f888bba799611836eb39a2 SHA256: 98d1e64445bbef46a36d4724699a386646de78881a1b6f2b346122c76d696c12 SHA512: ca07dc1d0a5297e29327e483f4f35dadb254d96a16a5c33da5ad048e6965a3863d621518a2be40f1a42226c68cbf5e779382a37ee5baa7dd7c538ec73ce059e8`, - displayedCode: `curl -s ${settings.platform_base_url}/api/agent/installer/openbas/linux/${userToken?.token_value} | sudo sh`, - code: `curl -s ${settings.platform_base_url}/api/agent/installer/openbas/linux/${userToken?.token_value} | sudo sh`, + displayedCode: `curl -s ${settings.platform_agent_url}/api/agent/installer/openbas/linux/${userToken?.token_value} | sudo sh`, + code: `curl -s ${settings.platform_agent_url}/api/agent/installer/openbas/linux/${userToken?.token_value} | sudo sh`, }; case 'macos': return { diff --git a/openbas-front/src/utils/api-types.d.ts b/openbas-front/src/utils/api-types.d.ts index 39caa3f48e..1b3ab66e4f 100644 --- a/openbas-front/src/utils/api-types.d.ts +++ b/openbas-front/src/utils/api-types.d.ts @@ -2473,6 +2473,7 @@ export interface PlatformSettings { java_version?: string; map_tile_server_dark?: string; map_tile_server_light?: string; + platform_agent_url?: string; platform_ai_enabled?: boolean; platform_ai_has_token?: boolean; platform_ai_model?: string;