AWS - API Gateway Unauthenticated Enum

Tip

AWS Hacking’i öğrenin ve pratik yapın:HackTricks Training AWS Red Team Expert (ARTE)
GCP Hacking’i öğrenin ve pratik yapın: HackTricks Training GCP Red Team Expert (GRTE)
Az Hacking’i öğrenin ve pratik yapın: HackTricks Training Azure Red Team Expert (AzRTE)

HackTricks'i Destekleyin

API Invoke bypass

Konuşmaya göre Attack Vectors for APIs Using AWS API Gateway Lambda Authorizers - Alexandre & Leonardo, Lambda Authorizers, API endpoints’i invoke etme izinleri vermek üzere using IAM syntax kullanılarak yapılandırılabilir. Bu, 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/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.

Bu şekilde endpoint’leri çağırma izinleri verme sorununun nedeni, “*“ın “her şeyi” ifade etmesi ve artık regex sözdiziminin desteklenmemesidir.

Birkaç örnek:

  • arn:aws:execute-apis:sa-east-1:accid:api-id/prod/*/dashboard/* gibi bir kural, her kullanıcıya /dashboard/user/{username} erişimi vermek amaçlı kullanıldığında örneğin /admin/dashboard/createAdmin gibi diğer rotalara da erişim sağlar.

Warning

Dikkat: “*” eğik çizgilerle birlikte genişlemeyi durdurmaz, bu nedenle örneğin api-id içinde “*” kullanırsanız, son regex hâlâ geçerli olduğu sürece bu “any stage” veya “any method” anlamına da gelebilir.
Dolayısıyla arn:aws:execute-apis:sa-east-1:accid:*/prod/GET/dashboard/*
örneğin test stage’ine yapılan bir POST isteğini /prod/GET/dashboard/admin yoluna doğrulayabilir.

Hangi kaynaklara erişime izin vermek istediğinizi her zaman net belirlemeli ve verilen izinlerle başka hangi senaryoların mümkün olabileceğini kontrol etmelisiniz.

For more info, 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 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.

Aynı talk içinde, eğer kod kullanıcı girdisini IAM politikalarını oluşturmak için kullanıyorsa, wildcard’lar (ve “.” veya belirli stringler gibi diğerleri) kısıtlamaları atlatmak amacıyla içine dahil edilebilir.

Public URL template

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

Kamuya açık API Gateway URL’sinden Hesap ID’sini Alma

S3 buckets, Data Exchange ve Lambda URL gateway’lerinde olduğu gibi, kamuya açık bir API Gateway URL’si aracılığıyla aws:ResourceAccount Policy Condition Key’i kötüye kullanarak bir hesabın hesap ID’sini bulmak mümkündür. Bu, politikadaki aws:ResourceAccount bölümünde joker karakterleri kullanarak hesap ID’sini karakter karakter bularak yapılır.
Bu teknik, eğer tag anahtarını biliyorsanız tag değerlerini elde etmeye de olanak tanır (bazı varsayılan ve ilginç olanlar mevcuttur).

Bu suistimale dair daha fazla bilgiyi orijinal araştırmada ve bu suistimali otomatikleştirmek için kullanılan conditional-love aracında bulabilirsiniz.

Tip

AWS Hacking’i öğrenin ve pratik yapın:HackTricks Training AWS Red Team Expert (ARTE)
GCP Hacking’i öğrenin ve pratik yapın: HackTricks Training GCP Red Team Expert (GRTE)
Az Hacking’i öğrenin ve pratik yapın: HackTricks Training Azure Red Team Expert (AzRTE)

HackTricks'i Destekleyin