Skip to content

Commit

Permalink
Solve static analysis findings
Browse files Browse the repository at this point in the history
  • Loading branch information
christophetd committed Aug 2, 2024
1 parent a95d8a2 commit e8819bc
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 25 deletions.
2 changes: 1 addition & 1 deletion cmd/grimoire/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (m *ShellCommand) Validate() error {
}
func (m *ShellCommand) Do() error {
ctx, cancel := context.WithCancel(context.Background())
sigChan := make(chan os.Signal)
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, os.Interrupt, syscall.SIGTERM)
go func() {
select {
Expand Down
22 changes: 2 additions & 20 deletions cmd/grimoire/stratus-red-team.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"context"
"encoding/json"
"errors"
"fmt"
"github.com/aws/aws-sdk-go-v2/config"
Expand Down Expand Up @@ -117,11 +116,11 @@ func (m *RunCommand) Do() error {
}

// Make sure we wait until cleanup is finished before exiting
if m.cleanupRunning.Load() == true {
if m.cleanupRunning.Load() {
log.Info("Waiting for Stratus Red Team attack technique clean-up to complete...")
}
m.cleanupWg.Wait()
if m.cleanupSucceeded.Load() == false {
if m.cleanupSucceeded.Load() {
// Note: Stratus Red Team Cleanup function calls the Terraform Go Wrapper, which unfortunately
// catches Ctrl+C signals. This means that if the user presses Ctrl+C at "the wrong time", the cleanup
// will fail because the Terraform Wrapper will panic and exit
Expand Down Expand Up @@ -150,23 +149,6 @@ func (m *RunCommand) handleNewEvent(event *map[string]interface{}) error {
return nil
}

func (m *RunCommand) writeToFile(events []map[string]interface{}) error {
if m.OutputFile == "" {
return nil // nothing to do
}
outputBytes, err := json.MarshalIndent(events, "", " ")
if err != nil {
return err
}

if m.OutputFile == "-" {
fmt.Println(string(outputBytes))
} else if err := os.WriteFile(m.OutputFile, outputBytes, 0600); err != nil {
return err
}
return nil
}

func (m *RunCommand) CleanupDetonation() error {
m.cleanupMutex.Lock()
defer m.cleanupMutex.Unlock()
Expand Down
1 change: 1 addition & 0 deletions pkg/grimoire/detonators/stratus_red_team.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type StratusRedTeamDetonator struct {
func NewStratusRedTeamDetonator(attackTechniqueID string) (*StratusRedTeamDetonator, error) {
ttp := stratus.GetRegistry().GetAttackTechniqueByName(attackTechniqueID)
if ttp == nil {
//lint:ignore ST1005 "Stratus Red Team" is a proper noun
return nil, fmt.Errorf("Stratus Red Team attack technique %s not found", attackTechniqueID)
}
return &StratusRedTeamDetonator{AttackTechnique: ttp}, nil
Expand Down
5 changes: 1 addition & 4 deletions pkg/grimoire/logs/cloudtrail.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,6 @@ func (m *CloudTrailEventsFinder) lookupEvents(ctx context.Context, detonation *d
} else {
log.Debugf("Found CloudTrail event %s matching detonation UID, but ignoring as it's on the exclude list", eventName)
}
} else {
// logging disabled for now, was noisy
//log.Debugf("Found CloudTrail event %s but it does not match detonation UID", eventName)
}
}
}
Expand All @@ -216,7 +213,7 @@ func (m *CloudTrailEventsFinder) eventsMatchesDetonation(event map[string]interf

switch m.Options.UserAgentMatchType {
case UserAgentMatchTypeExact:
return strings.ToLower(userAgent) == strings.ToLower(detonation.DetonationID)
return strings.EqualFold(userAgent, detonation.DetonationID)
case UserAgentMatchTypePartial:
return strings.Contains(userAgent, detonation.DetonationID)
default:
Expand Down

0 comments on commit e8819bc

Please sign in to comment.