# AWS - API Gateway 未认证枚举 {{#include ../../../banners/hacktricks-training.md}} ### API 调用绕过 根据演讲 [Attack Vectors for APIs Using AWS API Gateway Lambda Authorizers - Alexandre & Leonardo](https://www.youtube.com/watch?v=bsPKk7WDOnE),Lambda Authorizers 可以 **使用 IAM 语法** 配置以授予调用 API 端点的权限。这是 [**来自文档**](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" ] } ] } ``` 给端点赋予权限的这种方式的问题在于,**"\*" 意味着 "任何"**,并且**不再支持正则表达式语法**。 一些示例: - 规则如 `arn:aws:execute-apis:sa-east-1:accid:api-id/prod/*/dashboard/*` 为每个用户提供对 `/dashboard/user/{username}` 的访问权限,将使他们能够访问其他路由,例如 `/admin/dashboard/createAdmin`。 > [!WARNING] > 请注意,**"\*" 不会因斜杠而停止扩展**,因此,如果您在 api-id 中使用 "\*",它也可能表示 "任何阶段" 或 "任何方法",只要最终的正则表达式仍然有效。\ > 因此 `arn:aws:execute-apis:sa-east-1:accid:*/prod/GET/dashboard/*`\ > 可以验证对路径 `/prod/GET/dashboard/admin` 的测试阶段的 POST 请求。 您应该始终清楚您想要允许访问的内容,然后检查授予的权限是否可能导致其他场景。 有关更多信息,除了 [**docs**](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-control-access-using-iam-policies-to-invoke-api.html),您还可以在 [**this official aws github**](https://github.com/awslabs/aws-apigateway-lambda-authorizer-blueprints/tree/master/blueprints) 中找到实现授权者的代码。 ### IAM 策略注入 在同一 [**talk** ](https://www.youtube.com/watch?v=bsPKk7WDOnE) 中,暴露了这样一个事实:如果代码使用 **用户输入** 来 **生成 IAM 策略**,则可以在其中包含通配符(以及其他如 "." 或特定字符串),目的是 **绕过限制**。 ### 公共 URL 模板 ``` https://{random_id}.execute-api.{region}.amazonaws.com/{user_provided} ``` ### 从公共 API Gateway URL 获取账户 ID 就像 S3 存储桶、数据交换和 Lambda URL 网关一样,可以通过公共 API Gateway URL 利用 **`aws:ResourceAccount`** **策略条件键** 找到账户的账户 ID。这是通过逐个字符查找账户 ID,利用策略中 **`aws:ResourceAccount`** 部分的通配符来实现的。\ 此技术还允许获取 **标签的值**,如果你知道标签键(有一些默认的有趣标签)。 你可以在 [**原始研究**](https://blog.plerion.com/conditional-love-for-aws-metadata-enumeration/) 和工具 [**conditional-love**](https://github.com/plerionhq/conditional-love/) 中找到更多信息,以自动化此利用。 {{#include ../../../banners/hacktricks-training.md}}