-
Notifications
You must be signed in to change notification settings - Fork 292
New attack technique: Disable VPC Flow Logs on a Subnet (gcp.defense-evasion.remove-vpc-flow-logs) #794
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
christophetd
merged 3 commits into
main
from
simon.marechal/gcp-defense-evasion-remove-vpc-flow-logs
Apr 8, 2026
Merged
New attack technique: Disable VPC Flow Logs on a Subnet (gcp.defense-evasion.remove-vpc-flow-logs) #794
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
docs/attack-techniques/GCP/gcp.defense-evasion.remove-vpc-flow-logs.md
This file contains hidden or 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,59 @@ | ||
| --- | ||
| title: Disable VPC Flow Logs on a Subnet | ||
| --- | ||
|
|
||
| # Disable VPC Flow Logs on a Subnet | ||
|
|
||
|
|
||
| <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 | ||
|
|
||
| ## Mappings | ||
|
|
||
| - MITRE ATT&CK | ||
| - Defense Evasion | ||
|
|
||
|
|
||
|
|
||
| ## Description | ||
|
|
||
|
|
||
| Disables VPC flow logging on a subnet by patching its log configuration. | ||
| VPC flow logs record network traffic metadata for all VM instances in a subnet, | ||
| providing visibility for network monitoring and forensic investigation. | ||
|
|
||
| <span style="font-variant: small-caps;">Warm-up</span>: | ||
|
|
||
| - Create a VPC network | ||
| - Create a subnet with VPC flow logs enabled | ||
|
|
||
| <span style="font-variant: small-caps;">Detonation</span>: | ||
|
|
||
| - Disable VPC flow logs on the subnet by patching its <code>logConfig.enable</code> field to <code>false</code> | ||
|
|
||
| Revert: | ||
|
|
||
| - Re-enable VPC flow logs on the subnet | ||
|
|
||
| References: | ||
|
|
||
| - https://cloud.google.com/vpc/docs/using-flow-logs | ||
| - https://cloud.google.com/compute/docs/reference/rest/v1/subnetworks/patch | ||
| - https://github.com/GoogleCloudPlatform/security-analytics/blob/main/src/3.02/3.02.md | ||
| - https://securitylabs.datadoghq.com/cloud-security-atlas/attacks/removing-vpc-flow-logs/ | ||
|
|
||
|
|
||
| ## Instructions | ||
|
|
||
| ```bash title="Detonate with Stratus Red Team" | ||
| stratus detonate gcp.defense-evasion.remove-vpc-flow-logs | ||
| ``` | ||
| ## Detection | ||
|
|
||
|
|
||
| Identify when VPC flow logging is disabled on a subnet by monitoring for | ||
| <code>v1.compute.subnetworks.patch</code> events in GCP Admin Activity audit logs | ||
| where the request sets <code>logConfig.enable</code> to <code>false</code>. | ||
|
|
||
|
|
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
129 changes: 129 additions & 0 deletions
129
v2/internal/attacktechniques/gcp/defense-evasion/remove-vpc-flow-logs/main.go
This file contains hidden or 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,129 @@ | ||
| package gcp | ||
|
|
||
| import ( | ||
| "context" | ||
| _ "embed" | ||
| "fmt" | ||
| "log" | ||
|
|
||
| compute "cloud.google.com/go/compute/apiv1" | ||
| "cloud.google.com/go/compute/apiv1/computepb" | ||
| "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 | ||
|
|
||
| func init() { | ||
| stratus.GetRegistry().RegisterAttackTechnique(&stratus.AttackTechnique{ | ||
| ID: "gcp.defense-evasion.remove-vpc-flow-logs", | ||
| FriendlyName: "Disable VPC Flow Logs on a Subnet", | ||
| Description: ` | ||
| Disables VPC flow logging on a subnet by patching its log configuration. | ||
| VPC flow logs record network traffic metadata for all VM instances in a subnet, | ||
| providing visibility for network monitoring and forensic investigation. | ||
|
|
||
| Warm-up: | ||
|
|
||
| - Create a VPC network | ||
| - Create a subnet with VPC flow logs enabled | ||
|
|
||
| Detonation: | ||
|
|
||
| - Disable VPC flow logs on the subnet by patching its <code>logConfig.enable</code> field to <code>false</code> | ||
|
|
||
| Revert: | ||
|
|
||
| - Re-enable VPC flow logs on the subnet | ||
|
|
||
| References: | ||
|
|
||
| - https://cloud.google.com/vpc/docs/using-flow-logs | ||
| - https://cloud.google.com/compute/docs/reference/rest/v1/subnetworks/patch | ||
| - https://github.com/GoogleCloudPlatform/security-analytics/blob/main/src/3.02/3.02.md | ||
| - https://securitylabs.datadoghq.com/cloud-security-atlas/attacks/removing-vpc-flow-logs/ | ||
| `, | ||
| Detection: ` | ||
| Identify when VPC flow logging is disabled on a subnet by monitoring for | ||
| <code>v1.compute.subnetworks.patch</code> events in GCP Admin Activity audit logs | ||
| where the request sets <code>logConfig.enable</code> to <code>false</code>. | ||
| `, | ||
| Platform: stratus.GCP, | ||
| IsIdempotent: true, | ||
| MitreAttackTactics: []mitreattack.Tactic{mitreattack.DefenseEvasion}, | ||
| PrerequisitesTerraformCode: tf, | ||
| Detonate: detonate, | ||
| Revert: revert, | ||
| }) | ||
| } | ||
|
|
||
| func setFlowLogsEnabled(providers stratus.CloudProviders, subnetName string, region string, enabled bool) error { | ||
| gcp := providers.GCP() | ||
| ctx := context.Background() | ||
| projectId := gcp.GetProjectId() | ||
|
|
||
| subnetsClient, err := compute.NewSubnetworksRESTClient(ctx, gcp.Options()) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to create subnetworks client: %w", err) | ||
| } | ||
| defer subnetsClient.Close() | ||
|
|
||
| subnet, err := subnetsClient.Get(ctx, &computepb.GetSubnetworkRequest{ | ||
| Project: projectId, | ||
| Region: region, | ||
| Subnetwork: subnetName, | ||
| }) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to get subnet %s: %w", subnetName, err) | ||
| } | ||
|
|
||
| op, err := subnetsClient.Patch(ctx, &computepb.PatchSubnetworkRequest{ | ||
| Project: projectId, | ||
| Region: region, | ||
| Subnetwork: subnetName, | ||
| SubnetworkResource: &computepb.Subnetwork{ | ||
| Fingerprint: subnet.Fingerprint, | ||
| LogConfig: &computepb.SubnetworkLogConfig{ | ||
| Enable: ptr(enabled), | ||
| }, | ||
| }, | ||
| }) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to patch subnet %s: %w", subnetName, err) | ||
| } | ||
|
|
||
| if err = op.Wait(ctx); err != nil { | ||
| return fmt.Errorf("failed waiting for subnet patch to complete: %w", err) | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| func detonate(params map[string]string, providers stratus.CloudProviders) error { | ||
| subnetName := params["subnet_name"] | ||
| region := params["region"] | ||
|
|
||
| log.Printf("Disabling VPC flow logs on subnet %s in region %s\n", subnetName, region) | ||
| if err := setFlowLogsEnabled(providers, subnetName, region, false); err != nil { | ||
| return err | ||
| } | ||
| log.Printf("Successfully disabled VPC flow logs on subnet %s\n", subnetName) | ||
| return nil | ||
| } | ||
|
|
||
| func revert(params map[string]string, providers stratus.CloudProviders) error { | ||
| subnetName := params["subnet_name"] | ||
| region := params["region"] | ||
|
|
||
| log.Printf("Re-enabling VPC flow logs on subnet %s in region %s\n", subnetName, region) | ||
| if err := setFlowLogsEnabled(providers, subnetName, region, true); err != nil { | ||
| return err | ||
| } | ||
| log.Printf("Successfully re-enabled VPC flow logs on subnet %s\n", subnetName) | ||
| return nil | ||
| } | ||
|
|
||
| func ptr[T any](v T) *T { | ||
| return &v | ||
| } | ||
52 changes: 52 additions & 0 deletions
52
v2/internal/attacktechniques/gcp/defense-evasion/remove-vpc-flow-logs/main.tf
This file contains hidden or 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,52 @@ | ||
| terraform { | ||
| required_providers { | ||
| google = { | ||
| source = "hashicorp/google" | ||
| version = "~> 6.18.1" | ||
| } | ||
| random = { | ||
| source = "hashicorp/random" | ||
| version = "~> 3.3.2" | ||
| } | ||
| } | ||
| } | ||
|
|
||
| locals { | ||
| resource_prefix = "stratus-red-team-rvfl" # stratus red team remove vpc flow logs | ||
| } | ||
|
|
||
| resource "random_string" "suffix" { | ||
| length = 8 | ||
| special = false | ||
| min_lower = 8 | ||
| } | ||
|
|
||
| resource "google_compute_network" "vpc" { | ||
| name = "${local.resource_prefix}-vpc-${random_string.suffix.result}" | ||
| auto_create_subnetworks = false | ||
| } | ||
|
|
||
| resource "google_compute_subnetwork" "subnet" { | ||
| name = "${local.resource_prefix}-subnet-${random_string.suffix.result}" | ||
| ip_cidr_range = "10.10.0.0/24" | ||
| region = "us-central1" | ||
| network = google_compute_network.vpc.id | ||
|
|
||
| log_config { | ||
| aggregation_interval = "INTERVAL_5_SEC" | ||
| flow_sampling = 0.5 | ||
| metadata = "INCLUDE_ALL_METADATA" | ||
| } | ||
| } | ||
|
|
||
| output "subnet_name" { | ||
| value = google_compute_subnetwork.subnet.name | ||
| } | ||
|
|
||
| output "region" { | ||
| value = google_compute_subnetwork.subnet.region | ||
| } | ||
|
|
||
| output "display" { | ||
| value = format("Subnet %s in region %s with VPC flow logs enabled", google_compute_subnetwork.subnet.name, google_compute_subnetwork.subnet.region) | ||
| } |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.