collectors

package
v0.4.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 25, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package collectors gathers related logs from a SIEM after a simulation runs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Collector

type Collector interface {
	// Collect searches for logs matching the configured query and indicators,
	// and writes them to the output file. This is called once at the end of
	// scenario execution (when expectations pass or timeout is reached).
	// It returns the number of documents collected and any error that occurred.
	Collect(ctx context.Context, indicators map[string]string) (int, error)

	// String returns the textual, user-friendly representation of the collector
	String() string

	// GetOutputPath returns the path where the collected logs are stored
	GetOutputPath() string
}

Collector is an interface that every collector should implement to collect logs produced by attack activity for further analysis

type ElasticCollector

type ElasticCollector struct {
	Config         *ElasticCollectorConfig
	ScenarioConfig *ElasticCollectorScenarioConfig
	Scenario       string
	// contains filtered or unexported fields
}

ElasticCollector collects logs from Elasticsearch based on scenario indicators

func NewElasticCollector

func NewElasticCollector(config *ElasticCollectorConfig, scenarioConfig *ElasticCollectorScenarioConfig, scenario string) *ElasticCollector

NewElasticCollector creates a new ElasticCollector

func (*ElasticCollector) Collect

func (c *ElasticCollector) Collect(ctx context.Context, indicators map[string]string) (int, error)

Collect searches for logs matching the configured query and indicators, and writes them to the output file. Returns the number of documents collected.

func (*ElasticCollector) GetOutputPath

func (c *ElasticCollector) GetOutputPath() string

GetOutputPath returns the path where the collected logs are stored

func (*ElasticCollector) String

func (c *ElasticCollector) String() string

String returns the textual representation of the collector

type ElasticCollectorConfig

type ElasticCollectorConfig struct {
	ElasticsearchURL string `json:"elasticsearchUrl" yaml:"elasticsearchUrl"`
	CloudID          string `json:"cloudId" yaml:"cloudId"` // alternative to ElasticsearchURL
	APIKey           string `json:"apiKey" yaml:"apiKey"`
	OutputDir        string `json:"outputDir" yaml:"outputDir"` // default: "logs"
	// UserAgentField is the field used to search for user-agent containing detonation UUID
	UserAgentField string `json:"userAgentField" yaml:"userAgentField"`
}

ElasticCollectorConfig holds the configuration for Elastic collector from config file

func LoadElasticCollectorConfig

func LoadElasticCollectorConfig(envVars map[string]string) *ElasticCollectorConfig

LoadElasticCollectorConfig builds the collector configuration from a run-specific env-var map. The caller is responsible for populating envVars from a resolved Elastic connector (post-Phase 4) or from inherited process env (transitional CLI path). Pass nil for a zero-valued config.

Recognised keys:

  • SR_ELASTIC_URL, SR_ELASTIC_CLOUD_ID, SR_ELASTIC_API_KEY
  • SR_COLLECTOR_OUTPUT_DIR (defaults to "./logs")
  • SR_COLLECTOR_USER_AGENT_FIELD (defaults to "user_agent.original")

type ElasticCollectorScenarioConfig

type ElasticCollectorScenarioConfig struct {
	Index string `json:"index" yaml:"index"`
	// AdditionalFields values can be templates like "{{ indicators.terraformOutput.key }}"
	AdditionalFields map[string]string `json:"additionalFields,omitempty" yaml:"additionalFields,omitempty"`
}

ElasticCollectorScenarioConfig holds the per-scenario collector configuration

type ElasticSearchHit

type ElasticSearchHit struct {
	ID     string                 `json:"_id"`
	Index  string                 `json:"_index"`
	Source map[string]interface{} `json:"_source"`
}

ElasticSearchHit represents a single hit from Elasticsearch

type ElasticSearchResponse

type ElasticSearchResponse struct {
	Took int `json:"took"`
	Hits struct {
		Total struct {
			Value int `json:"value"`
		} `json:"total"`
		Hits []ElasticSearchHit `json:"hits"`
	} `json:"hits"`
}

ElasticSearchResponse represents the response from Elasticsearch search API

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL