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 का समर्थन करें

IAM

आप IAM का विवरण यहाँ पा सकते हैं:

AWS - Basic Information

एन्यूमरेशन

आवश्यक मुख्य अनुमतियाँ:

  • iam:ListPolicies, iam:GetPolicy and iam:GetPolicyVersion
  • iam:ListRoles
  • iam:ListUsers
  • iam:ListGroups
  • iam:ListGroupsForUser
  • iam:ListAttachedUserPolicies
  • iam:ListAttachedRolePolicies
  • iam:ListAttachedGroupPolicies
  • iam:ListUserPolicies and iam:GetUserPolicy
  • iam:ListGroupPolicies and iam:GetGroupPolicy
  • iam:ListRolePolicies and iam: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

Stealth permission confirmation — जानबूझकर विफलताओं के माध्यम से

जब List* या simulator APIs ब्लॉक हों, तो आप पूर्वानुमेय validation त्रुटियों को जबरदस्ती उत्पन्न करके परिवर्तनकारी अनुमतियाँ बिना स्थायी संसाधन बनाए पुष्टि कर सकते हैं। AWS इन त्रुटियों को वापस करने से पहले IAM का मूल्यांकन करता है, इसलिए त्रुटि देखना यह साबित करता है कि कॉलर के पास वह action है:

# 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

यदि आप अपनी स्वयं की permissions में रुचि रखते हैं लेकिन IAM को query करने का access नहीं है, तो आप उन्हें हमेशा brute-force कर सकते हैं।

bf-aws-permissions

यह टूल bf-aws-permissions सिर्फ़ एक bash script है जो निर्दिष्ट profile का उपयोग करके aws cli के help messages में मिलने वाली सभी list*, describe*, get* actions चलाएगा और सफल निष्पादनों को वापस करेगा

# Bruteforce permissions
bash bf-aws-permissions.sh -p default > /tmp/bf-permissions-verbose.txt

bf-aws-perms-simulate

यह टूल bf-aws-perms-simulate आपकी वर्तमान अनुमति (या अन्य principals की अनुमति) पता लगा सकता है अगर आपके पास अनुमति iam:SimulatePrincipalPolicy है।

# Ask for permissions
python3 aws_permissions_checker.py --profile <AWS_PROFILE> [--arn <USER_ARN>]

Perms2ManagedPolicies

यदि आपने कुछ अनुमतियाँ जो आपके यूजर के पास हैं पाई हैं, और आपको लगता है कि वे किसी managed AWS role (और किसी custom role से नहीं) द्वारा दी जा रही हैं, तो आप टूल aws-Perms2ManagedRoles का उपयोग करके उन सभी AWS managed roles की जाँच कर सकते हैं जो उन अनुमतियों को प्रदान करते हैं जिन्हें आपने पाया है।

# Run example with my profile
python3 aws-Perms2ManagedPolicies.py --profile myadmin --permissions-file example-permissions.txt

Warning

यह संभव है कि आप “जान” सकें कि जो अनुमतियाँ आपके पास हैं वे एक AWS managed role द्वारा प्रदान की गई हैं, अगर आप उदाहरण के लिए देखते हैं कि आपके पास उन सेवाओं पर अनुमतियाँ हैं जो उपयोग नहीं हो रही हैं

Cloudtrail2IAM

CloudTrail2IAM एक Python टूल है जो AWS CloudTrail logs का विश्लेषण करके सभी या किसी विशिष्ट उपयोगकर्ता/भूमिका द्वारा किए गए कार्यों को निकालता और सारांशित करता है। यह टूल संकेत किए गए bucket से हर cloudtrail log को पार्स करेगा

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) या CloudFormation फ़ाइलें (ये आमतौर पर किसी bucket के अंदर cf-templates प्रीफ़िक्स वाली yaml फ़ाइलें होती हैं) मिलती हैं, तो आप इन्हें पढ़कर aws कॉन्फ़िगरेशन और पता कर सकते हैं कि किसे कौन-कौन सी permissions आवंटित की गई हैं।

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.

(मेरे अनुभव में tool कुछ बिंदु पर hang कर जाता है, checkout this fix ताकि इसे ठीक करने की कोशिश की जा सके)।

Warning

मेरे अनुभव में यह tool पिछले वाले जैसा ही है पर कम प्रभावी रूप से काम करता है और कम 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 भी जांचेगा)। लेकिन यह केवल coded checks को ही जांचेगा (अधिक चीज़ें जांचने का एकमात्र तरीका है कि आप और टेस्ट कोड करें)।

# 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 permissions के लिए हार्डनिंग टूल्स

# 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>

पिछलों में से कोई भी टूल सभी permissions की जाँच करने में सक्षम नहीं है, इसलिए अगर आप किसी बेहतर टूल को जानते हैं तो एक PR भेजें!

Unauthenticated Access

AWS - IAM & STS Unauthenticated Enum

Privilege Escalation

निम्नलिखित पृष्ठ में आप देख सकते हैं कि कैसे abuse IAM permissions to escalate privileges:

AWS - IAM Privesc

IAM Post Exploitation

AWS - IAM Post Exploitation

IAM Persistence

AWS - IAM Persistence

IAM Identity Center

आप IAM Identity Center का विवरण निम्न में पा सकते हैं:

AWS - Basic Information

Connect via SSO with CLI

# 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 (इन नीतियों को उन सभी accounts में बनाना होगा जिन पर 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>

Local Enumeration

आप $HOME/.aws फ़ोल्डर के अंदर config फ़ाइल बना कर SSO के माध्यम से एक्सेस किए जा सकने वाले profiles कॉन्फ़िगर कर सकते हैं, उदाहरण के लिए:

[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

जब किसी जानकारी तक पहुँचने के लिए profile from SSO is used, तो credentials फ़ाइल में cached होते हैं जो फ़ोल्डर $HOME/.aws/sso/cache के अंदर रहती है। इसलिए उन्हें read and used from there किया जा सकता है।

इसके अलावा, more credentials फ़ोल्डर $HOME/.aws/cli/cache में संग्रहीत की जा सकती हैं। यह cache directory मुख्य रूप से तब उपयोग में आती है जब आप working with AWS CLI profiles हैं जो IAM user credentials का उपयोग करते हैं या IAM के माध्यम से रोल assume करते हैं (बिना SSO)। Config example:

[profile crossaccountrole]
role_arn = arn:aws:iam::234567890123:role/SomeRole
source_profile = default
mfa_serial = arn:aws:iam::123456789012:mfa/saanvi
external_id = 123456

Unauthenticated Access

AWS - Identity Center & SSO Unauthenticated Enum

Privilege Escalation

AWS - SSO & identitystore Privesc

Post Exploitation

AWS - SSO & identitystore Post Exploitation

Persistence

एक user बनाएं और उसे permissions सौंपें

# 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 का समर्थन करें