Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/core/capability/capability.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

type Context struct {
Command cacao.Command
CommandData cacao.CommandData
Step cacao.Step
Authentication cacao.AuthenticationInformation
Target cacao.AgentTarget
Expand Down
2 changes: 1 addition & 1 deletion pkg/core/capability/fin/fin.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (finCapability *FinCapability) Execute(
context capability.Context) (cacao.Variables, error) {

finCommand := finModel.NewCommand()
finCommand.CommandSubstructure.Command = context.Command.Command
finCommand.CommandSubstructure.Command = context.CommandData.Command
finCommand.CommandSubstructure.Authentication = context.Authentication
finCommand.CommandSubstructure.Variables = context.Variables
finCommand.CommandSubstructure.Context.ExecutionId = metadata.ExecutionId.String()
Expand Down
4 changes: 2 additions & 2 deletions pkg/core/capability/fin/fin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestFinExecution(t *testing.T) {

var metadata = execution.Metadata{ExecutionId: executionId, PlaybookId: playbookId.String(), StepId: stepId.String()}

command := cacao.Command{Type: "soarca-fin", Command: "test command"}
command := cacao.CommandData{Type: "soarca-fin", Command: "test command"}
auth := cacao.AuthenticationInformation{}
auth.Name = "some auth"
auth.Username = "user"
Expand Down Expand Up @@ -52,7 +52,7 @@ func TestFinExecution(t *testing.T) {
expectedVariableMap := cacao.NewVariables(variable1)

data := capability.Context{
Command: command,
CommandData: command,
Authentication: auth,
Target: target,
Variables: inputVariable,
Expand Down
2 changes: 1 addition & 1 deletion pkg/core/capability/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (httpCapability *HttpCapability) Execute(

soarca_http_options := http.HttpOptions{
Target: &context.Target,
Command: &context.Command,
Command: &context.CommandData,
Auth: &context.Authentication,
}

Expand Down
12 changes: 6 additions & 6 deletions pkg/core/capability/http/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestHTTPOptionsCorrectlyGenerated(t *testing.T) {
target := cacao.AgentTarget{Address: map[cacao.NetAddressType][]string{
"url": {"https://httpbin.org/post"},
}}
command := cacao.Command{
command := cacao.CommandData{
Type: "http-api",
Command: "POST / HTTP/1.1",
Headers: map[string][]string{"accept": {"application/json"}},
Expand Down Expand Up @@ -58,7 +58,7 @@ func TestHTTPOptionsCorrectlyGenerated(t *testing.T) {
mock_http_request.On("Request", httpOptions).Return(payload_byte, nil)

data := capability.Context{
Command: command,
CommandData: command,
Authentication: oauth2_info,
Target: target,
Variables: cacao.NewVariables(variable1),
Expand All @@ -84,7 +84,7 @@ func TestHTTPOptionsEmptyAuth(t *testing.T) {
target := cacao.AgentTarget{Address: map[cacao.NetAddressType][]string{
"url": {"https://httpbin.org/post"},
}}
command := cacao.Command{
command := cacao.CommandData{
Type: "http-api",
Command: "POST / HTTP/1.1",
Headers: map[string][]string{"accept": {"application/json"}},
Expand Down Expand Up @@ -113,7 +113,7 @@ func TestHTTPOptionsEmptyAuth(t *testing.T) {
mock_http_request.On("Request", httpOptions).Return(payload_byte, nil)

data := capability.Context{
Command: command,
CommandData: command,
Authentication: *empty_auth,
Target: target,
Variables: cacao.NewVariables(variable1),
Expand All @@ -139,7 +139,7 @@ func TestHTTPOptionsEmptyCommand(t *testing.T) {
target := cacao.AgentTarget{Address: map[cacao.NetAddressType][]string{
"url": {"https://httpbin.org/post"},
}}
empty_command := new(cacao.Command)
empty_command := new(cacao.CommandData)

var oauth2_info = cacao.AuthenticationInformation{
ID: "6ba7b810-9dad-11d1-80b4-00c04fd430c9",
Expand Down Expand Up @@ -168,7 +168,7 @@ func TestHTTPOptionsEmptyCommand(t *testing.T) {
mock_http_request.On("Request", httpOptions).Return([]byte{}, expected_error)

data := capability.Context{
Command: *empty_command,
CommandData: *empty_command,
Authentication: oauth2_info,
Target: target,
Variables: cacao.NewVariables(variable1),
Expand Down
2 changes: 1 addition & 1 deletion pkg/core/capability/openc2/openc2.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (OpenC2Capability *OpenC2Capability) Execute(
log.Trace(metadata.ExecutionId)

httpOptions := http.HttpOptions{
Command: &context.Command,
Command: &context.CommandData,
Target: &context.Target,
Auth: &context.Authentication,
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/core/capability/openc2/openc2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestOpenC2Request(t *testing.T) {
Token: "this-is-a-test",
}

command := cacao.Command{
command := cacao.CommandData{
Type: "http-api",
Command: "POST / HTTP/1.1",
Headers: map[string][]string{"accept": {"application/json"}},
Expand Down Expand Up @@ -65,7 +65,7 @@ func TestOpenC2Request(t *testing.T) {

mockHttp.On("Request", httpOptions).Return(payloadBytes, nil)

data := capability.Context{Command: command,
data := capability.Context{CommandData: command,
Authentication: auth,
Target: target,
Variables: cacao.NewVariables(cacaoVariable)}
Expand Down
6 changes: 3 additions & 3 deletions pkg/core/capability/powershell/powershell.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ func (capability *PowershellCapability) Execute(
defer cancel()

effectiveCommand := ""
if capabilityContext.Command.CommandB64 != "" {
bytes, err := base64.StdEncoding.DecodeString(capabilityContext.Command.CommandB64)
if capabilityContext.CommandData.CommandB64 != "" {
bytes, err := base64.StdEncoding.DecodeString(capabilityContext.CommandData.CommandB64)
if err != nil {
return cacao.NewVariables(), err
}
effectiveCommand = string(bytes)
} else {
effectiveCommand = capabilityContext.Command.Command
effectiveCommand = capabilityContext.CommandData.Command
}

result, stdErr, _, err := client.RunPSWithContext(ctx, effectiveCommand)
Expand Down
6 changes: 3 additions & 3 deletions pkg/core/capability/ssh/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ func (sshCapability *SshCapability) Execute(metadata execution.Metadata,
context capability.Context) (cacao.Variables, error) {

log.Trace(metadata.ExecutionId)
return execute(context.Command, context.Authentication, context.Target)
return execute(context.CommandData, context.Authentication, context.Target)
}

func execute(command cacao.Command,
func execute(command cacao.CommandData,
authentication cacao.AuthenticationInformation,
target cacao.AgentTarget) (cacao.Variables, error) {

Expand All @@ -64,7 +64,7 @@ func execute(command cacao.Command,
}

func executeCommand(session *ssh.Session,
command cacao.Command) (cacao.Variables, error) {
command cacao.CommandData) (cacao.Variables, error) {

response, err := session.Output(StripSshPrepend(command.Command))

Expand Down
50 changes: 25 additions & 25 deletions pkg/core/decomposer/decomposer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestExecutePlaybook(t *testing.T) {
mock_reporter := new(mock_reporter.Mock_Reporter)
mock_time := new(mock_time.MockTime)

expectedCommand := cacao.Command{
expectedCommand := cacao.CommandData{
Type: "ssh",
Command: "ssh ls -la",
}
Expand All @@ -51,7 +51,7 @@ func TestExecutePlaybook(t *testing.T) {
ID: "action--test",
Name: "ssh-tests",
StepVariables: cacao.NewVariables(expectedVariables),
Commands: []cacao.Command{expectedCommand},
Commands: []cacao.CommandData{expectedCommand},
Cases: map[string]string{},
OnCompletion: "end--test",
Agent: "agent1",
Expand Down Expand Up @@ -137,12 +137,12 @@ func TestExecutePlaybookMultiStep(t *testing.T) {
mock_reporter := new(mock_reporter.Mock_Reporter)
mock_time := new(mock_time.MockTime)

expectedCommand := cacao.Command{
expectedCommand := cacao.CommandData{
Type: "ssh",
Command: "ssh ls -la",
}

expectedCommand2 := cacao.Command{
expectedCommand2 := cacao.CommandData{
Type: "ssh2",
Command: "ssh pwd",
}
Expand Down Expand Up @@ -171,7 +171,7 @@ func TestExecutePlaybookMultiStep(t *testing.T) {
ID: "action--test",
Name: "ssh-tests",
StepVariables: cacao.NewVariables(expectedVariables),
Commands: []cacao.Command{expectedCommand},
Commands: []cacao.CommandData{expectedCommand},
Cases: map[string]string{},
OnCompletion: "action--test2",
Agent: "agent1",
Expand All @@ -184,7 +184,7 @@ func TestExecutePlaybookMultiStep(t *testing.T) {
ID: "action--test2",
Name: "ssh-tests",
StepVariables: cacao.NewVariables(expectedVariables2),
Commands: []cacao.Command{expectedCommand2},
Commands: []cacao.CommandData{expectedCommand2},
Cases: map[string]string{},
Agent: "agent1",
Targets: []string{"target1"},
Expand All @@ -195,7 +195,7 @@ func TestExecutePlaybookMultiStep(t *testing.T) {
ID: "action--test3",
Name: "ssh-tests",
StepVariables: cacao.NewVariables(expectedVariables2),
Commands: []cacao.Command{expectedCommand},
Commands: []cacao.CommandData{expectedCommand},
Agent: "agent1",
// Targets: []string{"target1"},
}
Expand Down Expand Up @@ -293,7 +293,7 @@ func TestExecuteEmptyMultiStep(t *testing.T) {
mock_reporter := new(mock_reporter.Mock_Reporter)
mock_time := new(mock_time.MockTime)

expectedCommand := cacao.Command{
expectedCommand := cacao.CommandData{
Type: "ssh",
Command: "ssh ls -la",
}
Expand Down Expand Up @@ -327,7 +327,7 @@ func TestExecuteEmptyMultiStep(t *testing.T) {
Name: "ssh-tests",
Agent: "agent1",
StepVariables: cacao.NewVariables(expectedVariables),
Commands: []cacao.Command{expectedCommand},
Commands: []cacao.CommandData{expectedCommand},
Cases: map[string]string{},
OnCompletion: "", // Empty
}
Expand Down Expand Up @@ -375,17 +375,17 @@ func TestFailingStepResultsInFailingPlaybook(t *testing.T) {
mock_reporter := new(mock_reporter.Mock_Reporter)
mock_time := new(mock_time.MockTime)

expectedCommand := cacao.Command{
expectedCommand := cacao.CommandData{
Type: "ssh",
Command: "ssh ls -la",
}

expectedCommand2 := cacao.Command{
expectedCommand2 := cacao.CommandData{
Type: "ssh",
Command: "ssh pwd",
}

expectedCommand3 := cacao.Command{
expectedCommand3 := cacao.CommandData{
Type: "ssh",
Command: "ssh breakeverything.exe",
}
Expand Down Expand Up @@ -420,7 +420,7 @@ func TestFailingStepResultsInFailingPlaybook(t *testing.T) {
ID: "action--test",
Name: "ssh-tests",
StepVariables: cacao.NewVariables(expectedVariables),
Commands: []cacao.Command{expectedCommand},
Commands: []cacao.CommandData{expectedCommand},
Cases: map[string]string{},
OnCompletion: "action--test2",
Agent: "agent1",
Expand All @@ -432,7 +432,7 @@ func TestFailingStepResultsInFailingPlaybook(t *testing.T) {
ID: "action--test2",
Name: "ssh-tests",
StepVariables: cacao.NewVariables(expectedVariables2),
Commands: []cacao.Command{expectedCommand2},
Commands: []cacao.CommandData{expectedCommand2},
Cases: map[string]string{},
Agent: "agent1",
Targets: []string{"target1"},
Expand All @@ -443,7 +443,7 @@ func TestFailingStepResultsInFailingPlaybook(t *testing.T) {
ID: "action--test3",
Name: "ssh-tests",
StepVariables: cacao.NewVariables(expectedVariables2),
Commands: []cacao.Command{expectedCommand3},
Commands: []cacao.CommandData{expectedCommand3},
Agent: "agent1",
Targets: []string{"target1"},
OnCompletion: "end--test",
Expand Down Expand Up @@ -554,7 +554,7 @@ func TestExecuteIllegalMultiStep(t *testing.T) {
mock_reporter := new(mock_reporter.Mock_Reporter)
mock_time := new(mock_time.MockTime)

expectedCommand := cacao.Command{
expectedCommand := cacao.CommandData{
Type: "ssh",
Command: "ssh ls -la",
}
Expand All @@ -577,7 +577,7 @@ func TestExecuteIllegalMultiStep(t *testing.T) {
ID: "action--test",
Name: "ssh-tests",
StepVariables: cacao.NewVariables(expectedVariables),
Commands: []cacao.Command{expectedCommand},
Commands: []cacao.CommandData{expectedCommand},
Cases: map[string]string{},
OnCompletion: "action-some-non-existing",
}
Expand Down Expand Up @@ -705,7 +705,7 @@ func TestExecuteIfCondition(t *testing.T) {
Value: "testing2",
}

expectedCommand := cacao.Command{
expectedCommand := cacao.CommandData{
Type: "ssh",
Command: "ssh ls -la",
}
Expand Down Expand Up @@ -743,7 +743,7 @@ func TestExecuteIfCondition(t *testing.T) {
Type: cacao.StepTypeAction,
ID: "action--step-true",
Name: "ssh-tests",
Commands: []cacao.Command{expectedCommand},
Commands: []cacao.CommandData{expectedCommand},
Targets: []string{expectedTarget.ID},
StepVariables: cacao.NewVariables(expectedVariables),
OnCompletion: endTrue.ID,
Expand All @@ -759,7 +759,7 @@ func TestExecuteIfCondition(t *testing.T) {
Type: cacao.StepTypeAction,
ID: "action--step-false",
Name: "ssh-tests",
Commands: []cacao.Command{expectedCommand},
Commands: []cacao.CommandData{expectedCommand},
Targets: []string{expectedTarget.ID},
StepVariables: cacao.NewVariables(expectedVariables),
OnCompletion: endFalse.ID,
Expand All @@ -769,7 +769,7 @@ func TestExecuteIfCondition(t *testing.T) {
Type: cacao.StepTypeAction,
ID: "action--step-completion",
Name: "ssh-tests",
Commands: []cacao.Command{expectedCommand},
Commands: []cacao.CommandData{expectedCommand},
Targets: []string{expectedTarget.ID},
StepVariables: cacao.NewVariables(expectedVariables),
OnCompletion: end.ID,
Expand Down Expand Up @@ -877,7 +877,7 @@ func TestDelayStepExecution(t *testing.T) {
mock_reporter := new(mock_reporter.Mock_Reporter)
mock_time := new(mock_time.MockTime)

expectedCommand := cacao.Command{
expectedCommand := cacao.CommandData{
Type: "ssh",
Command: "ssh ls -la",
}
Expand All @@ -893,7 +893,7 @@ func TestDelayStepExecution(t *testing.T) {
ID: "action--test",
Name: "ssh-tests",
StepVariables: cacao.NewVariables(expectedVariables),
Commands: []cacao.Command{expectedCommand},
Commands: []cacao.CommandData{expectedCommand},
Cases: map[string]string{},
OnCompletion: "end--test",
Agent: "agent1",
Expand Down Expand Up @@ -931,7 +931,7 @@ func TestDelayStepNegativeTimeExecution(t *testing.T) {
mock_reporter := new(mock_reporter.Mock_Reporter)
mock_time := new(mock_time.MockTime)

expectedCommand := cacao.Command{
expectedCommand := cacao.CommandData{
Type: "ssh",
Command: "ssh ls -la",
}
Expand All @@ -947,7 +947,7 @@ func TestDelayStepNegativeTimeExecution(t *testing.T) {
ID: "action--test",
Name: "ssh-tests",
StepVariables: cacao.NewVariables(expectedVariables),
Commands: []cacao.Command{expectedCommand},
Commands: []cacao.CommandData{expectedCommand},
Cases: map[string]string{},
OnCompletion: "end--test",
Agent: "agent1",
Expand Down
Loading