AWS - API Gateway Unauthenticated Enum

Reading time: 4 minutes

tip

Apprenez et pratiquez le hacking AWS :HackTricks Training AWS Red Team Expert (ARTE)
Apprenez et pratiquez le hacking GCP : HackTricks Training GCP Red Team Expert (GRTE) Apprenez et pratiquez le hacking Azure : HackTricks Training Azure Red Team Expert (AzRTE)

Soutenir 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:

json
{
"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 et pratiquez le hacking AWS :HackTricks Training AWS Red Team Expert (ARTE)
Apprenez et pratiquez le hacking GCP : HackTricks Training GCP Red Team Expert (GRTE) Apprenez et pratiquez le hacking Azure : HackTricks Training Azure Red Team Expert (AzRTE)

Soutenir HackTricks