Skip to content

Commit f1fe72d

Browse files
bugfix/330 manual commands not working (#331)
1 parent 49d0c92 commit f1fe72d

File tree

6 files changed

+29
-23
lines changed

6 files changed

+29
-23
lines changed

examples/manual-playbook.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
],
2323
"external_references": [
2424
{
25+
"name": "COSSAS",
2526
"description": "TNO COSSAS"
2627
}
2728
],
@@ -46,6 +47,7 @@
4647
},
4748
"on_completion": "end--a6f0b81e-affb-4bca-b4f6-a2d5af908958",
4849
"type": "action",
50+
"timeout": 100000,
4951
"commands": [
5052
{
5153
"type": "manual",
@@ -71,16 +73,16 @@
7173
"name": "soarca-manual-capability"
7274
},
7375
"soarca-manual-capability--7b0e98db-fa93-42aa-8511-e871c65131b1": {
74-
"type": "soarca-manual-capability",
75-
"name": "soarca-manual-capability",
76-
"description": "SOARCA's manual command handler"
76+
"type": "soarca-manual",
77+
"name": "soarca-manual",
78+
"description": "SOARCAs manual command handler"
7779
}
7880
},
7981
"target_definitions": {
8082
"individual--9d1f6217-34d5-435c-b29a-6a1af6b664d9": {
8183
"type": "individual",
8284
"name": "Luke Skywalker",
83-
"description": "Darth Vader's son",
85+
"description": "Darth Vaders son",
8486
"location": {
8587
"name": "Somewhere in a galaxy far far away"
8688
}

internal/controller/controller.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ import (
77
"reflect"
88
"soarca/internal/database/memory"
99
"soarca/internal/logger"
10+
1011
"soarca/pkg/core/capability"
1112
"soarca/pkg/core/capability/fin/protocol"
1213
"soarca/pkg/core/capability/http"
14+
"soarca/pkg/core/capability/manual"
1315
"soarca/pkg/core/capability/manual/interaction"
1416
"soarca/pkg/core/capability/openc2"
1517
"soarca/pkg/core/capability/powershell"
@@ -85,6 +87,9 @@ func (controller *Controller) NewDecomposer() decomposer.IDecomposer {
8587
poswershell := powershell.New()
8688
capabilities[poswershell.GetType()] = poswershell
8789

90+
man := manual.New(mainInteraction)
91+
capabilities[man.GetType()] = &man
92+
8893
enableFins, _ := strconv.ParseBool(utils.GetEnv("ENABLE_FINS", "false"))
8994

9095
if enableFins {

pkg/api/manual/manual_api.go

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ func NewManualHandler(interaction interaction.IInteractionStorage) *ManualHandle
5252

5353
// manual
5454
//
55-
// @Summary get all pending manual commands that still needs values to be returned
55+
// @Summary get all pending manual commands that still needs values to be returned
5656
// @Schemes
5757
// @Description get all pending manual commands that still needs values to be returned
5858
// @Tags manual
5959
// @Accept json
6060
// @Produce json
61-
// @Success 200 {object} api.Execution
62-
// @failure 400 {object} []api.InteractionCommandData
61+
// @Success 200 {object} api.Execution
62+
// @failure 400 {object} []api.InteractionCommandData
6363
// @Router /manual/ [GET]
6464
func (manualHandler *ManualHandler) GetPendingCommands(g *gin.Context) {
6565
commands, err := manualHandler.interactionCapability.GetPendingCommands()
@@ -82,14 +82,14 @@ func (manualHandler *ManualHandler) GetPendingCommands(g *gin.Context) {
8282

8383
// manual
8484
//
85-
// @Summary get a specific manual command that still needs a value to be returned
85+
// @Summary get a specific manual command that still needs a value to be returned
8686
// @Schemes
8787
// @Description get a specific manual command that still needs a value to be returned
8888
// @Tags manual
8989
// @Accept json
9090
// @Produce json
91-
// @Param exec_id path string true "execution ID"
92-
// @Param step_id path string true "step ID"
91+
// @Param exec_id path string true "execution ID"
92+
// @Param step_id path string true "step ID"
9393
// @Success 200 {object} api.InteractionCommandData
9494
// @failure 400 {object} api.Error
9595
// @Router /manual/{exec_id}/{step_id} [GET]
@@ -126,23 +126,17 @@ func (manualHandler *ManualHandler) GetPendingCommand(g *gin.Context) {
126126

127127
// manual
128128
//
129-
// @Summary updates the value of a variable according to the manual interaction
129+
// @Summary updates the value of a variable according to the manual interaction
130130
// @Schemes
131131
// @Description updates the value of a variable according to the manual interaction
132132
// @Tags manual
133133
// @Accept json
134134
// @Produce json
135-
// @Param exec_id path string true "execution ID"
136-
// @Param step_id path string true "step ID"
137-
// @Param type body string true "type"
138-
// @Param outArgs body string true "execution ID"
139-
// @Param execution_id body string true "playbook ID"
140-
// @Param playbook_id body string true "playbook ID"
141-
// @Param step_id body string true "step ID"
142-
// @Param response_status body string true "response status"
143-
// @Param response_out_args body cacao.Variables true "out args"
144-
// @Success 200 {object} api.Execution
145-
// @failure 400 {object} api.Error
135+
// @Param exec_id path string true "execution ID"
136+
// @Param step_id path string true "step ID"
137+
// @Param data body api.ManualOutArgsUpdatePayload true "playbook"
138+
// @Success 200 {object} api.Execution
139+
// @failure 400 {object} api.Error
146140
// @Router /manual/continue [POST]
147141
func (manualHandler *ManualHandler) PostContinue(g *gin.Context) {
148142

pkg/core/capability/manual/manual.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ var (
2020

2121
const (
2222
manualResultVariableName = "__soarca_manual_result__"
23-
manualCapabilityName = "soarca-manual-http"
23+
manualCapabilityName = "soarca-manual"
2424
fallbackTimeout = time.Minute * 1
2525
)
2626

@@ -51,6 +51,7 @@ func (manual *ManualCapability) Execute(
5151
}
5252

5353
timeout := manual.getTimeoutValue(commandContext.Step.Timeout)
54+
log.Trace("timeout is set to: ", timeout)
5455
ctx, cancel := context.WithTimeout(context.Background(), timeout)
5556
defer cancel()
5657

pkg/core/executors/action/action.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ type data struct {
4545
target cacao.AgentTarget
4646
variables cacao.Variables
4747
agent cacao.AgentTarget
48+
step cacao.Step
4849
}
4950

5051
func (executor *Executor) Execute(meta execution.Metadata,
@@ -85,6 +86,7 @@ func (executor *Executor) executeCommandFromArray(meta execution.Metadata,
8586
target: target,
8687
variables: metadata.Variables,
8788
agent: metadata.Agent,
89+
step: metadata.Step,
8890
}
8991

9092
outputVariables, err := executor.executeCommands(
@@ -156,6 +158,7 @@ func (executor *Executor) executeCommands(metadata execution.Metadata,
156158
context.Target = interpolatedTarget(data.target, data.variables)
157159
context.Authentication = interpolateAuthentication(data.authentication, data.variables)
158160
context.Variables = data.variables
161+
context.Step = data.step
159162
returnVariables, err := capability.Execute(metadata, context)
160163
return returnVariables, err
161164
} else {

pkg/core/executors/action/action_executor_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ func TestExecuteStep(t *testing.T) {
8383
Authentication: expectedAuth,
8484
Target: expectedTarget,
8585
Variables: cacao.NewVariables(expectedVariables),
86+
Step: step,
8687
}
8788

8889
layout := "2006-01-02T15:04:05.000Z"

0 commit comments

Comments
 (0)