Files
hacktricks-cloud/src/pentesting-cloud/azure-security/README.md

6.0 KiB
Raw Blame History

Azure Pentesting

{{#include ../../banners/hacktricks-training.md}}

基本信息

{{#ref}} az-basic-information/ {{#endref}}

Azure 渗透测试/红队方法论

为了审计 AZURE 环境,了解以下内容非常重要:使用了哪些 服务,暴露了什么,谁有 访问权限,以及内部 Azure 服务和 外部服务 是如何连接的。

从红队的角度来看,攻陷 Azure 环境的第一步是设法获取一些 Azure AD 的 凭证。以下是一些获取凭证的思路:

  • GitHub或类似平台中的 泄露 - OSINT
  • 社交 工程
  • 密码 重用(密码泄露)
  • Azure 托管应用中的漏洞
  • 服务器端请求伪造 访问元数据端点
  • 本地文件读取
  • /home/USERNAME/.azure
  • C:\Users\USERNAME\.azure
  • accessTokens.json 文件在 az cli 2.30 之前 - Jan2022 - 存储 明文 访问令牌
  • azureProfile.json 文件包含有关登录用户的 信息
  • az logout 移除令牌。
  • 较旧版本的 Az PowerShellTokenCache.dat 中以 明文 存储 访问令牌。它还在 AzureRmContext.json 中以 明文 存储 ServicePrincipalSecret。可以使用 cmdlet Save-AzContext存储 令牌
    使用 Disconnect-AzAccount 来移除它们。
  • 第三方 被攻破
  • 内部 员工
  • 常见钓鱼(凭证或 Oauth 应用)
  • 设备代码认证钓鱼
  • Azure 密码喷洒

即使您 没有攻陷任何用户 在您攻击的 Azure 租户中,您仍然可以 收集一些信息

{{#ref}} az-unauthenticated-enum-and-initial-entry/ {{#endref}}

Note

在您成功获取凭证后,您需要知道 这些凭证属于谁,以及 他们可以访问什么,因此您需要进行一些基本的枚举:

基本枚举

Note

请记住,枚举中 最嘈杂 的部分是 登录,而不是枚举本身。

SSRF

如果您在 Azure 内部的机器上发现了 SSRF请查看此页面以获取技巧

{{#ref}} https://book.hacktricks.wiki/en/generic-methodologies-and-resources/phishing-methodology/index.html {{#endref}}

绕过登录条件

在您拥有一些有效凭证但无法登录的情况下,以下是一些可能存在的常见保护措施:

  • IP 白名单 -- 您需要攻陷一个有效的 IP
  • 地理限制 -- 找到用户居住的地方或公司的办公室位置,并获取来自同一城市(或至少同一国家)的 IP
  • 浏览器 -- 可能只允许某些操作系统Windows、Linux、Mac、Android、iOS中的浏览器。找出受害者/公司使用的操作系统。
  • 您还可以尝试 攻陷服务主体凭证,因为它们通常限制较少,登录审核也较少

绕过后,您可能能够返回到初始设置,并且仍然可以访问。

子域名接管

Whoami

Caution

学习 如何安装 az cli、AzureAD 和 Az PowerShell 在 Az - Entra ID 部分。

您需要了解的第一件事是 您是谁(您处于哪个环境中):

{{#tabs }} {{#tab name="az cli" }}

az account list
az account tenant list # Current tenant info
az account subscription list # Current subscription info
az ad signed-in-user show # Current signed-in user
az ad signed-in-user list-owned-objects # Get owned objects by current user
az account management-group list #Not allowed by default

{{#endtab }}

{{#tab name="AzureAD" }}

#Get the current session state
Get-AzureADCurrentSessionInfo
#Get details of the current tenant
Get-AzureADTenantDetail

{{#endtab }}

{{#tab name="Az PowerShell" }}

# Get the information about the current context (Account, Tenant, Subscription etc.)
Get-AzContext
# List all available contexts
Get-AzContext -ListAvailable
# Enumerate subscriptions accessible by the current user
Get-AzSubscription
#Get Resource group
Get-AzResourceGroup
# Enumerate all resources visible to the current user
Get-AzResource
# Enumerate all Azure RBAC role assignments
Get-AzRoleAssignment # For all users
Get-AzRoleAssignment -SignInName test@corp.onmicrosoft.com # For current user

{{#endtab }} {{#endtabs }}

Caution

识别 Azure 的最重要命令之一是 Get-AzResource,因为它可以让你 了解当前用户可见的资源

你可以在 网页控制台 中获取相同的信息,访问 https://portal.azure.com/#view/HubsExtension/BrowseAll 或搜索 "所有资源"

Entra ID 枚举

默认情况下,任何用户应该具有 足够的权限来枚举 用户、组、角色、服务主体等信息...(查看 默认 AzureAD 权限)。
你可以在这里找到指南:

{{#ref}} az-services/az-azuread.md {{#endref}}

Note

现在你 已经有了一些关于你凭据的信息(如果你是红队,希望你 没有被发现)。是时候找出环境中正在使用哪些服务。
在接下来的部分中,你可以查看一些 枚举常见服务的方法

应用服务 SCM

Kudu 控制台用于登录到应用服务 '容器'。

Webshell

使用 portal.azure.com 并选择 shell或使用 shell.azure.com进行 bash 或 powershell。此 shell 的 '磁盘' 作为图像文件存储在存储帐户中。

Azure DevOps

Azure DevOps 与 Azure 是分开的。它具有代码库、管道yaml 或发布)、看板、维基等。变量组用于存储变量值和秘密。

{{#include ../../banners/hacktricks-training.md}}