# AWS - API Gateway Unauthenticated Enum {{#include ../../../../banners/hacktricks-training.md}} ### API Invoke bypass トーク [Attack Vectors for APIs Using AWS API Gateway Lambda Authorizers - Alexandre & Leonardo](https://www.youtube.com/watch?v=bsPKk7WDOnE) によると、Lambda Authorizers は **using IAM syntax** を用いて API エンドポイントを invoke する権限を付与するように設定できます。これは [**from the docs**](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-control-access-using-iam-policies-to-invoke-api.html): ```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" ] } ] } ``` The problem with this way to give permissions to invoke endpoints is that the **"\*" implies "anything"** and there is **no more regex syntax supported**. いくつかの例: - `arn:aws:execute-apis:sa-east-1:accid:api-id/prod/*/dashboard/*` のようなルールで各ユーザーに `/dashboard/user/{username}` へのアクセスを与えようとすると、例えば `/admin/dashboard/createAdmin` のような他のルートにもアクセスできてしまいます。 > [!WARNING] > **"\*" がスラッシュで展開を止めない** ことに注意してください。したがって、たとえば api-id に "\*" を使うと、最終的な regex が有効である限り「任意のステージ」や「任意のメソッド」を示すことにもなり得ます。\ > 例: `arn:aws:execute-apis:sa-east-1:accid:*/prod/GET/dashboard/*`\ > たとえば `/prod/GET/dashboard/admin` のようなパスへの test ステージへの POST リクエストを許可してしまう可能性があります。 何にアクセスを許可したいのかを常に明確にし、付与した権限で他のシナリオが発生し得ないか確認すべきです。 For more info, apart of the [**docs**](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-control-access-using-iam-policies-to-invoke-api.html), you can find code to implement authorizers in [**this official aws github**](https://github.com/awslabs/aws-apigateway-lambda-authorizer-blueprints/tree/master/blueprints). ### IAM Policy Injection 同じ [**talk** ](https://www.youtube.com/watch?v=bsPKk7WDOnE) では、コードが **user input** を使って **generate the IAM policies** を行う場合、wildcards (and others such as "." or specific strings) を含めることで **bypassing restrictions** を狙えることが示されています。 ### Public URL template ``` https://{random_id}.execute-api.{region}.amazonaws.com/{user_provided} ``` ### 公開の API Gateway URL からアカウント ID を取得 S3 buckets、Data Exchange、Lambda URLs gateways と同様に、公開の API Gateway URL から **`aws:ResourceAccount`** の **Policy Condition Key** を悪用してアカウント ID を特定することが可能です。\ これはポリシーの **`aws:ResourceAccount`** セクションでワイルドカードを悪用し、アカウント ID を1文字ずつ特定することで行われます。\ この手法では、タグキーが分かっている場合に **タグの値** を取得することも可能です(デフォルトで興味深いタグがいくつかあります)。 詳細は [**original research**](https://blog.plerion.com/conditional-love-for-aws-metadata-enumeration/) と、自動化用ツール [**conditional-love**](https://github.com/plerionhq/conditional-love/) を参照してください。 {{#include ../../../../banners/hacktricks-training.md}}