Skip to content

Commit

Permalink
Merge pull request #89 from Security-Onion-Solutions/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
TOoSmOotH authored Jan 31, 2022
2 parents d7be1d5 + 2ec42f6 commit b383034
Show file tree
Hide file tree
Showing 165 changed files with 8,408 additions and 763 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Copyright 2019 Jason Ertel (jertel). All rights reserved.
# Copyright 2020-2021 Security Onion Solutions, LLC. All rights reserved.
# Copyright 2020-2022 Security Onion Solutions, LLC. All rights reserved.
#
# This program is distributed under the terms of version 2 of the
# GNU General Public License. See LICENSE for further details.
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.kratos
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Copyright 2019 Jason Ertel (jertel). All rights reserved.
# Copyright 2020-2021 Security Onion Solutions, LLC. All rights reserved.
# Copyright 2020-2022 Security Onion Solutions, LLC. All rights reserved.
#
# This program is distributed under the terms of version 2 of the
# GNU General Public License. See LICENSE for further details.
Expand Down
22 changes: 11 additions & 11 deletions agent/agent.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2019 Jason Ertel (jertel). All rights reserved.
// Copyright 2020-2021 Security Onion Solutions, LLC. All rights reserved.
// Copyright 2020-2022 Security Onion Solutions, LLC. All rights reserved.
//
// This program is distributed under the terms of version 2 of the
// GNU General Public License. See LICENSE for further details.
Expand All @@ -17,19 +17,19 @@ import (
)

type Agent struct {
Client *web.Client
Config *config.AgentConfig
JobMgr *JobManager
stoppedChan chan bool
Version string
Client *web.Client
Config *config.AgentConfig
JobMgr *JobManager
stoppedChan chan bool
Version string
}

func NewAgent(cfg *config.AgentConfig, version string) *Agent {
agent := &Agent{
Config: cfg,
Client: web.NewClient(cfg.ServerUrl, cfg.VerifyCert),
Config: cfg,
Client: web.NewClient(cfg.ServerUrl, cfg.VerifyCert),
stoppedChan: make(chan bool, 1),
Version: version,
Version: version,
}
agent.JobMgr = NewJobManager(agent)
return agent
Expand All @@ -47,5 +47,5 @@ func (agent *Agent) Stop() {
}

func (agent *Agent) Wait() {
<- agent.stoppedChan
}
<-agent.stoppedChan
}
2 changes: 1 addition & 1 deletion agent/agent_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2019 Jason Ertel (jertel). All rights reserved.
// Copyright 2020-2021 Security Onion Solutions, LLC. All rights reserved.
// Copyright 2020-2022 Security Onion Solutions, LLC. All rights reserved.
//
// This program is distributed under the terms of version 2 of the
// GNU General Public License. See LICENSE for further details.
Expand Down
18 changes: 9 additions & 9 deletions agent/jobmanager.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2019 Jason Ertel (jertel). All rights reserved.
// Copyright 2020-2021 Security Onion Solutions, LLC. All rights reserved.
// Copyright 2020-2022 Security Onion Solutions, LLC. All rights reserved.
//
// This program is distributed under the terms of version 2 of the
// GNU General Public License. See LICENSE for further details.
Expand All @@ -12,12 +12,12 @@ package agent

import (
"errors"
"github.com/apex/log"
"github.com/security-onion-solutions/securityonion-soc/model"
"io"
"strconv"
"sync"
"time"
"github.com/apex/log"
"github.com/security-onion-solutions/securityonion-soc/model"
)

type JobManager struct {
Expand All @@ -31,10 +31,10 @@ type JobManager struct {
func NewJobManager(agent *Agent) *JobManager {
mgr := &JobManager{
agent: agent,
node: model.NewNode(agent.Config.NodeId),
node: model.NewNode(agent.Config.NodeId),
}

// Any field/value added to this list must be manually copied to the
// Any field/value added to this list must be manually copied to the
// existing node object in filedatastoreimpl.go::UpdateNode()
mgr.node.Role = agent.Config.Role
mgr.node.Description = agent.Config.Description
Expand All @@ -59,7 +59,7 @@ func (mgr *JobManager) Start() {
} else {
log.WithField("jobId", job.Id).Info("Discovered pending job")
var reader io.ReadCloser
reader, err = mgr.ProcessJob(job)
reader, err = mgr.ProcessJob(job)
if err == nil {
if reader != nil {
defer reader.Close()
Expand Down Expand Up @@ -104,7 +104,7 @@ func (mgr *JobManager) ProcessJob(job *model.Job) (io.ReadCloser, error) {
for _, processor := range mgr.jobProcessors {
reader, err = processor.ProcessJob(job, reader)
if err != nil {
log.WithError(err).WithFields(log.Fields {
log.WithError(err).WithFields(log.Fields{
"jobId": job.Id,
}).Error("Failed to process job; job processing aborted")
break
Expand All @@ -115,7 +115,7 @@ func (mgr *JobManager) ProcessJob(job *model.Job) (io.ReadCloser, error) {

func (mgr *JobManager) CleanupJob(job *model.Job) {
for _, processor := range mgr.jobProcessors {
processor.CleanupJob(job)
processor.CleanupJob(job)
}
}

Expand All @@ -131,7 +131,7 @@ func (mgr *JobManager) updateDataEpoch() {
}

func (mgr *JobManager) StreamJobResults(job *model.Job, reader io.ReadCloser) error {
resp, err := mgr.agent.Client.SendAuthorizedRequest("POST", "/api/stream?jobId=" + strconv.Itoa(job.Id), "application/octet-stream", reader)
resp, err := mgr.agent.Client.SendAuthorizedRequest("POST", "/api/stream?jobId="+strconv.Itoa(job.Id), "application/octet-stream", reader)
if resp.StatusCode != 200 {
err = errors.New("Unable to submit job results (" + strconv.Itoa(resp.StatusCode) + "): " + resp.Status)
}
Expand Down
6 changes: 3 additions & 3 deletions agent/jobprocessor.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2019 Jason Ertel (jertel). All rights reserved.
// Copyright 2020-2021 Security Onion Solutions, LLC. All rights reserved.
// Copyright 2020-2022 Security Onion Solutions, LLC. All rights reserved.
//
// This program is distributed under the terms of version 2 of the
// GNU General Public License. See LICENSE for further details.
Expand All @@ -11,13 +11,13 @@
package agent

import (
"github.com/security-onion-solutions/securityonion-soc/model"
"io"
"time"
"github.com/security-onion-solutions/securityonion-soc/model"
)

type JobProcessor interface {
ProcessJob(*model.Job, io.ReadCloser) (io.ReadCloser, error)
CleanupJob(*model.Job)
GetDataEpoch() time.Time
}
}
16 changes: 8 additions & 8 deletions cmd/sensoroni.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2019 Jason Ertel (jertel). All rights reserved.
// Copyright 2020-2021 Security Onion Solutions, LLC. All rights reserved.
// Copyright 2020-2022 Security Onion Solutions, LLC. All rights reserved.
//
// This program is distributed under the terms of version 2 of the
// GNU General Public License. See LICENSE for further details.
Expand All @@ -13,10 +13,6 @@ package main
import (
"flag"
"fmt"
"os"
"os/signal"
"syscall"
"time"
"github.com/apex/log"
"github.com/apex/log/handlers/logfmt"
"github.com/apex/log/handlers/text"
Expand All @@ -26,6 +22,10 @@ import (
"github.com/security-onion-solutions/securityonion-soc/module"
"github.com/security-onion-solutions/securityonion-soc/server"
serverModules "github.com/security-onion-solutions/securityonion-soc/server/modules"
"os"
"os/signal"
"syscall"
"time"
)

var (
Expand Down Expand Up @@ -58,10 +58,10 @@ func main() {
logFile, _ := InitLogging(cfg.LogFilename, cfg.LogLevel)
defer logFile.Close()

log.WithFields(log.Fields {
"version": cfg.Version,
log.WithFields(log.Fields{
"version": cfg.Version,
"buildTime": cfg.BuildTime,
}).Info("Version Information")
}).Info("Version Information")

moduleMgr := module.NewModuleManager()
var srv *server.Server
Expand Down
2 changes: 1 addition & 1 deletion cmd/sensoroni_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2019 Jason Ertel (jertel). All rights reserved.
// Copyright 2020-2021 Security Onion Solutions, LLC. All rights reserved.
// Copyright 2020-2022 Security Onion Solutions, LLC. All rights reserved.
//
// This program is distributed under the terms of version 2 of the
// GNU General Public License. See LICENSE for further details.
Expand Down
26 changes: 13 additions & 13 deletions config/agentconfig.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2019 Jason Ertel (jertel). All rights reserved.
// Copyright 2020-2021 Security Onion Solutions, LLC. All rights reserved.
// Copyright 2020-2022 Security Onion Solutions, LLC. All rights reserved.
//
// This program is distributed under the terms of version 2 of the
// GNU General Public License. See LICENSE for further details.
Expand All @@ -12,23 +12,23 @@ package config

import (
"errors"
"os"
"github.com/security-onion-solutions/securityonion-soc/module"
"os"
)

const DEFAULT_POLL_INTERVAL_MS = 1000

type AgentConfig struct {
NodeId string `json:"nodeId"`
Role string `json:"role"`
Description string `json:"description"`
Address string `json:"address"`
Model string `json:"model"`
ServerUrl string `json:"serverUrl"`
VerifyCert bool `json:"verifyCert"`
PollIntervalMs int `json:"pollIntervalMs"`
Modules module.ModuleConfigMap `json:"modules"`
ModuleFailuresIgnored bool `json:"moduleFailuresIgnored"`
NodeId string `json:"nodeId"`
Role string `json:"role"`
Description string `json:"description"`
Address string `json:"address"`
Model string `json:"model"`
ServerUrl string `json:"serverUrl"`
VerifyCert bool `json:"verifyCert"`
PollIntervalMs int `json:"pollIntervalMs"`
Modules module.ModuleConfigMap `json:"modules"`
ModuleFailuresIgnored bool `json:"moduleFailuresIgnored"`
}

func (config *AgentConfig) Verify() error {
Expand All @@ -43,4 +43,4 @@ func (config *AgentConfig) Verify() error {
err = errors.New("Agent.ServerUrl configuration value is required")
}
return err
}
}
2 changes: 1 addition & 1 deletion config/agentconfig_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2019 Jason Ertel (jertel). All rights reserved.
// Copyright 2020-2021 Security Onion Solutions, LLC. All rights reserved.
// Copyright 2020-2022 Security Onion Solutions, LLC. All rights reserved.
//
// This program is distributed under the terms of version 2 of the
// GNU General Public License. See LICENSE for further details.
Expand Down
67 changes: 48 additions & 19 deletions config/clientparameters.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2019 Jason Ertel (jertel). All rights reserved.
// Copyright 2020-2021 Security Onion Solutions, LLC. All rights reserved.
// Copyright 2020-2022 Security Onion Solutions, LLC. All rights reserved.
//
// This program is distributed under the terms of version 2 of the
// GNU General Public License. See LICENSE for further details.
Expand All @@ -19,6 +19,8 @@ const DEFAULT_MOST_RECENTLY_USED_LIMIT = 5
type ClientParameters struct {
HuntingParams HuntingParameters `json:"hunt"`
AlertingParams HuntingParameters `json:"alerts"`
CasesParams HuntingParameters `json:"cases"`
CaseParams CaseParameters `json:"case"`
JobParams HuntingParameters `json:"job"`
DocsUrl string `json:"docsUrl"`
CheatsheetUrl string `json:"cheatsheetUrl"`
Expand All @@ -30,6 +32,7 @@ type ClientParameters struct {
CacheExpirationMs int `json:"cacheExpirationMs"`
InactiveTools []string `json:"inactiveTools"`
Tools []ClientTool `json:"tools"`
CasesEnabled bool `json:"casesEnabled"`
}

func (config *ClientParameters) Verify() error {
Expand All @@ -39,6 +42,9 @@ func (config *ClientParameters) Verify() error {
if err := config.AlertingParams.Verify(); err != nil {
return err
}
if err := config.CasesParams.Verify(); err != nil {
return err
}
return config.JobParams.Verify()
}

Expand Down Expand Up @@ -70,6 +76,7 @@ type HuntingAction struct {
Method string `json:"method"`
Body string `json:"body"`
Options map[string]interface{} `json:"options"`
Categories []string `json:"categories"`
}

type ToggleFilter struct {
Expand All @@ -82,24 +89,24 @@ type ToggleFilter struct {
}

type HuntingParameters struct {
GroupItemsPerPage int `json:"groupItemsPerPage"`
GroupFetchLimit int `json:"groupFetchLimit"`
EventItemsPerPage int `json:"eventItemsPerPage"`
EventFetchLimit int `json:"eventFetchLimit"`
RelativeTimeValue int `json:"relativeTimeValue"`
RelativeTimeUnit int `json:"relativeTimeUnit"`
MostRecentlyUsedLimit int `json:"mostRecentlyUsedLimit"`
EventFields map[string][]string `json:"eventFields"`
QueryBaseFilter string `json:"queryBaseFilter"`
QueryToggleFilters []*ToggleFilter `json:"queryToggleFilters"`
Queries []*HuntingQuery `json:"queries"`
Actions []*HuntingAction `json:"actions"`
Advanced bool `json:"advanced"`
AckEnabled bool `json:"ackEnabled"`
EscalateEnabled bool `json:"escalateEnabled"`
}

type GridParameters struct {
GroupItemsPerPage int `json:"groupItemsPerPage"`
GroupFetchLimit int `json:"groupFetchLimit"`
EventItemsPerPage int `json:"eventItemsPerPage"`
EventFetchLimit int `json:"eventFetchLimit"`
RelativeTimeValue int `json:"relativeTimeValue"`
RelativeTimeUnit int `json:"relativeTimeUnit"`
MostRecentlyUsedLimit int `json:"mostRecentlyUsedLimit"`
EventFields map[string][]string `json:"eventFields"`
QueryBaseFilter string `json:"queryBaseFilter"`
QueryToggleFilters []*ToggleFilter `json:"queryToggleFilters"`
Queries []*HuntingQuery `json:"queries"`
Actions []*HuntingAction `json:"actions"`
Advanced bool `json:"advanced"`
AckEnabled bool `json:"ackEnabled"`
EscalateEnabled bool `json:"escalateEnabled"`
EscalateRelatedEventsEnabled bool `json:"escalateRelatedEventsEnabled"`
ViewEnabled bool `json:"viewEnabled"`
CreateLink string `json:"createLink"`
}

func (params *HuntingParameters) Verify() error {
Expand Down Expand Up @@ -131,3 +138,25 @@ func (params *HuntingParameters) combineDeprecatedLinkIntoLinks() {
}
}
}

type PresetParameters struct {
Labels []string `json:"labels"`
CustomEnabled bool `json:"customEnabled"`
}

type CaseParameters struct {
MostRecentlyUsedLimit int `json:"mostRecentlyUsedLimit"`
RenderAbbreviatedCount int `json:"renderAbbreviatedCount"`
Presets map[string]PresetParameters `json:"presets"`
}

func (params *CaseParameters) Verify() error {
var err error
if params.MostRecentlyUsedLimit < 0 {
params.MostRecentlyUsedLimit = 0
}
return err
}

type GridParameters struct {
}
Loading

0 comments on commit b383034

Please sign in to comment.