AWS - IAM、Identity Center & SSO 列挙
Tip
学んで実践する AWS Hacking:
HackTricks Training AWS Red Team Expert (ARTE)
学んで実践する GCP Hacking:HackTricks Training GCP Red Team Expert (GRTE)
学んで実践する Az Hacking:HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks をサポートする
- subscription plans を確認してください!
- 参加する 💬 Discord group または telegram group に参加するか、Twitter 🐦 @hacktricks_live をフォローしてください。
- Share hacking tricks by submitting PRs to the HackTricks and HackTricks Cloud github repos.
IAM
IAMの説明は次で確認できます:
列挙
必要な主な権限:
iam:ListPolicies,iam:GetPolicyandiam:GetPolicyVersioniam:ListRolesiam:ListUsersiam:ListGroupsiam:ListGroupsForUseriam:ListAttachedUserPoliciesiam:ListAttachedRolePoliciesiam:ListAttachedGroupPoliciesiam:ListUserPoliciesandiam:GetUserPolicyiam:ListGroupPoliciesandiam:GetGroupPolicyiam:ListRolePoliciesandiam:GetRolePolicy
# All IAMs
## Retrieves information about all IAM users, groups, roles, and policies
## in your Amazon Web Services account, including their relationships to
## one another. Use this operation to obtain a snapshot of the configura-
## tion of IAM permissions (users, groups, roles, and policies) in your
## account.
aws iam get-account-authorization-details
# List users
aws iam get-user #Get current user information
aws iam list-users
aws iam list-ssh-public-keys #User keys for CodeCommit
aws iam get-ssh-public-key --user-name <username> --ssh-public-key-id <id> --encoding SSH #Get public key with metadata
aws iam list-service-specific-credentials #Get special permissions of the IAM user over specific services
aws iam get-user --user-name <username> #Get metadata of user, included permissions boundaries
aws iam list-access-keys #List created access keys
## inline policies
aws iam list-user-policies --user-name <username> #Get inline policies of the user
aws iam get-user-policy --user-name <username> --policy-name <policyname> #Get inline policy details
## attached policies
aws iam list-attached-user-policies --user-name <username> #Get policies of user, it doesn't get inline policies
# List groups
aws iam list-groups #Get groups
aws iam list-groups-for-user --user-name <username> #Get groups of a user
aws iam get-group --group-name <name> #Get group name info
## inline policies
aws iam list-group-policies --group-name <username> #Get inline policies of the group
aws iam get-group-policy --group-name <username> --policy-name <policyname> #Get an inline policy info
## attached policies
aws iam list-attached-group-policies --group-name <name> #Get policies of group, it doesn't get inline policies
# List roles
aws iam list-roles #Get roles
aws iam get-role --role-name <role-name> #Get role
## inline policies
aws iam list-role-policies --role-name <name> #Get inline policies of a role
aws iam get-role-policy --role-name <name> --policy-name <name> #Get inline policy details
## attached policies
aws iam list-attached-role-policies --role-name <role-name> #Get policies of role, it doesn't get inline policies
# List policies
aws iam list-policies [--only-attached] [--scope Local]
aws iam list-policies-granting-service-access --arn <identity> --service-namespaces <svc> # Get list of policies that give access to the user to the service
## Get policy content
aws iam get-policy --policy-arn <policy_arn>
aws iam list-policy-versions --policy-arn <arn>
aws iam get-policy-version --policy-arn <arn:aws:iam::975426262029:policy/list_apigateways> --version-id <VERSION_X>
# Enumerate providers
aws iam list-saml-providers
aws iam get-saml-provider --saml-provider-arn <ARN>
aws iam list-open-id-connect-providers
aws iam get-open-id-connect-provider --open-id-connect-provider-arn <ARN>
# Password Policy
aws iam get-account-password-policy
# MFA
aws iam list-mfa-devices
aws iam list-virtual-mfa-devices
意図的な失敗によるステルス権限確認
List*やシミュレータAPIがブロックされている場合、予測可能なバリデーションエラーを発生させることで、永続的なリソースを作成することなく変更権限を確認できます。AWSはこれらのエラーを返す前にIAM評価を行うため、エラーが返されることは呼び出し元がそのアクションを持っていることの証明になります:
# Confirm iam:CreateUser without creating a new principal (fails only after authz)
aws iam create-user --user-name <existing_user> # -> EntityAlreadyExistsException
# Confirm iam:CreateLoginProfile while learning password policy requirements
aws iam create-login-profile --user-name <target_user> --password lower --password-reset-required # -> PasswordPolicyViolationException
These attempts still generate CloudTrail events (with errorCode set) but avoid leaving new IAM artifacts, making them useful for low-noise permission validation during interactive recon.
Permissions Brute Force
If you are interested in your own permissions but you don’t have access to query IAM you could always brute-force them.
bf-aws-permissions
The tool bf-aws-permissions is just a bash script that will run using the indicated profile all the list*, describe*, get* actions it can find using aws cli help messages and return the successful executions.
# Bruteforce permissions
bash bf-aws-permissions.sh -p default > /tmp/bf-permissions-verbose.txt
bf-aws-perms-simulate
ツール bf-aws-perms-simulate は、権限 iam:SimulatePrincipalPolicy を持っていれば、自分の現在の権限(または他のプリンシパルの権限)を確認できます。
# Ask for permissions
python3 aws_permissions_checker.py --profile <AWS_PROFILE> [--arn <USER_ARN>]
Perms2ManagedPolicies
もしあなたのユーザが持ついくつかの権限を見つけ、それらが(カスタムロールではなく)AWSマネージドロールによって付与されていると思われる場合、ツール aws-Perms2ManagedRoles を使って、あなたが発見した権限を付与するすべてのAWSマネージドロールを確認できます。
# Run example with my profile
python3 aws-Perms2ManagedPolicies.py --profile myadmin --permissions-file example-permissions.txt
Warning
例えば、使われていないサービスに対する権限を持っていることが分かれば、その権限がAWSマネージドロールによって付与されているかどうかを「知る」ことが可能です。
Cloudtrail2IAM
CloudTrail2IAM は Python 製のツールで、AWS CloudTrail のログを解析して実行されたアクションを抽出・要約します。全ユーザー分、または特定のユーザーやロールのみを対象にできます。ツールは指定したバケットからすべての CloudTrail ログを解析します。
git clone https://github.com/carlospolop/Cloudtrail2IAM
cd Cloudtrail2IAM
pip install -r requirements.txt
python3 cloudtrail2IAM.py --prefix PREFIX --bucket_name BUCKET_NAME --profile PROFILE [--filter-name FILTER_NAME] [--threads THREADS]
Warning
.tfstate (Terraform state files) or CloudFormation files(これらは通常プレフィックス cf-templates の bucket 内にある yaml ファイルです)を見つけた場合、それらを読み取って aws の設定を確認し、どの権限が誰に割り当てられているかを特定することもできます。
enumerate-iam
To use the tool https://github.com/andresriancho/enumerate-iam you first need to download all the API AWS endpoints, from those the script generate_bruteforce_tests.py will get all the “list_”, “describe_”, and “get_” endpoints. And finally, it will try to access them with the given credentials and indicate if it worked.
(In my experience the tool hangs at some point, checkout this fix to try to fix that).
Warning
私の経験ではこのツールは前のものと似ていますが、動作が悪くチェックする permissions が少ないです。
# Install tool
git clone git@github.com:andresriancho/enumerate-iam.git
cd enumerate-iam/
pip install -r requirements.txt
# Download API endpoints
cd enumerate_iam/
git clone https://github.com/aws/aws-sdk-js.git
python3 generate_bruteforce_tests.py
rm -rf aws-sdk-js
cd ..
# Enumerate permissions
python3 enumerate-iam.py --access-key ACCESS_KEY --secret-key SECRET_KEY [--session-token SESSION_TOKEN] [--region REGION]
weirdAAL
ツールweirdAALを使うこともできます。 このツールはいくつかの一般的なサービスにおけるいくつかの一般的な操作をチェックします(いくつかの enumeration permissions および privesc permissions をチェックします)。 しかし、コード化されたチェックのみを実行するため、より多くの項目をチェックするには追加のテストをコーディングする必要があります。
# Install
git clone https://github.com/carnal0wnage/weirdAAL.git
cd weirdAAL
python3 -m venv weirdAAL
source weirdAAL/bin/activate
pip3 install -r requirements.txt
# Create a .env file with aws credentials such as
[default]
aws_access_key_id = <insert key id>
aws_secret_access_key = <insert secret key>
# Setup DB
python3 create_dbs.py
# Invoke it
python3 weirdAAL.py -m ec2_describe_instances -t ec2test # Just some ec2 tests
python3 weirdAAL.py -m recon_all -t MyTarget # Check all permissions
# You will see output such as:
# [+] elbv2 Actions allowed are [+]
# ['DescribeLoadBalancers', 'DescribeAccountLimits', 'DescribeTargetGroups']
BF 権限を強化するツール
# Export env variables
./index.js --console=text --config ./config.js --json /tmp/out-cloudsploit.json
# Filter results removing unknown
jq 'map(select(.status | contains("UNKNOWN") | not))' /tmp/out-cloudsploit.json | jq 'map(select(.resource | contains("N/A") | not))' > /tmp/out-cloudsploit-filt.json
# Get services by regions
jq 'group_by(.region) | map({(.[0].region): ([map((.resource | split(":"))[2]) | unique])})' ~/Desktop/pentests/cere/greybox/core-dev-dev-cloudsploit-filtered.json
<YourTool>
前述のどちらのツールも、ほとんどすべての権限をチェックできるわけではありません。より良いツールを知っている場合は、PRを送ってください!
未認証アクセス
AWS - IAM & STS Unauthenticated Enum
権限昇格
以下のページで、権限昇格のためにIAMの権限を悪用する方法を確認できます:
IAM Post Exploitation
IAM Persistence
IAM Identity Center
IAM Identity Centerの説明は以下にあります:
CLIでSSO経由で接続
# Connect with sso via CLI aws configure sso
aws configure sso
[profile profile_name]
sso_start_url = https://subdomain.awsapps.com/start/
sso_account_id = <account_numbre>
sso_role_name = AdministratorAccess
sso_region = us-east-1
列挙
Identity Center の主な要素は:
- ユーザーとグループ
- Permission Sets: ポリシーがアタッチされる
- AWS Accounts
その後、ユーザー/グループがAWS Accountに対してPermission Setsを持つように関係が作成されます。
Note
Permission Set にポリシーをアタッチする方法は3つあります。AWS managed policies をアタッチする、Customer managed policies(これらのポリシーはPermission Set が影響するすべてのアカウントで作成する必要があります)をアタッチする、そして inline policies(その中に定義される)です。
# Check if IAM Identity Center is used
aws sso-admin list-instances
# Get Permissions sets. These are the policies that can be assigned
aws sso-admin list-permission-sets --instance-arn <instance-arn>
aws sso-admin describe-permission-set --instance-arn <instance-arn> --permission-set-arn <perm-set-arn>
## Get managed policies of a permission set
aws sso-admin list-managed-policies-in-permission-set --instance-arn <instance-arn> --permission-set-arn <perm-set-arn>
## Get inline policies of a permission set
aws sso-admin get-inline-policy-for-permission-set --instance-arn <instance-arn> --permission-set-arn <perm-set-arn>
## Get customer managed policies of a permission set
aws sso-admin list-customer-managed-policy-references-in-permission-set --instance-arn <instance-arn> --permission-set-arn <perm-set-arn>
## Get boundaries of a permission set
aws sso-admin get-permissions-boundary-for-permission-set --instance-arn <instance-arn> --permission-set-arn <perm-set-arn>
## List accounts a permission set is affecting
aws sso-admin list-accounts-for-provisioned-permission-set --instance-arn <instance-arn> --permission-set-arn <perm-set-arn>
## List principals given a permission set in an account
aws sso-admin list-account-assignments --instance-arn <instance-arn> --permission-set-arn <perm-set-arn> --account-id <account_id>
# Get permissions sets affecting an account
aws sso-admin list-permission-sets-provisioned-to-account --instance-arn <instance-arn> --account-id <account_id>
# List users & groups from the identity store
aws identitystore list-users --identity-store-id <store-id>
aws identitystore list-groups --identity-store-id <store-id>
## Get members of groups
aws identitystore list-group-memberships --identity-store-id <store-id> --group-id <group-id>
## Get memberships or a user or a group
aws identitystore list-group-memberships-for-member --identity-store-id <store-id> --member-id <member-id>
ローカル列挙
フォルダ $HOME/.aws 内に、SSO経由でアクセス可能なプロファイルを設定するためのファイル config を作成することができます。例えば:
[default]
region = us-west-2
output = json
[profile my-sso-profile]
sso_start_url = https://my-sso-portal.awsapps.com/start
sso_region = us-west-2
sso_account_id = 123456789012
sso_role_name = MySSORole
region = us-west-2
output = json
[profile dependent-profile]
role_arn = arn:aws:iam::<acc-id>:role/ReadOnlyRole
source_profile = Hacktricks-Admin
この構成は次のコマンドで使用できます:
# Login in ms-sso-profile
aws sso login --profile my-sso-profile
# Use dependent-profile
aws s3 ls --profile dependent-profile
情報にアクセスする際にSSOのプロファイルが使用されると、認証情報はフォルダ**$HOME/.aws/sso/cache内のファイルにキャッシュされます。したがって、そこから読み取って利用できます**。
さらに、より多くの認証情報がフォルダ**$HOME/.aws/cli/cacheに保存されることがあります。このキャッシュディレクトリは主に、AWS CLIのプロファイルを使用してIAMユーザーの認証情報を使う、またはIAMを介してロールをassume**する(SSOを使わない)場合に使用されます。設定例:
[profile crossaccountrole]
role_arn = arn:aws:iam::234567890123:role/SomeRole
source_profile = default
mfa_serial = arn:aws:iam::123456789012:mfa/saanvi
external_id = 123456
未認証アクセス
AWS - Identity Center & SSO Unauthenticated Enum
権限昇格
AWS - SSO & identitystore Privesc
侵害後の操作
AWS - SSO & identitystore Post Exploitation
永続化
ユーザーを作成して権限を割り当てる
# Create user identitystore:CreateUser
aws identitystore create-user --identity-store-id <store-id> --user-name privesc --display-name privesc --emails Value=sdkabflvwsljyclpma@tmmbt.net,Type=Work,Primary=True --name Formatted=privesc,FamilyName=privesc,GivenName=privesc
## After creating it try to login in the console using the selected username, you will receive an email with the code and then you will be able to select a password
- グループを作成し、そのグループに権限を割り当て、管理されたユーザーを設定する
- 管理されたユーザーまたはグループに追加の権限を付与する
- デフォルトでは、Management Account からの権限を持つユーザーのみが IAM Identity Center にアクセスして制御できます。
ただし、Delegate Administrator を介して別のアカウントのユーザーに管理を許可することが可能です。彼らはまったく同じ権限を持つわけではありませんが、management activities を実行できるようになります。
Tip
学んで実践する AWS Hacking:
HackTricks Training AWS Red Team Expert (ARTE)
学んで実践する GCP Hacking:HackTricks Training GCP Red Team Expert (GRTE)
学んで実践する Az Hacking:HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks をサポートする
- subscription plans を確認してください!
- 参加する 💬 Discord group または telegram group に参加するか、Twitter 🐦 @hacktricks_live をフォローしてください。
- Share hacking tricks by submitting PRs to the HackTricks and HackTricks Cloud github repos.
HackTricks Cloud

