# AWS - IAM, पहचान केंद्र और SSO Enum {{#include ../../../banners/hacktricks-training.md}} ## IAM आप IAM का **विवरण** यहाँ पा सकते हैं: {{#ref}} ../aws-basic-information/ {{#endref}} ### 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` ```bash # 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 --ssh-public-key-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 #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 #Get inline policies of the user aws iam get-user-policy --user-name --policy-name #Get inline policy details ## attached policies aws iam list-attached-user-policies --user-name #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 #Get groups of a user aws iam get-group --group-name #Get group name info ## inline policies aws iam list-group-policies --group-name #Get inline policies of the group aws iam get-group-policy --group-name --policy-name #Get an inline policy info ## attached policies aws iam list-attached-group-policies --group-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 #Get role ## inline policies aws iam list-role-policies --role-name #Get inline policies of a role aws iam get-role-policy --role-name --policy-name #Get inline policy details ## attached policies aws iam list-attached-role-policies --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 --service-namespaces # Get list of policies that give access to the user to the service ## Get policy content aws iam get-policy --policy-arn aws iam list-policy-versions --policy-arn aws iam get-policy-version --policy-arn --version-id # Enumerate providers aws iam list-saml-providers aws iam get-saml-provider --saml-provider-arn aws iam list-open-id-connect-providers aws iam get-open-id-connect-provider --open-id-connect-provider-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**](https://github.com/carlospolop/bf-aws-permissions) बस एक बैश स्क्रिप्ट है जो निर्दिष्ट प्रोफ़ाइल का उपयोग करके सभी **`list*`, `describe*`, `get*`** क्रियाएँ चलाएगी जो इसे `aws` cli सहायता संदेशों का उपयोग करके मिल सकती हैं और **सफल कार्यान्वयन** लौटाएगी। ```bash # Bruteforce permissions bash bf-aws-permissions.sh -p default > /tmp/bf-permissions-verbose.txt ``` #### bf-aws-perms-simulate उपकरण [**bf-aws-perms-simulate**](https://github.com/carlospolop/bf-aws-perms-simulate) आपकी वर्तमान अनुमति (या अन्य प्रिंसिपलों की) को ढूंढ सकता है यदि आपके पास अनुमति **`iam:SimulatePrincipalPolicy`** है। ```bash # Ask for permissions python3 aws_permissions_checker.py --profile [--arn ] ``` #### Perms2ManagedPolicies यदि आपने **कुछ अनुमतियाँ पाई हैं जो आपके उपयोगकर्ता के पास हैं**, और आप सोचते हैं कि ये **प्रबंधित AWS भूमिका** द्वारा दी जा रही हैं (और किसी कस्टम द्वारा नहीं)। आप टूल [**aws-Perms2ManagedRoles**](https://github.com/carlospolop/aws-Perms2ManagedPolicies) का उपयोग कर सकते हैं यह जांचने के लिए कि **AWS प्रबंधित भूमिकाएँ कौन सी हैं जो उन अनुमतियों को प्रदान करती हैं जो आपने खोजी हैं कि आपके पास हैं**। ```bash # Run example with my profile python3 aws-Perms2ManagedPolicies.py --profile myadmin --permissions-file example-permissions.txt ``` > [!WARNING] > यह "जानना" संभव है कि आपके पास जो अनुमतियाँ हैं वे AWS प्रबंधित भूमिका द्वारा दी गई हैं यदि आप देखते हैं कि **आपके पास उन सेवाओं पर अनुमतियाँ हैं जो उपयोग नहीं की जाती हैं** उदाहरण के लिए। #### Cloudtrail2IAM [**CloudTrail2IAM**](https://github.com/carlospolop/Cloudtrail2IAM) एक Python उपकरण है जो **AWS CloudTrail लॉग का विश्लेषण करता है ताकि सभी या केवल एक विशिष्ट उपयोगकर्ता या भूमिका द्वारा किए गए कार्यों को निकाला और संक्षेपित किया जा सके**। यह उपकरण **निर्दिष्ट बकेट से हर क्लाउडट्रेल लॉग को पार्स करेगा**। ```bash 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**](https://github.com/andresriancho/enumerate-iam) का उपयोग करने के लिए, आपको पहले सभी API AWS एंडपॉइंट्स डाउनलोड करने की आवश्यकता है, जिनमें से स्क्रिप्ट **`generate_bruteforce_tests.py`** सभी **"list\_", "describe\_", और "get\_" एंडपॉइंट्स प्राप्त करेगी।** और अंत में, यह दिए गए क्रेडेंशियल्स के साथ **उन्हें एक्सेस करने की कोशिश करेगी** और **यह बताएगी कि क्या यह सफल रहा।** (मेरे अनुभव में **यह टूल किसी बिंदु पर लटक जाता है**, [**इस फिक्स को देखें**](https://github.com/andresriancho/enumerate-iam/pull/15/commits/77ad5b41216e3b5f1511d0c385da8cd5984c2d3c) इसे ठीक करने के लिए प्रयास करने के लिए)। > [!WARNING] > मेरे अनुभव में यह टूल पिछले वाले की तरह है लेकिन खराब काम कर रहा है और कम अनुमतियों की जांच कर रहा है। ```bash # 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**](https://github.com/carnal0wnage/weirdAAL/wiki) का भी उपयोग कर सकते हैं। यह टूल **कई सामान्य सेवाओं पर कई सामान्य ऑपरेशनों की जांच करेगा** (कुछ enumeration अनुमतियों और कुछ privesc अनुमतियों की भी जांच करेगा)। लेकिन यह केवल कोडेड जांचों की जांच करेगा (अधिक चीजों की जांच करने का एकमात्र तरीका अधिक परीक्षण कोड करना है)। ```bash # 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 = aws_secret_access_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 अनुमतियों को मजबूत करने के उपकरण {{#tabs }} {{#tab name="CloudSploit" }} ```bash # 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 ``` {{#endtab }} {{#tab name="SteamPipe" }} ```bash # https://github.com/turbot/steampipe-mod-aws-insights steampipe check all --export=json # https://github.com/turbot/steampipe-mod-aws-perimeter # In this case you cannot output to JSON, so heck it in the dashboard steampipe dashboard ``` {{#endtab }} {{#endtabs }} #### \ पिछले किसी भी उपकरण में सभी अनुमतियों की जांच करने की क्षमता नहीं है, इसलिए यदि आप एक बेहतर उपकरण जानते हैं तो PR भेजें! ### अनधिकृत पहुंच {{#ref}} ../aws-unauthenticated-enum-access/aws-iam-and-sts-unauthenticated-enum.md {{#endref}} ### विशेषाधिकार वृद्धि अगली पृष्ठ पर आप **IAM अनुमतियों का दुरुपयोग करके विशेषाधिकार बढ़ाने** का तरीका देख सकते हैं: {{#ref}} ../aws-privilege-escalation/aws-iam-privesc.md {{#endref}} ### IAM पोस्ट एक्सप्लोइटेशन {{#ref}} ../aws-post-exploitation/aws-iam-post-exploitation.md {{#endref}} ### IAM स्थिरता {{#ref}} ../aws-persistence/aws-iam-persistence.md {{#endref}} ## IAM पहचान केंद्र आप **IAM पहचान केंद्र का विवरण** यहाँ पा सकते हैं: {{#ref}} ../aws-basic-information/ {{#endref}} ### CLI के साथ SSO के माध्यम से कनेक्ट करें ```bash # 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 = sso_role_name = AdministratorAccess sso_region = us-east-1 ``` ### Enumeration Identity Center के मुख्य तत्व हैं: - उपयोगकर्ता और समूह - अनुमति सेट: नीतियाँ संलग्न हैं - AWS खाते फिर, संबंध बनाए जाते हैं ताकि उपयोगकर्ता/समूहों के पास AWS खाते पर अनुमति सेट हो। > [!NOTE] > ध्यान दें कि अनुमति सेट पर नीतियाँ संलग्न करने के 3 तरीके हैं। AWS प्रबंधित नीतियाँ संलग्न करना, ग्राहक प्रबंधित नीतियाँ (ये नीतियाँ उन सभी खातों में बनाई जानी चाहिए जिन पर अनुमति सेट प्रभाव डाल रहा है), और इनलाइन नीतियाँ (जो वहाँ परिभाषित हैं)। ```bash # 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 aws sso-admin describe-permission-set --instance-arn --permission-set-arn ## Get managed policies of a permission set aws sso-admin list-managed-policies-in-permission-set --instance-arn --permission-set-arn ## Get inline policies of a permission set aws sso-admin get-inline-policy-for-permission-set --instance-arn --permission-set-arn ## Get customer managed policies of a permission set aws sso-admin list-customer-managed-policy-references-in-permission-set --instance-arn --permission-set-arn ## Get boundaries of a permission set aws sso-admin get-permissions-boundary-for-permission-set --instance-arn --permission-set-arn ## List accounts a permission set is affecting aws sso-admin list-accounts-for-provisioned-permission-set --instance-arn --permission-set-arn ## List principals given a permission set in an account aws sso-admin list-account-assignments --instance-arn --permission-set-arn --account-id # Get permissions sets affecting an account aws sso-admin list-permission-sets-provisioned-to-account --instance-arn --account-id # List users & groups from the identity store aws identitystore list-users --identity-store-id aws identitystore list-groups --identity-store-id ## Get members of groups aws identitystore list-group-memberships --identity-store-id --group-id ## Get memberships or a user or a group aws identitystore list-group-memberships-for-member --identity-store-id --member-id ``` ### Local Enumeration यह संभव है कि `$HOME/.aws` फ़ोल्डर के अंदर config फ़ाइल बनाई जाए ताकि उन प्रोफाइलों को कॉन्फ़िगर किया जा सके जो SSO के माध्यम से सुलभ हैं, उदाहरण के लिए: ```ini [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:::role/ReadOnlyRole source_profile = Hacktricks-Admin ``` यह कॉन्फ़िगरेशन निम्नलिखित कमांड के साथ उपयोग किया जा सकता है: ```bash # 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 के)। कॉन्फ़िग उदाहरण: ```ini [profile crossaccountrole] role_arn = arn:aws:iam::234567890123:role/SomeRole source_profile = default mfa_serial = arn:aws:iam::123456789012:mfa/saanvi external_id = 123456 ``` ### अनधिकृत पहुँच {{#ref}} ../aws-unauthenticated-enum-access/aws-identity-center-and-sso-unauthenticated-enum.md {{#endref}} ### विशेषाधिकार वृद्धि {{#ref}} ../aws-privilege-escalation/aws-sso-and-identitystore-privesc.md {{#endref}} ### पोस्ट एक्सप्लोइटेशन {{#ref}} ../aws-post-exploitation/aws-sso-and-identitystore-post-exploitation.md {{#endref}} ### स्थिरता #### एक उपयोगकर्ता बनाएं और उसे अनुमतियाँ सौंपें ```bash # Create user identitystore:CreateUser aws identitystore create-user --identity-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 पहचान केंद्र तक पहुँच और नियंत्रण करने में सक्षम होंगे। हालांकि, यह डेलीगेट एडमिनिस्ट्रेटर के माध्यम से संभव है कि एक अलग खाते के उपयोगकर्ताओं को इसे प्रबंधित करने की अनुमति दी जाए। उनके पास बिल्कुल वही अनुमति नहीं होगी, लेकिन वे [**प्रबंधन गतिविधियाँ**](https://docs.aws.amazon.com/singlesignon/latest/userguide/delegated-admin.html) करने में सक्षम होंगे। {{#include ../../../banners/hacktricks-training.md}}