Skip to content

Commit 49e9478

Browse files
committed
Use full event name when logging cloudtrail events
1 parent 4ac40ad commit 49e9478

File tree

5 files changed

+31
-5
lines changed

5 files changed

+31
-5
lines changed

cmd/grimoire/shell.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ func (m *ShellCommand) Do() error {
155155
os.Exit(1)
156156
}
157157

158-
log.Infof("Found event: %s", (*evt.CloudTrailEvent)["eventName"])
158+
log.Infof("Found event: %s", utils.GetCloudTrailEventFullName(evt.CloudTrailEvent))
159159
if err := utils.AppendToJsonFileArray(m.OutputFile, *evt.CloudTrailEvent); err != nil {
160160
log.Errorf("unable to append CloudTrail event to output file: %v", err)
161161
}

cmd/grimoire/stratus-red-team.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ func (m *StratusRedTeamCommand) Do() error {
127127
}
128128

129129
func (m *StratusRedTeamCommand) handleNewEvent(event *map[string]interface{}) error {
130-
log.Printf("Found new CloudTrail event generated on %s UTC: %s", (*event)["eventTime"], (*event)["eventName"])
130+
log.Printf("Found new CloudTrail event generated on %s UTC: %s", (*event)["eventTime"], utils.GetCloudTrailEventFullName(event))
131131
err := utils.AppendToJsonFileArray(m.OutputFile, *event)
132132
if err != nil {
133133
return fmt.Errorf("unable to write CloudTrail event to %s: %v", m.OutputFile, err)

pkg/grimoire/logs/cloudtrail.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,7 @@ func (m *CloudTrailEventsFinder) lookupEvents(ctx context.Context, detonation *d
199199
func (m *CloudTrailEventsFinder) shouldKeepEvent(event *map[string]interface{}) bool {
200200
// note: we know (precondition) that zero or one of IncludeEvents and ExcludeEvents is set, not both
201201

202-
eventName := (*event)["eventName"].(string)
203-
eventSourceShort := strings.TrimSuffix((*event)["eventSource"].(string), ".amazonaws.com")
204-
fullEventName := fmt.Sprintf("%s:%s", eventSourceShort, eventName) // e.g. "sts:GetCallerIdentity"
202+
fullEventName := grimoire.GetCloudTrailEventFullName(event)
205203
isReadOnly := (*event)["readOnly"].(bool)
206204

207205
if m.Options.WriteEventsOnly && isReadOnly {

pkg/grimoire/utils/aws.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package utils
2+
3+
import (
4+
"fmt"
5+
"strings"
6+
)
7+
8+
// GetCloudTrailEventFullName returns the full name of a CloudTrail event, e.g. sts:GetCallerIdentity
9+
func GetCloudTrailEventFullName(event *map[string]interface{}) string {
10+
eventName := (*event)["eventName"].(string)
11+
eventSourceShort := strings.TrimSuffix((*event)["eventSource"].(string), ".amazonaws.com")
12+
return fmt.Sprintf("%s:%s", eventSourceShort, eventName) // e.g. "sts:GetCallerIdentity"
13+
}

pkg/grimoire/utils/aws_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package utils
2+
3+
import (
4+
"github.com/stretchr/testify/assert"
5+
"testing"
6+
)
7+
8+
func TestGetCloudTrailEventFullName(t *testing.T) {
9+
event := map[string]interface{}{
10+
"eventName": "SendCommand",
11+
"eventSource": "ssm.amazonaws.com",
12+
}
13+
result := GetCloudTrailEventFullName(&event)
14+
assert.Equal(t, "ssm:SendCommand", result)
15+
}

0 commit comments

Comments
 (0)