AWS - IAM, Identity Center & SSO Enum

Support HackTricks

IAM

IAM에 대한 설명은 다음에서 찾을 수 있습니다:

AWS - Basic Information

Enumeration

필요한 주요 권한:

  • iam:ListPolicies, iam:GetPolicyiam:GetPolicyVersion

  • iam:ListRoles

  • iam:ListUsers

  • iam:ListGroups

  • iam:ListGroupsForUser

  • iam:ListAttachedUserPolicies

  • iam:ListAttachedRolePolicies

  • iam:ListAttachedGroupPolicies

  • iam:ListUserPoliciesiam:GetUserPolicy

  • iam:ListGroupPoliciesiam:GetGroupPolicy

  • iam:ListRolePoliciesiam: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 도움말 메시지를 사용하여 찾고 성공적인 실행 결과를 반환하는 bash 스크립트입니다.

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

bf-aws-perms-simulate

도구 bf-aws-perms-simulateiam: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모든 사용자 또는 특정 사용자 또는 역할에 의해 수행된 작업을 추출하고 요약하기 위해 AWS CloudTrail 로그를 분석하는 Python 도구입니다. 이 도구는 지정된 버킷의 모든 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 상태 파일) 또는 CloudFormation 파일(이 파일들은 일반적으로 cf-templates 접두사가 있는 버킷 내의 yaml 파일)에 대해 찾으면, 이를 읽어 aws 구성과 어떤 권한이 누구에게 할당되었는지 확인할 수 있습니다.

enumerate-iam

https://github.com/andresriancho/enumerate-iam 도구를 사용하려면 먼저 모든 API AWS 엔드포인트를 다운로드해야 하며, 그 중에서 스크립트 **generate_bruteforce_tests.py**가 모든 "list_", "describe_", 및 "get_" 엔드포인트를 가져옵니다. 마지막으로, 주어진 자격 증명으로 접근을 시도하고 작동했는지 여부를 표시합니다.

(내 경험상 이 도구는 어느 시점에서 멈추는 경향이 있습니다, 이 수정 사항을 확인하세요 이 문제를 해결하기 위해 시도해 보세요).

내 경험상 이 도구는 이전 도구와 비슷하지만 더 나쁘게 작동하고 권한을 덜 확인합니다.

# 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를 사용할 수 있습니다. 이 도구는 여러 일반 서비스에서 여러 일반 작업을 확인합니다 (일부 열거 권한과 일부 권한 상승 권한을 확인합니다). 그러나 코딩된 검사만 확인하며 (더 많은 것을 확인하는 유일한 방법은 더 많은 테스트를 코딩하는 것입니다).

# 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 권한을 남용하여 권한을 상승시키는 방법을 확인할 수 있습니다:

AWS - IAM Privesc

IAM 포스트 익스플로잇

AWS - IAM Post Exploitation

IAM 지속성

AWS - IAM Persistence

IAM 아이덴티티 센터

다음에서 IAM 아이덴티티 센터에 대한 설명을 찾을 수 있습니다:

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

Enumeration

Identity Center의 주요 요소는 다음과 같습니다:

  • 사용자 및 그룹

  • 권한 세트: 정책이 연결되어 있음

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

Local Enumeration

$HOME/.aws 폴더 안에 SSO를 통해 접근할 수 있는 프로필을 구성하기 위한 config 파일을 생성하는 것이 가능합니다. 예를 들어:

[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

When a profile from SSO is used to access some information, the credentials are cached in a file inside the folder $HOME/.aws/sso/cache. Therefore they can be read and used from there.

또한, 더 많은 자격 증명은 폴더 **$HOME/.aws/cli/cache**에 저장될 수 있습니다. 이 캐시 디렉토리는 주로 IAM 사용자 자격 증명을 사용하거나 IAM을 통해 역할을 가정할 때 AWS CLI 프로필로 작업할 때 사용됩니다. 구성 예:

[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 Identity Center에 접근하고 제어할 수 있습니다.

그러나 Delegate Administrator를 통해 다른 계정의 사용자가 이를 관리할 수 있도록 허용할 수 있습니다. 그들은 정확히 동일한 권한을 가지지는 않지만, 관리 활동을 수행할 수 있습니다.

Support HackTricks

Last updated