# AWS - IAM, Identiteitsentrum & SSO Enum {{#include ../../../banners/hacktricks-training.md}} ## IAM Jy kan 'n **beskrywing van IAM** vind in: {{#ref}} ../aws-basic-information/ {{#endref}} ### Enumerasie Hoof toestemmings benodig: - `iam:ListPolicies`, `iam:GetPolicy` en `iam:GetPolicyVersion` - `iam:ListRoles` - `iam:ListUsers` - `iam:ListGroups` - `iam:ListGroupsForUser` - `iam:ListAttachedUserPolicies` - `iam:ListAttachedRolePolicies` - `iam:ListAttachedGroupPolicies` - `iam:ListUserPolicies` en `iam:GetUserPolicy` - `iam:ListGroupPolicies` en `iam:GetGroupPolicy` - `iam:ListRolePolicies` en `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 ``` ### Toestemmings Brute Force As jy belangstel in jou eie toestemmings, maar jy het nie toegang om IAM te ondervra nie, kan jy altyd brute-force hulle. #### bf-aws-permissions Die hulpmiddel [**bf-aws-permissions**](https://github.com/carlospolop/bf-aws-permissions) is net 'n bash-skrip wat sal loop met die aangeduide profiel al die **`list*`, `describe*`, `get*`** aksies wat dit kan vind met behulp van `aws` cli hulpboodskappe en **teruggee die suksesvolle uitvoerings**. ```bash # Bruteforce permissions bash bf-aws-permissions.sh -p default > /tmp/bf-permissions-verbose.txt ``` #### bf-aws-perms-simulate Die hulpmiddel [**bf-aws-perms-simulate**](https://github.com/carlospolop/bf-aws-perms-simulate) kan jou huidige toestemming (of dié van ander principals) vind as jy die toestemming **`iam:SimulatePrincipalPolicy`** het. ```bash # Ask for permissions python3 aws_permissions_checker.py --profile [--arn ] ``` #### Perms2ManagedPolicies As jy **sekere toestemmings wat jou gebruiker het** gevind het, en jy dink dat dit deur 'n **bestuurde AWS-rol** (en nie deur 'n pasgemaakte een nie) toegeken word. Jy kan die hulpmiddel [**aws-Perms2ManagedRoles**](https://github.com/carlospolop/aws-Perms2ManagedPolicies) gebruik om al die **AWS bestuurde rolle wat die toestemmings wat jy ontdek het dat jy het, toeken** te kontroleer. ```bash # Run example with my profile python3 aws-Perms2ManagedPolicies.py --profile myadmin --permissions-file example-permissions.txt ``` > [!WARNING] > Dit is moontlik om te "weet" of die toestemmings wat jy het, toegeken is deur 'n AWS bestuurde rol as jy sien dat **jy toestemmings oor dienste het wat nie gebruik word** nie, byvoorbeeld. #### Cloudtrail2IAM [**CloudTrail2IAM**](https://github.com/carlospolop/Cloudtrail2IAM) is 'n Python-gereedskap wat **AWS CloudTrail logs analiseer om aksies** wat deur almal of net 'n spesifieke gebruiker of rol gedoen is, te onttrek en saam te vat. Die gereedskap sal **elke cloudtrail log van die aangeduide emmer parse**. ```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] > As jy .tfstate (Terraform toestand lêers) of CloudFormation lêers vind (hierdie is gewoonlik yaml lêers wat binne 'n emmer met die voorvoegsel cf-templates geleë is), kan jy dit ook lees om aws konfigurasie te vind en te sien watter toestemmings aan wie toegeken is. #### enumerate-iam Om die hulpmiddel [**https://github.com/andresriancho/enumerate-iam**](https://github.com/andresriancho/enumerate-iam) te gebruik, moet jy eers al die API AWS eindpunte aflaai, van daardie sal die skrif **`generate_bruteforce_tests.py`** al die **"list\_", "describe\_", en "get\_" eindpunte kry.** En uiteindelik sal dit probeer om **toegang tot hulle** te verkry met die gegewe akrediteer en **aangee of dit gewerk het**. (Volgens my ervaring hang die **hulpmiddel op 'n sekere punt**, [**kyk na hierdie regstelling**](https://github.com/andresriancho/enumerate-iam/pull/15/commits/77ad5b41216e3b5f1511d0c385da8cd5984c2d3c) om te probeer om dit reg te stel). > [!WARNING] > Volgens my ervaring is hierdie hulpmiddel soos die vorige, maar werk erger en kontroleer minder toestemmings. ```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 Jy kan ook die hulpmiddel [**weirdAAL**](https://github.com/carnal0wnage/weirdAAL/wiki) gebruik. Hierdie hulpmiddel sal **verskeie algemene operasies op verskeie algemene dienste nagaan** (sal 'n paar enumerasie-toestemmings en ook 'n paar privesc-toestemmings nagaan). Maar dit sal net die gekodeerde toetse nagaan (die enigste manier om meer goed na te gaan is om meer toetse te kodeer). ```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'] ``` #### Versterking van Gereedskap om BF-toestemmings {{#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 }} #### \ Geen van die vorige gereedskap is in staat om naby al die toestemmings te kontroleer nie, so as jy 'n beter gereedskap ken, stuur 'n PR! ### Ongeauthentiseerde Toegang {{#ref}} ../aws-unauthenticated-enum-access/aws-iam-and-sts-unauthenticated-enum.md {{#endref}} ### Privilege Escalation Op die volgende bladsy kan jy kyk hoe om **IAM-toestemmings te misbruik om voorregte te verhoog**: {{#ref}} ../aws-privilege-escalation/aws-iam-privesc.md {{#endref}} ### IAM Post Exploitation {{#ref}} ../aws-post-exploitation/aws-iam-post-exploitation.md {{#endref}} ### IAM Persistence {{#ref}} ../aws-persistence/aws-iam-persistence.md {{#endref}} ## IAM Identiteitsentrum Jy kan 'n **beskrywing van IAM Identiteitsentrum** vind in: {{#ref}} ../aws-basic-information/ {{#endref}} ### Verbind via SSO met CLI ```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 ``` ### Enumerasie Die hoofelemente van die Identiteitsentrum is: - Gebruikers en groepe - Toestemmingsstelle: Het beleide aangeheg - AWS-rekeninge Dan word verhoudings geskep sodat gebruikers/groepe Toestemmingsstelle oor AWS-rekening het. > [!NOTE] > Let daarop dat daar 3 maniere is om beleide aan 'n Toestemmingsstel te heg. Om AWS-beheerde beleide, Kliënt-beheerde beleide (hierdie beleide moet in al die rekeninge geskep word wat die Toestemmingsstel beïnvloed), en inline beleide (gedefinieer daar) aan te heg. ```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 ``` ### Plaaslike Enumerasie Dit is moontlik om binne die gids `$HOME/.aws` die lêer config te skep om profiele te konfigureer wat via SSO toeganklik is, byvoorbeeld: ```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 ``` Hierdie konfigurasie kan gebruik word met die opdragte: ```bash # Login in ms-sso-profile aws sso login --profile my-sso-profile # Use dependent-profile aws s3 ls --profile dependent-profile ``` Wanneer 'n **profiel van SSO gebruik word** om toegang tot sekere inligting te verkry, word die geloofsbriewe **gekas** in 'n lêer binne die gids **`$HOME/.aws/sso/cache`**. Daarom kan hulle **gelees en daar gebruik word**. Boonop kan **meer geloofsbriewe** in die gids **`$HOME/.aws/cli/cache`** gestoor word. Hierdie kasgids word hoofsaaklik gebruik wanneer jy **met AWS CLI-profiele werk** wat IAM-gebruiker geloofsbriewe gebruik of **aanneem** rolle deur IAM (sonder SSO). Konfigurasie voorbeeld: ```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 ``` ### Ongeauthentiseerde Toegang {{#ref}} ../aws-unauthenticated-enum-access/aws-identity-center-and-sso-unauthenticated-enum.md {{#endref}} ### Privilege Escalation {{#ref}} ../aws-privilege-escalation/aws-sso-and-identitystore-privesc.md {{#endref}} ### Post Exploitation {{#ref}} ../aws-post-exploitation/aws-sso-and-identitystore-post-exploitation.md {{#endref}} ### Volharding #### Skep 'n gebruiker en ken toestemmings aan dit toe ```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 ``` - Skep 'n groep en ken dit toestemmings toe en stel 'n beheerde gebruiker daarop in - Gee ekstra toestemmings aan 'n beheerde gebruiker of groep - Standaard sal slegs gebruikers met toestemmings van die Bestuursrekening toegang hê en die IAM Identiteitsentrum kan beheer. Dit is egter moontlik om via 'n Gedelegeerde Administrateur gebruikers van 'n ander rekening toe te laat om dit te bestuur. Hulle sal nie presies dieselfde toestemmings hê nie, maar hulle sal in staat wees om [**bestuursaktiwiteite**](https://docs.aws.amazon.com/singlesignon/latest/userguide/delegated-admin.html) uit te voer. {{#include ../../../banners/hacktricks-training.md}}