3.7 KiB
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 によると、Lambda Authorizers は using IAM syntax を用いて API エンドポイントを invoke する権限を付与するように設定できます。これは 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.
いくつかの例:
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, you can find code to implement authorizers in this official aws github.
IAM Policy Injection
同じ talk では、コードが 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 と、自動化用ツール conditional-love を参照してください。
{{#include ../../../../banners/hacktricks-training.md}}