AWS - API Gateway Unauthenticated Enum
Last updated
Last updated
Learn & practice AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE) Learn & practice GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)
According to the talk Attack Vectors for APIs Using AWS API Gateway Lambda Authorizers - Alexandre & Leonardo, Lambda Authorizers can be configured using IAM syntax to give permissions to invoke API endpoints. This is taken from the docs:
The problem with this way to give permissions to invoke endpoints is that the "*" implies "anything" and there is no more regex syntax supported.
Some examples:
A rule such as arn:aws:execute-apis:sa-east-1:accid:api-id/prod/*/dashboard/*
in order to give each user access to /dashboard/user/{username}
will give them access to other routes such as /admin/dashboard/createAdmin
for example.
Note that "*" doesn't stop expanding with slashes, therefore, if you use "*" in api-id for example, it could also indicate "any stage" or "any method" as long as the final regex is still valid.
So arn:aws:execute-apis:sa-east-1:accid:*/prod/GET/dashboard/*
Can validate a post request to test stage to the path /prod/GET/dashboard/admin
for example.
You should always have clear what you want to allow to access and then check if other scenarios are possible with the permissions granted.
For more info, apart of the docs, you can find code to implement authorizers in this official aws github.
In the same talk it's exposed the fact that if the code is using user input to generate the IAM policies, wildcards (and others such as "." or specific strings) can be included in there with the goal of bypassing restrictions.
Just like with S3 buckets, Data Exchange and Lambda URLs gateways, It's possible to find the account ID of an account abusing the aws:ResourceAccount
Policy Condition Key from a public API Gateway URL. This is done by finding the account ID one character at a time abusing wildcards in the aws:ResourceAccount
section of the policy.
This technique also allows to get values of tags if you know the tag key (there some default interesting ones).
You can find more information in the original research and the tool conditional-love to automate this exploitation.
Learn & practice AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE) Learn & practice GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)