-
Notifications
You must be signed in to change notification settings - Fork 225
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New attack technique: Delete CloudTrail trail
- Loading branch information
1 parent
08ac16c
commit 3d0024f
Showing
6 changed files
with
168 additions
and
0 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
docs/attack-techniques/AWS/aws.defense-evasion.delete-cloudtrail.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Delete a CloudTrail Trail | ||
|
||
Platform: AWS | ||
|
||
## MITRE ATT&CK Tactics | ||
|
||
|
||
- Defense Evasion | ||
|
||
## Description | ||
|
||
|
||
Delete a CloudTrail trail. | ||
|
||
Warm-up: Creates a CloudTrail trail. | ||
|
||
Detonation: Deletes the CloudTrail trail. | ||
|
||
|
||
## Instructions | ||
|
||
```bash title="Detonate with Stratus Red Team" | ||
stratus detonate aws.defense-evasion.delete-cloudtrail | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
internal/attacktechniques/aws/defense-evasion/delete-cloudtrail/main.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package aws | ||
|
||
import ( | ||
"context" | ||
_ "embed" | ||
"errors" | ||
"github.com/aws/aws-sdk-go-v2/aws" | ||
"github.com/aws/aws-sdk-go-v2/service/cloudtrail" | ||
"github.com/datadog/stratus-red-team/internal/providers" | ||
"github.com/datadog/stratus-red-team/pkg/stratus" | ||
"github.com/datadog/stratus-red-team/pkg/stratus/mitreattack" | ||
"log" | ||
) | ||
|
||
//go:embed main.tf | ||
var tf []byte | ||
|
||
func init() { | ||
stratus.GetRegistry().RegisterAttackTechnique(&stratus.AttackTechnique{ | ||
ID: "aws.defense-evasion.delete-cloudtrail", | ||
FriendlyName: "Delete a CloudTrail Trail", | ||
Platform: stratus.AWS, | ||
MitreAttackTactics: []mitreattack.Tactic{mitreattack.DefenseEvasion}, | ||
Description: ` | ||
Delete a CloudTrail trail. | ||
Warm-up: Creates a CloudTrail trail. | ||
Detonation: Deletes the CloudTrail trail. | ||
`, | ||
PrerequisitesTerraformCode: tf, | ||
Detonate: detonate, | ||
}) | ||
} | ||
|
||
func detonate(params map[string]string) error { | ||
cloudtrailClient := cloudtrail.NewFromConfig(providers.AWS().GetConnection()) | ||
trailName := params["cloudtrail_trail_name"] | ||
|
||
log.Println("Deleting CloudTrail trail " + trailName) | ||
|
||
_, err := cloudtrailClient.DeleteTrail(context.Background(), &cloudtrail.DeleteTrailInput{ | ||
Name: aws.String(trailName), | ||
}) | ||
|
||
if err != nil { | ||
return errors.New("unable to delete CloudTrail logging: " + err.Error()) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func revert(params map[string]string) error { | ||
cloudtrailClient := cloudtrail.NewFromConfig(providers.AWS().GetConnection()) | ||
trailName := params["cloudtrail_trail_name"] | ||
|
||
log.Println("Restarting CloudTrail trail " + trailName) | ||
_, err := cloudtrailClient.StartLogging(context.Background(), &cloudtrail.StartLoggingInput{ | ||
Name: aws.String(trailName), | ||
}) | ||
|
||
return err | ||
} |
77 changes: 77 additions & 0 deletions
77
internal/attacktechniques/aws/defense-evasion/delete-cloudtrail/main.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
terraform { | ||
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = "~> 3.71.0" | ||
} | ||
} | ||
} | ||
provider "aws" { | ||
skip_region_validation = true | ||
skip_credentials_validation = true | ||
skip_get_ec2_platforms = true | ||
skip_metadata_api_check = true | ||
default_tags { | ||
tags = { | ||
StratusRedTeam = true | ||
} | ||
} | ||
} | ||
|
||
resource "aws_cloudtrail" "trail" { | ||
name = "my-cloudtrail-trail-2" | ||
s3_bucket_name = aws_s3_bucket.cloudtrail.id | ||
} | ||
|
||
resource "random_string" "suffix" { | ||
length = 16 | ||
min_lower = 16 | ||
special = false | ||
} | ||
|
||
locals { | ||
bucket-name = "my-cloudtrail-bucket-${random_string.suffix.result}" | ||
} | ||
resource "aws_s3_bucket" "cloudtrail" { | ||
bucket = local.bucket-name | ||
force_destroy = true | ||
|
||
policy = <<POLICY | ||
{ | ||
"Version": "2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Sid": "AWSCloudTrailAclCheck", | ||
"Effect": "Allow", | ||
"Principal": { | ||
"Service": "cloudtrail.amazonaws.com" | ||
}, | ||
"Action": "s3:GetBucketAcl", | ||
"Resource": "arn:aws:s3:::${local.bucket-name}" | ||
}, | ||
{ | ||
"Sid": "AWSCloudTrailWrite", | ||
"Effect": "Allow", | ||
"Principal": { | ||
"Service": "cloudtrail.amazonaws.com" | ||
}, | ||
"Action": "s3:PutObject", | ||
"Resource": "arn:aws:s3:::${local.bucket-name}/*", | ||
"Condition": { | ||
"StringEquals": { | ||
"s3:x-amz-acl": "bucket-owner-full-control" | ||
} | ||
} | ||
} | ||
] | ||
} | ||
POLICY | ||
} | ||
|
||
output "cloudtrail_trail_name" { | ||
value = aws_cloudtrail.trail.name | ||
} | ||
|
||
output "display" { | ||
value = format("CloudTrail trail %s ready", aws_cloudtrail.trail.arn) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters