IAMActionHunter 是一个 IAM 策略语句解析与查询工具,旨在简化对 AWS 身份与访问管理(IAM)中用户和角色的权限策略语句的收集与理解过程。虽然功能简单,但该工具是为了应对日常 AWS 渗透测试中对高效解决方案的需求而开发的。
https://rhinosecuritylabs.com/aws/iamactionhunter-aws-iam-permissions/
该工具可用于通过查询可能被利用的各种 AWS IAM 操作,来搜索 AWS 账户中潜在的权限提升机会。虽然其他工具会执行扫描以识别权限提升风险,但该工具提供了更手动的方法,允许用户调查权限并快速查看所涉及的角色、用户和资源,以进行针对性分析。
该工具还支持以 CSV 格式输出并保存查询结果,这对于安全团队获取 AWS 账户中主体权限和资源的高层次概览非常有用。例如,您可能希望找出账户中拥有 iam:put* 权限的用户和角色。通过执行查询并生成 CSV,您可以轻松查看所有具有这些权限的用户和角色及其可访问的资源。
推荐方式:
pip3 install iamactionhunter
该工具的许多功能也已作为模块 iam__enum_action_query 集成到 https://github.com/RhinoSecurityLabs/pacu 中,如果您更倾向于使用 pacu。
克隆并使用 Poetry:
git clone https://github.com/RhinoSecurityLabs/IAMActionHunter.git
cd IAMActionHunter
# (可能必要:poetry env use python3.9)
poetry install
iamactionhunter --help
iamactionhunter --collect --profile <some-aws-profile>
克隆并使用 Pip:
git clone https://github.com/RhinoSecurityLabs/IAMActionHunter.git
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]
收集 AWS 账户中所有用户/角色的所有策略,然后查询策略以获取权限。
可选参数:
-h, --help 显示此帮助信息并退出
--profile PROFILE 用于用户/角色集合身份验证的 AWS 配置文件名称。
--account ACCOUNT 要查询的账户编号。
--query QUERY 要查询的权限。字符串形式如:s3:GetObject 或 s3:* 或 s3:GetObject,s3:PutObject
--role ROLE 过滤要查询的角色。
--user USER 过滤要查询的用户。
--all-or-none 检查是否允许所有查询的操作,而不仅仅是部分。
--collect 收集账户的用户和角色策略。
--list 列出可供查询的账户。
--csv CSV 用于 CSV 报告输出的文件名。
--config CONFIG 用于预设查询的 JSON 配置文件。
首先下载所有用户和角色的 IAM 信息:
iamactionhunter --collect --profile my-aws-profile
列出已为其收集数据的账户:
iamactionhunter --list
然后查询某些内容:
iamactionhunter --account <账户编号_来自上面的配置文件> --query iam:create*
然后查询更多:
iamactionhunter --account <账户编号_来自上面的配置文件> --query iam:create*,iam:put*
查询特定角色:
iamactionhunter --account <账户编号_来自上面的配置文件> --role some_role --query iam:*
查询特定用户:
iamactionhunter --account <账户编号_来自上面的配置文件> --user some_user --query iam:*
输出到 CSV:
iamactionhunter --account <账户编号_来自上面的配置文件> --query iam:* --csv report.csv
运行预设配置:
iamactionhunter --account <账户编号_来自上面的配置文件> --config dangerous_iam
运行仅当用户或角色拥有所有查询权限时才显示结果的查询:
iamactionhunter --account <账户编号_来自上面的配置文件> --query s3:getobject,s3:listbucket --all-or-none
内置配置选项有:
dangerous_iam
write_actions
privescs
iamactionhunter --account <账户编号_来自上面的配置文件> --config dangerous_iam
配置文件是一个 JSON 文件,用于指定您要查找的特定权限。以下是一个示例文件,用于搜索 CodeBuild 中的写入操作。
[
{
"Description": "这些是可能允许 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 <账户编号_来自上面的配置文件> --config write_code_build.json