AWS - IAM, पहचान केंद्र और SSO Enum
Reading time: 14 minutes
tip
AWS हैकिंग सीखें और अभ्यास करें:HackTricks Training AWS Red Team Expert (ARTE)
GCP हैकिंग सीखें और अभ्यास करें: HackTricks Training GCP Red Team Expert (GRTE)
Azure हैकिंग सीखें और अभ्यास करें:
HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks का समर्थन करें
- सदस्यता योजनाओं की जांच करें!
- हमारे 💬 Discord समूह या टेलीग्राम समूह में शामिल हों या हमें Twitter 🐦 @hacktricks_live** पर फॉलो करें।**
- हैकिंग ट्रिक्स साझा करें, PRs को HackTricks और HackTricks Cloud गिटहब रिपोजिटरी में सबमिट करके।
IAM
आप IAM का विवरण यहाँ पा सकते हैं:
Enumeration
मुख्य अनुमतियाँ आवश्यक हैं:
iam:ListPolicies
,iam:GetPolicy
औरiam:GetPolicyVersion
iam:ListRoles
iam:ListUsers
iam:ListGroups
iam:ListGroupsForUser
iam:ListAttachedUserPolicies
iam:ListAttachedRolePolicies
iam:ListAttachedGroupPolicies
iam:ListUserPolicies
औरiam:GetUserPolicy
iam:ListGroupPolicies
औरiam:GetGroupPolicy
iam:ListRolePolicies
और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
Permissions Brute Force
यदि आप अपनी अनुमतियों में रुचि रखते हैं लेकिन आपके पास IAM को क्वेरी करने का एक्सेस नहीं है, तो आप हमेशा उन्हें ब्रूट-फोर्स कर सकते हैं।
bf-aws-permissions
टूल bf-aws-permissions बस एक बैश स्क्रिप्ट है जो निर्दिष्ट प्रोफ़ाइल का उपयोग करके सभी list*
, describe*
, get*
क्रियाएँ चलाएगी जो इसे aws
cli सहायता संदेशों का उपयोग करके मिल सकती हैं और सफल कार्यान्वयन लौटाएगी।
# 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 लॉग का विश्लेषण करता है ताकि सभी या केवल एक विशिष्ट उपयोगकर्ता या भूमिका द्वारा किए गए कार्यों को निकाला और संक्षेपित किया जा सके। यह उपकरण निर्दिष्ट बकेट से हर क्लाउडट्रेल लॉग को पार्स करेगा।
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 स्थिति फ़ाइलें) या CloudFormation फ़ाइलें (ये आमतौर पर एक बकेट के अंदर cf-templates उपसर्ग के साथ स्थित yaml फ़ाइलें होती हैं) पाते हैं, तो आप उन्हें aws कॉन्फ़िगरेशन खोजने और यह पता लगाने के लिए भी पढ़ सकते हैं कि किसे कौन सी अनुमतियाँ दी गई हैं।
enumerate-iam
इस टूल https://github.com/andresriancho/enumerate-iam का उपयोग करने के लिए, आपको पहले सभी API AWS एंडपॉइंट्स डाउनलोड करने की आवश्यकता है, जिनमें से स्क्रिप्ट generate_bruteforce_tests.py
सभी "list_", "describe_", और "get_" एंडपॉइंट्स प्राप्त करेगी। और अंत में, यह दिए गए क्रेडेंशियल्स के साथ उन्हें एक्सेस करने की कोशिश करेगी और यह बताएगी कि क्या यह सफल रहा।
(मेरे अनुभव में यह टूल किसी बिंदु पर लटक जाता है, इस फिक्स को देखें इसे ठीक करने के लिए प्रयास करने के लिए)।
warning
मेरे अनुभव में यह टूल पिछले वाले की तरह है लेकिन खराब काम कर रहा है और कम अनुमतियों की जांच कर रहा है।
# 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 अनुमतियों और कुछ privesc अनुमतियों की भी जांच करेगा)। लेकिन यह केवल कोडेड जांचों की जांच करेगा (अधिक चीजों की जांच करने का एकमात्र तरीका अधिक परीक्षण कोड करना है)।
# 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 पोस्ट एक्सप्लोइटेशन
IAM स्थिरता
IAM पहचान केंद्र
आप IAM पहचान केंद्र का विवरण यहाँ पा सकते हैं:
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
Enumeration
Identity Center के मुख्य तत्व हैं:
- उपयोगकर्ता और समूह
- अनुमति सेट: नीतियाँ संलग्न हैं
- AWS खाते
फिर, संबंध बनाए जाते हैं ताकि उपयोगकर्ता/समूहों के पास AWS खाते पर अनुमति सेट हो।
note
ध्यान दें कि अनुमति सेट पर नीतियाँ संलग्न करने के 3 तरीके हैं। AWS प्रबंधित नीतियाँ संलग्न करना, ग्राहक प्रबंधित नीतियाँ (ये नीतियाँ उन सभी खातों में बनाई जानी चाहिए जिन पर अनुमति सेट प्रभाव डाल रहा है), और इनलाइन नीतियाँ (जो वहाँ परिभाषित हैं)।
# 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 के माध्यम से सुलभ हैं, उदाहरण के लिए:
[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 के माध्यम से रोल्स को असुम करते हैं (बिना 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
- एक समूह बनाएं और इसे अनुमतियाँ सौंपें और उस पर एक नियंत्रित उपयोगकर्ता सेट करें
- एक नियंत्रित उपयोगकर्ता या समूह को अतिरिक्त अनुमतियाँ दें
- डिफ़ॉल्ट रूप से, केवल प्रबंधन खाते से अनुमतियों वाले उपयोगकर्ता IAM पहचान केंद्र तक पहुँच और नियंत्रण करने में सक्षम होंगे।
हालांकि, यह डेलीगेट एडमिनिस्ट्रेटर के माध्यम से संभव है कि एक अलग खाते के उपयोगकर्ताओं को इसे प्रबंधित करने की अनुमति दी जाए। उनके पास बिल्कुल वही अनुमति नहीं होगी, लेकिन वे प्रबंधन गतिविधियाँ करने में सक्षम होंगे।
tip
AWS हैकिंग सीखें और अभ्यास करें:HackTricks Training AWS Red Team Expert (ARTE)
GCP हैकिंग सीखें और अभ्यास करें: HackTricks Training GCP Red Team Expert (GRTE)
Azure हैकिंग सीखें और अभ्यास करें:
HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks का समर्थन करें
- सदस्यता योजनाओं की जांच करें!
- हमारे 💬 Discord समूह या टेलीग्राम समूह में शामिल हों या हमें Twitter 🐦 @hacktricks_live** पर फॉलो करें।**
- हैकिंग ट्रिक्स साझा करें, PRs को HackTricks और HackTricks Cloud गिटहब रिपोजिटरी में सबमिट करके।