AWS - API Gateway Enumerazione non autenticata
Reading time: 4 minutes
tip
Impara e pratica il hacking AWS: HackTricks Training AWS Red Team Expert (ARTE)
HackTricks Training AWS Red Team Expert (ARTE)
Impara e pratica il hacking GCP:  HackTricks Training GCP Red Team Expert (GRTE)
HackTricks Training GCP Red Team Expert (GRTE) Impara e pratica il hacking Azure:
Impara e pratica il hacking Azure:  HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks Training Azure Red Team Expert (AzRTE)
Supporta HackTricks
- Controlla i piani di abbonamento!
- Unisciti al 💬 gruppo Discord o al gruppo telegram o seguici su Twitter 🐦 @hacktricks_live.
- Condividi trucchi di hacking inviando PR ai HackTricks e HackTricks Cloud repos su github.
API Invoke bypass
Secondo il talk Attack Vectors for APIs Using AWS API Gateway Lambda Authorizers - Alexandre & Leonardo, i Lambda Authorizers possono essere configurati usando la sintassi IAM per concedere permessi di invocare endpoint API. Questo è tratto 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"
]
}
]
}
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/createAdminfor example.
warning
Nota che "*" non smette di espandersi con le slash, quindi, se usi "*" in api-id per esempio, potrebbe anche indicare "any stage" o "any method" purché la regex finale sia ancora valida.
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.
Devi sempre avere chiaro cosa vuoi permettere di accedere e poi verificare se altri scenari sono possibili con i permessi concessi.
Per ulteriori informazioni, oltre alle docs, puoi trovare codice per implementare authorizers in this official aws github.
IAM Policy Injection
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.
Public URL template
https://{random_id}.execute-api.{region}.amazonaws.com/{user_provided}
Ottenere l'Account ID da un URL pubblico di API Gateway
Come per S3 buckets, Data Exchange e Lambda URLs gateways, è possibile trovare l'account ID sfruttando la aws:ResourceAccount Policy Condition Key da un URL pubblico di API Gateway. Questo si ottiene trovando l'account ID un carattere alla volta sfruttando i wildcard nella sezione aws:ResourceAccount della policy.
Questa tecnica permette anche di ottenere i valori dei tag se conosci la chiave del tag (ci sono alcuni valori di default interessanti).
Puoi trovare più informazioni nella original research e nello strumento conditional-love per automatizzare questa exploitation.
tip
Impara e pratica il hacking AWS: HackTricks Training AWS Red Team Expert (ARTE)
HackTricks Training AWS Red Team Expert (ARTE)
Impara e pratica il hacking GCP:  HackTricks Training GCP Red Team Expert (GRTE)
HackTricks Training GCP Red Team Expert (GRTE) Impara e pratica il hacking Azure:
Impara e pratica il hacking Azure:  HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks Training Azure Red Team Expert (AzRTE)
Supporta HackTricks
- Controlla i piani di abbonamento!
- Unisciti al 💬 gruppo Discord o al gruppo telegram o seguici su Twitter 🐦 @hacktricks_live.
- Condividi trucchi di hacking inviando PR ai HackTricks e HackTricks Cloud repos su github.
 HackTricks Cloud
HackTricks Cloud