(ctx ModuleContext, sessionID string, taskID uint32, spite *implantpb.Spite)
| 13 | func (m *ExecModule) Name() string { return consts.ModuleExecute } |
| 14 | |
| 15 | func (m *ExecModule) Handle(ctx ModuleContext, sessionID string, taskID uint32, spite *implantpb.Spite) { |
| 16 | exec := spite.GetExecRequest() |
| 17 | if exec == nil { |
| 18 | ctx.SendSpite(sessionID, taskID, execSpite("missing ExecRequest")) |
| 19 | ctx.Tasks.Fail(sessionID, taskID, "missing ExecRequest") |
| 20 | return |
| 21 | } |
| 22 | |
| 23 | command := extractCommand(exec.Path, exec.Args) |
| 24 | |
| 25 | sess, toolName := acquireShellSession(ctx, sessionID, taskID, m.Name()) |
| 26 | if sess == nil { |
| 27 | return |
| 28 | } |
| 29 | |
| 30 | result := enqueueAndAwait(ctx, sessionID, taskID, sess, toolName, command) |
| 31 | if result == nil { |
| 32 | return |
| 33 | } |
| 34 | |
| 35 | resp := parseToolOutput(result.Output) |
| 36 | resp.End = true |
| 37 | resultSpite := &implantpb.Spite{ |
| 38 | Name: consts.ModuleExecute, |
| 39 | Body: &implantpb.Spite_ExecResponse{ExecResponse: resp}, |
| 40 | } |
| 41 | |
| 42 | if err := ctx.SendSpite(sessionID, taskID, resultSpite); err != nil { |
| 43 | log.Errorf("[bridge] failed to forward exec task %d: %v", taskID, err) |
| 44 | ctx.Tasks.Fail(sessionID, taskID, err.Error()) |
| 45 | } else { |
| 46 | log.Infof("[bridge] forwarded exec task %d result for session %s", taskID, sessionID) |
| 47 | ctx.Tasks.Complete(sessionID, taskID) |
| 48 | } |
| 49 | } |
nothing calls this directly
no test coverage detected