AWS - IAM, Identity Center & SSO Enum

जानें AWS हैकिंग को शून्य से हीरो तक htARTE (HackTricks AWS Red Team Expert) के साथ!

HackTricks का समर्थन करने के अन्य तरीके:

IAM

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

pageAWS - Basic Information

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

अनुमतियों की ब्रूट फोर्स

यदि आप अपनी अनुमतियों में रुचि रखते हैं लेकिन आपके पास 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

यदि आप देखते हैं कि आपके पास अनुमतियाँ हैं जो उपयोग नहीं की जा रही हैं, तो संभावना है कि ये 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]

यदि आप .tfstate (Terraform state files) या CloudFormation files (ये आम तौर पर बाल्टी के अंदर स्थित yaml files होते हैं जिनका prefix cf-templates होता है), तो आप इन्हें पढ़ सकते हैं ताकि आप aws configuration ढूंढ सकें और यह भी पता लगा सकें कि किसे कौन सी अनुमतियाँ प्रदान की गई हैं।

enumerate-iam

टूल https://github.com/andresriancho/enumerate-iam का उपयोग करने के लिए पहले आपको सभी API AWS endpoints डाउनलोड करने की आवश्यकता है, उनमें से स्क्रिप्ट generate_bruteforce_tests.py सभी "list_", "describe_", और "get_" endpoints प्राप्त करेगा। और अंततः, यह कोशिश करेगा कि दिए गए credentials के साथ उन्हें एक्सेस करें और यह दिखाए कि काम किया गया है या नहीं

(मेरे अनुभव में टूल किसी समय फंस जाता है, इस सुधार को देखें जिसे सुधारने की कोशिश करें)।

मेरे अनुभव में यह टूल पिछले वाले टूल की तरह है लेकिन अधिक खराब काम कर रहा है और कम अनुमतियों की जांच कर रहा है।

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

वीर्डएएल

आप टूल वीर्डएएल का भी उपयोग कर सकते हैं। यह टूल कई सामान्य सेवाओं पर कई सामान्य कार्यों की जांच करेगा (कुछ जांच अनुमतियों और कुछ 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']

अनुमतियों को बीएफ करने के लिए हार्डनिंग टूल

# 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

<आपका टूल>

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

अप्रमाणित पहुंच

pageAWS - IAM & STS Unauthenticated Enum

विशेषाधिकार उन्नयन

निम्नलिखित पृष्ठ पर आप देख सकते हैं कि IAM अनुमतियों का दुरुपयोग करके विशेषाधिकारों को उन्नयन कैसे करें:

pageAWS - IAM Privesc

IAM पोस्ट एक्सप्लोइटेशन

pageAWS - IAM Post Exploitation

IAM स्थिरता

pageAWS - IAM Persistence

IAM पहचान केंद्र

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

pageAWS - Basic Information

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

गणना

पहचान केंद्र के मुख्य तत्व हैं:

  • उपयोगकर्ता और समूह

  • अनुमति सेट: जिसमें नीतियाँ जुड़ी होती हैं

  • AWS खाते

फिर, संबंध बनाए जाते हैं ताकि उपयोगकर्ता/समूहों के पास AWS खाते पर अनुमति सेट हो।

ध्यान दें कि एक अनुमति सेट पर नीतियों को जोड़ने के लिए 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>

स्थानीय जांच

यह संभव है कि फ़ोल्डर $HOME/.aws के अंदर फ़ाइल कॉन्फ़िग बनाना संभव है ताकि 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 के माध्यम से भूमिकाएँ अनुमानित करते हैं। कॉन्फ़िग उदाहरण:

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

अप्रमाणित पहुंच

pageAWS - Identity Center & SSO Unauthenticated Enum

विशेषाधिकार उन्नयन

pageAWS - SSO & identitystore Privesc

पोस्ट एक्सप्लोइटेशन

pageAWS - 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 पहचान केंद्र तक पहुंचने और नियंत्रण करने के लिए सक्षम होंगे।

हालांकि, डेलीगेट प्रशासक के माध्यम से इसे प्रबंधित करने के लिए एक विभिन्न खाते से उपयोगकर्ताओं को अनुमति देना संभव है। उनके पास ठीक वही अनुमति नहीं होगी, लेकिन वे प्रबंधन गतिविधियाँ कर सकेंगे।

जानें AWS हैकिंग को शून्य से हीरो तक htARTE (HackTricks AWS Red Team Expert) के साथ!

HackTricks का समर्थन करने के अन्य तरीके:

Last updated