AWS - API Gateway Unauthenticated Enum

支持 HackTricks

API Invoke 绕过

根据演讲 Attack Vectors for APIs Using AWS API Gateway Lambda Authorizers - Alexandre & Leonardo,Lambda Authorizers 可以配置 使用 IAM 语法 来授予调用 API 端点的权限。这是从 文档 中摘录的:

{
"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

注意,"*" 不会因斜杠而停止扩展,因此,如果在 api-id 中使用 "*",它也可能表示 "任何阶段" 或 "任何方法",只要最终的正则表达式仍然有效。 所以 arn:aws:execute-apis:sa-east-1:accid:*/prod/GET/dashboard/* 可以验证对路径 /prod/GET/dashboard/admin 的测试阶段的 post 请求。

你应该始终明确你想允许访问的内容,然后检查授予的权限是否可能导致其他场景。

更多信息,除了 docs,你可以在 这个官方 aws github 中找到实现 authorizers 的代码。

IAM Policy Injection

在同一个 talk 中,暴露了如果代码使用用户输入生成 IAM policies,通配符(以及其他如 "." 或特定字符串)可以被包含在内,以绕过限制

Public URL template

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

从公共 API Gateway URL 获取 Account ID

就像 S3 buckets、Data Exchange 和 Lambda URLs gateways 一样,可以通过滥用公共 API Gateway URL 中的 aws:ResourceAccount Policy Condition Key 来找到账户的 Account ID。通过在策略的 aws:ResourceAccount 部分滥用通配符,一次找到一个字符的 Account ID。 如果你知道标签键(有一些默认的有趣标签),这种技术还可以获取 标签的值

你可以在原始研究和工具 conditional-love 中找到更多信息,以自动化此漏洞利用。

支持 HackTricks

Last updated