Skip to content

Commit

Permalink
[backend/frontend] Add possibility to launch openbas agent on docker …
Browse files Browse the repository at this point in the history
…and linux image
  • Loading branch information
RomuDeuxfois authored Sep 16, 2024
1 parent 65b004e commit f16ced6
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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<String, String> 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} &");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
}
4 changes: 2 additions & 2 deletions openbas-front/src/admin/components/agents/Agents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions openbas-front/src/utils/api-types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit f16ced6

Please sign in to comment.