IAMActionHunter是一款功能强大的AWS IAM策略声明解析和查询工具,旨在简化研究人员在 AWS IAM中收集和理解用户和角色权限策略语句的过程。
该工具的主要目的是通过查询可能被利用的各种 AWS IAM 操作来搜索 AWS 账户中潜在的安全风险,并以此来辅助安全管理人员提升AWS环境的安全性。
除此之外,该工具还提供了以 CSV 格式输出和保存查询结果的功能,这对于寻求 AWS 账户内主要权限和资源高级概览的安全团队非常有用。例如,你可能希望识别账户中具有iam:put*权限的用户和角色。通过执行查询并生成 CSV,你可以轻松查看具有这些权限的所有用户和角色,以及他们有权访问的资源。
boto3==1.26.113
botocore==1.29.113
colorama==0.4.6
jmespath==1.0.1
numpy==1.24.2
pandas==2.0.0
policyuniverse==1.5.0.20220613
python-dateutil==2.8.2
pytz==2023.3
s3transfer==0.6.0
six==1.16.0
tzdata==2023.3
urllib3==1.26.15
由于该工具基于Python 3开发,因此我们首先需要在本地设备上安装并配置好最新版本的Python 3环境。
源码获取
广大研究人员可以直接使用下列命令将该项目源码克隆至本地:
git clone https://github.com/RhinoSecurityLabs/IAMActionHunter.git
poetry使用
切换到项目目录中:
cd IAMActionHunter
运行下列命令启动poetry和IAMActionHunter:
# (potentially necessary: poetry env use python3.9)
poetry install
iamactionhunter --help
iamactionhunter --collect --profile <some-aws-profile>
pip使用
切换到项目目录中,执行下列命令即可:
cd IAMActionHunter
pip install .
iamactionhunter --help
iamactionhunter --collect --profile <some-aws-profile>
usage: iamactionhunter [-h] [--profile PROFILE] [--account ACCOUNT] [--query QUERY] [--role ROLE] [--user USER]
[--all-or-none] [--collect] [--list] [--csv CSV] [--config CONFIG]
Collect all policies for all users/roles in an AWS account and then query the policies for permissions.
optional arguments:
-h, --help 显示此帮助消息并退出
--profile PROFILE 用于用户/角色收集身份验证的AWS配置文件名称
--account ACCOUNT 要查询的账号
--query QUERY 查询权限。提供一个类似于:s3:GetObject或s3:*或s3:GetObjects、s3:PutObject的字符串
--role ROLE 筛选要查询的角色
--user USER 筛选要查询的用户
--all-or-none 检查是否允许所有查询的操作
--collect 收集帐户的用户和角色策略
--list 列出可查询的帐户
--csv CSV 报告输出的csv文件名
--config CONFIG JSON配置文件用于预设查询
内置配置选项包括:
dangerous_iam
write_actions
privescs
iamactionhunter --account <account_number_of_profile> --config dangerous_iam
创建自定义配置
配置文件是一个 JSON 文件,它指定了你想要查找的一些特定权限。下面是一个在 CodeBuild 中搜索写入操作的示例文件。
[
{
"Description": "These are all actions which may allow some kind of write privilege in CodeBuild.",
"Name": "CodeBuildWriteActions",
"ActionsNeeded": [
"codebuild:Put*",
"codebuild:Create*",
"codebuild:Delete*",
"codebuild:Modify*",
"codebuild:Update*",
"codebuild:Attach*",
"codebuild:Detach*",
"codebuild:Associate*",
"codebuild:Disassociate*",
"codebuild:Add*",
"codebuild:Remove*",
"codebuild:Set*",
"codebuild:Enable*",
"codebuild:Disable*",
"codebuild:Reset*",
"codebuild:Stop*",
"codebuild:Terminate*",
"codebuild:Reboot*",
"codebuild:Start*"
],
"AllOrNone": false
}
]
然后,你只需在--config参数中指定文件名即可运行配置。
iamactionhunter --account <account_number_of_profile> --config write_code_build.json
下载用户和角色的所有 IAM 信息:
iamactionhunter --collect --profile my-aws-profile
列出已收集的所有帐户数据:
iamactionhunter --list
执行简单查询:
iamactionhunter --account <account_number_of_profile_above> --query iam:create*
查询更多信息:
iamactionhunter --account <account_number_of_profile_above> --query iam:create*,iam:put*
查询特定角色:
iamactionhunter --account <account_number_of_profile_above> --role some_role --query iam:*
查询特定用户:
iamactionhunter --account <account_number_of_profile_above> --user some_user --query iam:*
输出到 CSV:
iamactionhunter --account <account_number_of_profile_above> --query iam:* --csv report.csv
运行预设配置:
iamactionhunter --account <account_number_of_profile_above> --config dangerous_iam
运行查询,仅当用户或角色具有所有查询权限时才显示结果:
iamactionhunter --account <account_number_of_profile_above> --query s3:getobject,s3:listbucket --all-or-none
本项目的开发与发布遵循Apache-2.0开源许可协议。
IAMActionHunter:
https://github.com/RhinoSecurityLabs/IAMActionHunter
原文始发于微信公众号(FreeBuf):IAMActionHunter:一款AWS IAM策略声明解析和查询工具
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论