Skip to content
KitploitKITPLOIT
工具博客
提交
工具博客
提交

黑客、渗透测试和网络安全工具,武装您的安全武器库!

Kitploit 是一个黑客、网络安全和渗透测试工具的目录。发现最新的项目更新,查找漏洞、分析系统、自动化测试并加强你的安全。

··订阅源·联系·隐私·© 2026 Kitploit

工具目录

分类

查看所有分类
Loading categories
iam-vulnerable — 使用 Terraform 创建你自己设计的易受攻击的 AWS IAM 权限提升演练环境。 | Kitploit
工具/GitHubGitHub/bishopfox/iam-vulnerable
权限提升漏洞分析渗透测试云安全身份与访问管理 (IAM)学习与教育实验室与实践
GitHubbishopfox/iam-vulnerable

iam-vulnerable

使用 Terraform 创建你自己设计的易受攻击的 AWS IAM 权限提升演练环境。

查看仓库
58510711个月前Kitploit 审核通过

最受欢迎

查看全部 →

发现我们社区最常用的工具。

探索所有工具

浏览我们的工具集合

查看所有工具 →
分享
网站

IAM 漏洞环境(IAM Vulnerable)

使用 Terraform 创建你自己的AWS IAM 权限提升靶场。

IAM 漏洞环境使用 Terraform 二进制文件和你的 AWS 凭证,在你选择的 AWS 账户中部署超过 250 个 IAM 资源。几分钟内,你就可以开始学习如何识别和利用允许权限提升的易受攻击 IAM 配置。

IAM 漏洞环境的“大哥”——CloudFoxable

大家好。IAM 漏洞环境对于理解 AWS IAM 权限提升的基本构建块仍然非常有用。然而,在制作 IAM 漏洞环境几年后,我创建了 CloudFoxable,这是一个 CTF 风格版本,可以更全面地教你云渗透测试的基础知识。——@sethsec

故意制作的漏洞靶场

  • CloudFoxable - 一个游戏化的云黑客沙箱

想聊一聊 IAM-Vulnerable、CloudFox 和 CloudFoxable 吗?

加入我们的 RedSec Discord 服务器

🦊 当前支持的权限提升路径: 31

目录

  • IAM 漏洞环境
  • 推荐方法
  • 详细使用说明
  • 快速入门
    • 刚才创建了哪些资源?
    • 这要花多少钱?
  • 模块化方法
    • 免费资源模块
    • 非免费资源模块
  • 支持的权限提升路径
  • 其他用例
  • 常见问题

推荐方法

  1. 选择或创建一个 AWS 账户——不要使用任何包含生产资源或敏感数据的账户。
  2. 创建你的漏洞靶场——使用此仓库创建支持 31 种独特 AWS IAM 权限提升路径的 IAM 主体和策略。
  3. 做好功课——了解 Spencer Gietzen 首创的 21 种原始权限提升路径。
  4. 黑掉它,黑掉它——按照 Gerben Kleijn 的指南在你的新靶场中练习利用。
  5. 升级——针对你的新 IAM 权限提升靶场账户运行你的工具(例如 Cloudsplaining、AWSPX、Principal Mapper、Pacu)。

详细使用说明

博客文章:IAM 漏洞环境——一个 AWS IAM 权限提升靶场

快速入门

本快速入门概述了一种带有主观意见的方法,旨在尽可能快地在你的 AWS 账户中启动并运行 IAM 漏洞环境。你可能已经完成了其中许多步骤,或者你可能希望调整一些设置以适应当前配置。请查看此仓库中的其他用例部分,了解一些其他配置选项。

  1. 选择或创建一个 AWS 账户。(不要使用任何包含生产资源或敏感数据的账户!)
  2. 创建一个具有管理访问权限的非 root 用户,你将在运行 Terraform 时使用该用户。
  3. 为该用户创建访问密钥。
  4. 安装 AWS CLI。
  5. 配置你的 AWS CLI,将你新建的管理员用户设为默认配置文件。
  6. 通过执行 aws sts get-caller-identity 确认 CLI 按预期工作。
  7. 安装 Terraform 二进制文件并将二进制文件位置添加到你的路径中。
  8. git clone https://github.com/BishopFox/iam-vulnerable
  9. cd iam-vulnerable/
  10. terraform init
  11. (可选)export TF_VAR_aws_local_profile=PROFILE_IN_AWS_CREDENTIALS_FILE_IF_OTHER_THAN_DEFAULT
  12. (可选)export TF_VAR_aws_local_creds_file=FILE_LOCATION_IF_NON_DEFAULT
  13. (可选)terraform plan
  14. terraform apply

清理

每当你想要移除所有 IAM 漏洞环境创建的资源时,可以运行以下命令:

  1. cd iam-vulnerable/
  2. terraform destroy

替代清理(当 Terraform 状态丢失时)

如果你已使用 Terraform 部署了 iam-vulnerable,但不再拥有对状态文件的访问权限(并且 terraform destroy 无法正常工作),则可以使用以下清理脚本:```bash

Python version (requires boto3)

./cleanup-scripts/cleanup_iam_vulnerable.py --dry-run

Bash version (requires AWS CLI and jq)

./cleanup-scripts/cleanup_iam_vulnerable.sh --dry-run

root@kitploit:~
这些脚本将:
- 自动识别您 AWS 账户中所有存在 IAM 漏洞的资源
- 在操作前向您展示将要删除的内容
- 按正确顺序删除资源以避免依赖冲突
- 支持 AWS 配置文件并提供详细日志

**重要提醒**:始终先使用 `--dry-run` 运行,查看将被删除的内容。详细使用说明请参见 `cleanup-scripts/CLEANUP_README.md`。

## 刚刚创建了哪些资源?

Terraform 二进制文件已使用您的默认 AWS 账户配置文件凭证创建了:
* **31 个用户、角色和策略**,每个都有通往该游乐场账户管理权限的独特利用路径
* 一些额外的用户、组、角色和策略,用于完全实现某些利用路径
* 一些额外的用户、角色和策略,用于测试其他工具的检测能力

默认情况下,此 Terraform 模块创建的每个角色均可由您用来运行 Terraform 的用户或角色代入。
* 如果您希望 Terraform 使用除默认配置文件之外的配置文件,或希望硬编码 `assume_role_policy` ARN,请参阅[其他用例](#other-use-cases)。

## 这需要花费多少钱?

在**默认配置下部署 IAM Vulnerable 不会产生任何费用**。请参阅下一节了解如何启用确实会产生费用的非默认模块,以及部署后每个模块每月的大致费用。

# 模块化方法

IAM Vulnerable 将某些资源分组到模块中。部分模块默认启用(不会产生费用的模块),其他模块默认禁用(部署后会产生费用的模块)。这样,您可以根据需要启用特定模块。

例如,当您准备好尝试涉及 IAM 之外资源的利用路径(如 `ssm:StartSession`)时,可以通过取消 `iam-vulnerable/main.tf` 文件中相关模块的注释,并重新运行 `terraform apply` 来按需部署和拆除这些资源:```
# Uncomment the next four lines to create an ec2 instance and related resources
#module "ec2" {
#  source = "./modules/non-free-resources/ec2"
#  aws_assume_role_arn = (var.aws_assume_role_arn != "" ? var.aws_assume_role_arn : data.aws_caller_identity.current.arn)
#}

在你取消注释ec2模块后,运行:``` terraform init terraform apply

root@kitploit:~
您现已部署所需组件,可尝试 SSM 权限提升路径。

## 免费资源模块

部署在 `free-resources` 中的任何内容均无成本:

| 名称 | 默认状态 | 预估成本 | 描述 |
| --- | --- | --- | --- |
| privesc-paths | 已启用 | 无 | 包含所有 IAM 权限提升路径 |
| tool-testing | 已启用 | 无 | 包含评估不同 IAM 权限提升工具能力的测试用例 |

## 非免费资源模块

部署这些附加模块可能产生费用:

| 名称 | 默认状态 | 预估成本 | 描述 | 所需用途 |
| --- | --- | --- | --- | --- |
| EC2 | 已禁用 | :heavy_dollar_sign: <br> 每月 $4.50 | 创建一个 EC2 实例及一个允许任意来源 SSH 连接的安全组 | `ssm-SendCommand` <br> `ssm-StartSession` <br> `ec2InstanceConnect-SendSSHPublicKey` |
| Lambda | 已禁用 | :slightly_smiling_face: <br> 每月费用取决于使用量(成本应为零) | 创建一个 Lambda 函数 | `Lambda-EditExistingLambdaFunctionWithRole` |
| Glue | 已禁用 | :heavy_dollar_sign::heavy_dollar_sign::heavy_dollar_sign::heavy_dollar_sign: <br> 每小时 $4 | 创建一个 Glue 开发端点 | `Glue-UpdateExistingGlueDevEndpoint` |
| SageMaker | 已禁用 | 尚不确定 | 创建一个 SageMaker 笔记本 | `sageMakerCreatePresignedNotebookURL` |
| CloudFormation | 已禁用 | :slightly_smiling_face: <br> 通过 CloudFormation 创建的密钥每月 $0.40。栈本身无成本或几乎无成本 | 创建一个 CloudFormation 栈,该栈在 Secret Manager 中创建一个密钥 | `privesc-cloudFormationUpdateStack` |

# 支持的权限提升路径

| 路径名称 | IAM 脆弱配置文件名称 | 所需非默认模块 | 利用参考 |
| --- | --- | --- | --- |
| **类别:对其他用户的 IAM 权限** | | | |
| IAM-CreateAccessKey | privesc4 | 无 | :fox_face: [Well, That Escalated Quickly - Privesc 04](https://labs.bishopfox.com/tech-blog/privilege-escalation-in-aws) <br> :lock: [s3cur3.it IAMVulnerable - Part 3](https://s3cur3.it/home/practicing-aws-security-with-iamvulnerable-part-3) |
| IAM-CreateLoginProfile | privesc5 | 无 | :fox_face: [Well, That Escalated Quickly - Privesc 05](https://labs.bishopfox.com/tech-blog/privilege-escalation-in-aws) <br> :lock: [s3cur3.it IAMVulnerable - Part 3](https://s3cur3.it/home/practicing-aws-security-with-iamvulnerable-part-3) |
| IAM-UpdateLoginProfile | privesc6 | 无 | :fox_face: [Well, That Escalated Quickly - Privesc 06](https://labs.bishopfox.com/tech-blog/privilege-escalation-in-aws) <br> :lock: [s3cur3.it IAMVulnerable - Part 3](https://s3cur3.it/home/practicing-aws-security-with-iamvulnerable-part-3) |
| **类别:将角色传递(PassRole)给服务** | | | |
| CloudFormation-PassExistingRoleToCloudFormation | privesc20 | 无 | :fox_face: [Well, That Escalated Quickly - Privesc 20](https://labs.bishopfox.com/tech-blog/privilege-escalation-in-aws) |
| CodeBuild-CreateProjectPassRole | privesc-codeBuildProject | 无 | |
| DataPipeline-PassExistingRoleToNewDataPipeline | privesc21 | 无 | :fox_face: [Well, That Escalated Quickly - Privesc 21](https://labs.bishopfox.com/tech-blog/privilege-escalation-in-aws) |
| EC2-CreateInstanceWithExistingProfile | privesc3 | 无 | :fox_face: [Well, That Escalated Quickly - Privesc 03](https://labs.bishopfox.com/tech-blog/privilege-escalation-in-aws) <br> :lock: [s3cur3.it IAMVulnerable - Part 2](https://s3cur3.it/home/practicing-aws-security-with-iamvulnerable-part-2) |
| Glue-PassExistingRoleToNewGlueDevEndpoint | privesc18 | 无 | :fox_face: [Well, That Escalated Quickly - Privesc 18](https://labs.bishopfox.com/tech-blog/privilege-escalation-in-aws) |
| Lambda-PassExistingRoleToNewLambdaThenInvoke | privesc15 | 无 | :fox_face: [Well, That Escalated Quickly - Privesc 15](https://labs.bishopfox.com/tech-blog/privilege-escalation-in-aws) |
| Lambda-PassRoleToNewLambdaThenTrigger | privesc16 | 无 | :fox_face: [Well, That Escalated Quickly - Privesc 16](https://labs.bishopfox.com/tech-blog/privilege-escalation-in-aws) |
| SageMaker-CreateNotebookPassRole | privesc-sageNotebook | 无 | :rhinoceros: [AWS IAM Privilege Escalation - Method 2](https://rhinosecuritylabs.com/aws/aws-privilege-escalation-methods-mitigation-part-2/) |
| SageMaker-CreateTrainingJobPassRole | privesc-sageTraining | 无 | |
| SageMaker-CreateProcessingJobPassRole | privesc-sageProcessing | 无 | |
| **类别:对策略的权限** | | | |
| IAM-AddUserToGroup | privesc13 | 无 | :fox_face: [Well, That Escalated Quickly - Privesc 13](https://labs.bishopfox.com/tech-blog/privilege-escalation-in-aws) |
| IAM-AttachGroupPolicy | privesc8 | 无 | :fox_face: [Well, That Escalated Quickly - Privesc 08](https://labs.bishopfox.com/tech-blog/privilege-escalation-in-aws) |
| IAM-AttachRolePolicy | privesc9 | 无 | :fox_face: [Well, That Escalated Quickly - Privesc 09](https://labs.bishopfox.com/tech-blog/privilege-escalation-in-aws) |
| IAM-AttachUserPolicy | privesc7 | 无 | :fox_face: [Well, That Escalated Quickly - Privesc 07](https://labs.bishopfox.com/tech-blog/privilege-escalation-in-aws) |
| IAM-CreateNewPolicyVersion | privesc1 | 无 | :fox_face: [Well, That Escalated Quickly - Privesc 01](https://labs.bishopfox.com/tech-blog/privilege-escalation-in-aws) <br> :lock: [s3cur3.it IAMVulnerable - Part 1](https://s3cur3.it/home/practicing-aws-security-with-iamvulnerable) |
| IAM-PutGroupPolicy | privesc11 | 无 | :fox_face: [Well, That Escalated Quickly - Privesc 11](https://labs.bishopfox.com/tech-blog/privilege-escalation-in-aws) |
| IAM-PutRolePolicy | privesc12 | 无 | :fox_face: [Well, That Escalated Quickly - Privesc 12](https://labs.bishopfox.com/tech-blog/privilege-escalation-in-aws) |
| IAM-PutUserPolicy | privesc10 | 无 | :fox_face: [Well, That Escalated Quickly - Privesc 10](https://labs.bishopfox.com/tech-blog/privilege-escalation-in-aws) |
| IAM-SetExistingDefaultPolicyVersion | privesc2 | 无 | :fox_face: [Well, That Escalated Quickly - Privesc 02](https://labs.bishopfox.com/tech-blog/privilege-escalation-in-aws) <br> :lock: [s3cur3.it IAMVulnerable - Part 2](https://s3cur3.it/home/practicing-aws-security-with-iamvulnerable-part-2) |
| **类别:使用 AWS 服务进行权限提升** | | | |
| EC2InstanceConnect-SendSSHPublicKey | privesc-instanceConnect | EC2 | 🔑 [AWS IAM privilege escalation paths](https://pswalia2u.medium.com/aws-iam-privilege-escalation-paths-cba36be1aa9e) |
| CloudFormation-UpdateStack | privesc-cfUpdateStack | CloudFormation | 🔑 [AWS IAM privilege escalation paths](https://pswalia2u.medium.com/aws-iam-privilege-escalation-paths-cba36be1aa9e) |
| Glue-UpdateExistingGlueDevEndpoint | privesc19 | Glue | :fox_face: [Well, That Escalated Quickly - Privesc 19](https://labs.bishopfox.com/tech-blog/privilege-escalation-in-aws) |
| Lambda-EditExistingLambdaFunctionWithRole | privesc17 | Lambda | :fox_face: [Well, That Escalated Quickly - Privesc 17](https://labs.bishopfox.com/tech-blog/privilege-escalation-in-aws) <br> :lock: [s3cur3.it IAMVulnerable - Part 4](https://s3cur3.it/home/practicing-aws-security-with-iamvulnerable-part-4) |
| SageMakerCreatePresignedNotebookURL | privesc-sageUpdateURL | SageMaker | :rhinoceros: [AWS IAM Privilege Escalation - Method 3](https://rhinosecuritylabs.com/aws/aws-privilege-escalation-methods-mitigation-part-2/) |
| SSM-SendCommand | privesc-ssm-command | EC2 | 🔑 [AWS IAM privilege escalation paths](https://pswalia2u.medium.com/aws-iam-privilege-escalation-paths-cba36be1aa9e) |
| SSM-StartSession | privesc-ssm-session | EC2 | 🔑 [AWS IAM privilege escalation paths](https://pswalia2u.medium.com/aws-iam-privilege-escalation-paths-cba36be1aa9e) |
| STS-AssumeRole | privesc-assumerole | 无 | 🔑 [AWS IAM privilege escalation paths](https://pswalia2u.medium.com/aws-iam-privilege-escalation-paths-cba36be1aa9e) |
| **类别:更新 AssumeRole 策略** | | | |
| IAM-UpdatingAssumeRolePolicy | privesc14 | 无 | :fox_face: [Well, That Escalated Quickly - Privesc 14](https://labs.bishopfox.com/tech-blog/privilege-escalation-in-aws) |

# 其他使用场景

#### 默认 - 未配置 `terraform.tfvars`
* 使用默认 AWS 配置文件(Default)进行部署
* 所有创建的角色均可由运行 Terraform 的主体(在默认配置文件中指定)担任

#### 使用非默认配置文件运行 Terraform
* 将 `terraform.tfvars.example` 复制为 `terraform.tfvars`
* 取消注释 `#aws_local_profile = "profile_name"` 并输入要使用的配置文件名称
* 如果你使用了非默认配置文件,并且仍想使用 `aws_credentials_file_example` 文件,可以使用以下命令生成适用于非默认配置文件名称的 AWS 凭证文件(感谢 @scriptingislife)
   * 记得将 `nondefaultuser` 替换为你所使用的配置文件名称:
   * `tail -n +7 aws_credentials_file_example | sed -e "s/111111111111/$(aws sts get-caller-identity | grep Account | awk -F\" '{print $4}')/g;s/default/nondefaultuser/g" >> ~/.aws/credentials`

#### 使用除调用者以外的 ARN 作为可担任新创建角色的主体

* 将 `terraform.tfvars.example` 复制为 `terraform.tfvars`
* 取消注释 `#aws_assume_role_arn = "arn:aws:iam::112233445566:user/you"` 并输入要使用的 ARN

创建后,每个权限提升角色均可由你指定的主体(ARN)担任。

#### 在账户 X 中创建资源,但使用账户 Y 的 ARN 作为可担任新创建角色的主体

如果你配置了可假定其他账户角色的 AWS CLI 配置文件,则需要指定配置文件名称,并手动指定要用于承担不同角色的 ARN。

在以下示例中,资源将在与 `"prod-cross-org-access-role"` 关联的账户中创建,但 Terraform 创建的每个角色均可由属于另一个账户的 `"arn:aws:iam::112233445566:user/you"` 访问。```
aws_local_profile = "prod-cross-org-access-role"
aws_assume_role_arn = "arn:aws:iam::112233445566:user/you"

常见问题解答

IAM Vulnerable 与 CloudGoat、Terragoat 和 SadCloud 相比如何?

这些工具都使用 Terraform 在 AWS 上部署有意的脆弱基础设施。然而,IAM Vulnerable 的重点是 IAM 权限提升,而其他工具要么不涉及 IAM 权限提升,要么只涵盖部分场景。

  • CloudGoat 部署了八个独特场景,其中一些涉及 IAM 权限提升路径,另一些则专注于其他领域,如 EC2 元数据中的密钥。
  • Terragoat 和 SadCloud 都聚焦于云账户的错误配置方式,但不涉及 IAM 权限提升路径。事实上,你可以将 IAM Vulnerable 视为与 Terragoat 或 SadCloud 配合使用时缺失的一块拼图。这些有意的脆弱配置是互补的。

IAM Vulnerable 与 Cloudsplaining、AWSPX、Principal Mapper、Pacu、Cloudmapper 或 ScoutSuite 相比如何?

所有这些工具都有助于识别 AWS 环境中现有的错误配置。有些工具(如 Pacu)还能帮助你利用这些错误配置。相比之下,IAM Vulnerable 创建了有意的脆弱基础设施。如果你真想学习如何使用 Principal Mapper (PMapper)、AWSPX、Pacu 和 Cloudsplaining 这类工具,那么 IAM Vulnerable 就是为你准备的。

我从没用过 Terraform,有点害怕。帮帮我!?

我以前也害怕 Terraform 以及那些会在我的账户中创建资源的项目,那时我还不知道 Terraform 是如何工作的。以下是一些可能缓解你焦虑的方法:

  • 通过使用一个专门用于此目的的 AWS 账户,你可以放心,这个仓库不会对你关心的其他任何事情产生负面影响。即使你在 AWS 组织中的独立账户中部署 IAM Vulnerable,你也可以放心,组织中的其他账户将不受此实验账户的破坏范围影响。
  • terraform plan 命令是一个预演。它会在你实际运行 terraform apply 之前精确显示将要部署的内容。
  • 请放心,你可以通过 terraform destroy 销毁任何使用 terraform apply 部署的内容,从而获得一个干净的环境。
  • 如果你担心成本,可以查看 Infracost。下载此二进制文件,注册获取免费 API 密钥,然后在像 iam-vulnerable 这样的 Terraform 目录中执行它。该工具会运行 terraform plan,并根据当前配置计算与该计划相关的月度成本。我就是用这个工具来填充上面模块成本估算表的。

我能在同一个 AWS 账户中同时运行这个工具和另一个工具(如 CloudGoat、Terragoat 或 SadCloud)吗?

可以。每个工具都会独立维护其 Terraform 状态,但所有资源将在同一账户中创建、更新和删除,并且它们可以共存。

先前工作与优秀参考

  • https://github.com/RhinoSecurityLabs/AWS-IAM-Privilege-Escalation
  • https://rhinosecuritylabs.com/aws/aws-privilege-escalation-methods-mitigation/
  • https://rhinosecuritylabs.com/aws/aws-privilege-escalation-methods-mitigation-part-2/
  • https://labs.bishopfox.com/tech-blog/privilege-escalation-in-aws
  • https://ermetic.com/whats-new/blog/aws/auditing-passrole-a-problematic-privilege-escalation-permission/
下载工具
  • (可选)将 IAM 漏洞环境配置文件添加到你的 AWS 凭证文件中,并更改账户号码。
    • 以下命令会备份你当前的 AWS 凭证文件,然后从仓库中获取示例凭证文件,将占位符账户替换为目标账户号码,最后将所有 IAM 漏洞环境权限提升配置文件添加到你的凭证文件中,以便你可以使用它们:
    • cp ~/.aws/credentials ~/.aws/credentials.backup
    • tail -n +7 aws_credentials_file_example | sed s/111111111111/$(aws sts get-caller-identity | grep Account | awk -F\" '{print $4}')/g >> ~/.aws/credentials