AWS - API Gateway Unauthenticated Enum

Tip

Apprenez & pratiquez AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
Apprenez & pratiquez GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)
Apprenez & pratiquez Az Hacking: HackTricks Training Azure Red Team Expert (AzRTE)

Soutenez HackTricks

API Invoke bypass

Selon la prĂ©sentation Attack Vectors for APIs Using AWS API Gateway Lambda Authorizers - Alexandre & Leonardo, les Lambda Authorizers peuvent ĂȘtre configurĂ©s en utilisant la syntaxe IAM pour accorder l’autorisation d’invoquer des endpoints API. Ceci est tirĂ© from the docs:

{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Permission",
"Action": ["execute-api:Execution-operation"],
"Resource": [
"arn:aws:execute-api:region:account-id:api-id/stage/METHOD_HTTP_VERB/Resource-path"
]
}
]
}

Le problùme avec cette maniùre d’accorder des permissions pour invoquer des endpoints est que le “*” implique “tout” et qu’il n’y a plus de prise en charge de la syntaxe regex.

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.

Warning

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.

Vous devez toujours savoir exactement ce que vous voulez autoriser et ensuite vĂ©rifier si d’autres scĂ©narios sont possibles avec les permissions accordĂ©es.

Pour plus d’infos, apart of the docs, you can find code to implement authorizers in this official aws github.

IAM Policy Injection

In the same talk it’s exposed the fact that if the code is using entrĂ©es utilisateur to gĂ©nĂ©rer les IAM policies, wildcards (and others such as “.” or specific strings) can be included in there with the goal of contourner les restrictions.

Modùle d’URL publique

https://{random_id}.execute-api.{region}.amazonaws.com/{user_provided}

Get Account ID from public API Gateway URL

Tout comme pour les buckets S3, Data Exchange et les URL Lambda gateways, il est possible de trouver l’ID de compte d’un compte en abusant de la aws:ResourceAccount Policy Condition Key Ă  partir d’une URL publique API Gateway. Cela se fait en dĂ©couvrant l’ID caractĂšre par caractĂšre en abusant des jokers dans la section aws:ResourceAccount de la policy.
Cette technique permet Ă©galement d’obtenir les valeurs des tags si vous connaissez la clĂ© du tag (il y en a quelques-unes par dĂ©faut intĂ©ressantes).

Vous pouvez trouver plus d’informations dans la original research et l’outil conditional-love pour automatiser cette exploitation.

Tip

Apprenez & pratiquez AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
Apprenez & pratiquez GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)
Apprenez & pratiquez Az Hacking: HackTricks Training Azure Red Team Expert (AzRTE)

Soutenez HackTricks