From 3d65cc1dbf2a0feb5e5e5e3ce8382eb4a484a413 Mon Sep 17 00:00:00 2001 From: Translator Date: Tue, 16 Jun 2026 13:29:12 +0000 Subject: [PATCH] Translated ['', 'src/pentesting-cloud/azure-security/az-unauthenticated- --- .../README.md | 214 +++++++++++++++--- 1 file changed, 177 insertions(+), 37 deletions(-) diff --git a/src/pentesting-cloud/azure-security/az-unauthenticated-enum-and-initial-entry/README.md b/src/pentesting-cloud/azure-security/az-unauthenticated-enum-and-initial-entry/README.md index 7e1a906ee..775d6f49a 100644 --- a/src/pentesting-cloud/azure-security/az-unauthenticated-enum-and-initial-entry/README.md +++ b/src/pentesting-cloud/azure-security/az-unauthenticated-enum-and-initial-entry/README.md @@ -2,20 +2,21 @@ {{#include ../../../banners/hacktricks-training.md}} -## Azure 租户 +## Azure Tenant ### Tenant Enumeration -有一些 **public Azure APIs**,攻击者只要知道 **租户的域名** 就可以查询以收集更多信息。你可以直接查询这些 API,或使用 PowerShell 库 [**AADInternals**](https://github.com/Gerenios/AADInternals) (`Install-Module AADInternals`): +有一些**public Azure APIs**,只要知道攻击者的**tenant**域名,就可以查询并收集更多信息。\ +你可以直接查询 API,或者使用 PowerShell library [**AADInternals**](https://github.com/Gerenios/AADInternals)(`Install-Module AADInternals`): -- **登录信息,包括租户 ID** -- `Get-AADIntTenantID -Domain ` (main API `login.microsoftonline.com//.well-known/openid-configuration`) -- **租户中所有有效域名** -- `Get-AADIntTenantDomains -Domain ` (main API `autodiscover-s.outlook.com/autodiscover/autodiscover.svc`) -- **用户的登录信息**。如果 `NameSpaceType` 是 `Managed`,表示使用 EntraID -- `Get-AADIntLoginInformation -UserName ` (main API `login.microsoftonline.com/GetUserRealm.srf?login=`) +- **Login 信息,包括 tenant ID** +- `Get-AADIntTenantID -Domain `(main API `login.microsoftonline.com//.well-known/openid-configuration`) +- **tenant 中所有有效域名** +- `Get-AADIntTenantDomains -Domain `(main API `autodiscover-s.outlook.com/autodiscover/autodiscover.svc`) +- **用户的 Login 信息**。如果 `NameSpaceType` 是 `Managed`,这表示使用了 EntraID +- `Get-AADIntLoginInformation -UserName `(main API `login.microsoftonline.com/GetUserRealm.srf?login=`) -你可以使用 [**AADInternals**](https://github.com/Gerenios/AADInternals) 的 **仅一条命令** 来查询整个 Azure 租户的信息: +你可以只用 [**AADInternals**](https://github.com/Gerenios/AADInternals) 的**一个命令**查询 Azure tenant 的所有信息: ```bash # Doesn't work in macos because 'Resolve-DnsName' doesn't exist Invoke-AADIntReconAsOutsider -DomainName corp.onmicrosoft.com | Format-Table @@ -34,33 +35,61 @@ company.mail.onmicrosoft.com True True True Managed company.onmicrosoft.com True True True Managed int.company.com False False False Managed ``` -可以观察到有关租户名称、ID 和“brand”名称的详细信息。此外,还会显示 Desktop Single Sign-On (SSO),也就是 [**Seamless SSO**](https://docs.microsoft.com/en-us/azure/active-directory/hybrid/how-to-connect-sso) 的状态。启用后,该功能便于确定目标组织中是否存在(枚举)特定用户。 +可以观察到有关租户名称、ID 和 “brand” 名称的详细信息。另外,还会显示 Desktop Single Sign-On (SSO),也称为 [**Seamless SSO**](https://docs.microsoft.com/en-us/azure/active-directory/hybrid/how-to-connect-sso) 的状态。启用后,此功能有助于确定目标组织中是否存在特定用户(enumeration)。 -此外,输出还列出了与目标租户关联的所有已验证域名及其各自的身份类型。对于 federated domains,会显示所使用身份提供者的 Fully Qualified Domain Name (FQDN),通常为 ADFS 服务器。“MX” 列表明邮件是否路由到 Exchange Online,而 “SPF” 列则表示是否将 Exchange Online 列为邮件发送者。需要注意的是,当前的侦察功能不会解析 SPF 记录中的 “include” 语句,这可能导致假阴性。 +此外,输出还会展示与目标 tenant 关联的所有已验证域名及其各自的 identity type。对于 federated 域,还会披露所使用 identity provider 的 Fully Qualified Domain Name (FQDN),通常是 ADFS server。“MX” 列指定邮件是否路由到 Exchange Online,而 “SPF” 列表示 Exchange Online 是否被列为邮件发送方。需要注意的是,当前的 reconnaissance 功能不会解析 SPF records 中的 “include” 语句,这可能导致 false negatives。 ### User Enumeration > [!TIP] -> 请注意,即使租户为同一用户使用多个邮箱,**username is unique**。这意味着它只会在用户关联的域上生效,而不会在其他域上生效。 +> 注意,即使一个 tenant 为同一用户使用了多个 emails,**username 也是唯一的**。这意味着它只能与用户关联的那个 domain 一起使用,而不能与其他 domains 一起使用。 -可以**检查某个 username 是否存在**于租户内。这也包括**来宾用户**,其 username 的格式为: +可以 **check if a username exists** 在 tenant 内。这也包括 **guest users**,其 username 的格式为: ``` #EXT#@.onmicrosoft.com ``` -该邮箱为用户的邮箱地址,其中 “@” 被替换为下划线 “\_”。 +电子邮件是用户的电子邮件地址,其中 “@” 被替换为下划线 “\_”。 使用 [**AADInternals**](https://github.com/Gerenios/AADInternals),你可以轻松检查该用户是否存在: ```bash # Check does the user exist Invoke-AADIntUserEnumerationAsOutsider -UserName "user@company.com" ``` -请提供文件 src/pentesting-cloud/azure-security/az-unauthenticated-enum-and-initial-entry/README.md 的内容(原始 Markdown),我会按要求翻译成中文并保留所有 Markdown/HTML/路径/标签。 +## 未经身份验证的枚举与初始入口 + +Azure 提供了多种机制来控制对资源的访问,但某些配置错误或暴露的服务可能允许在**未认证**的情况下进行枚举,并为后续的初始入口创造机会。 + +常见的攻击面包括: + +- **公开可访问的服务**:Blob storage、Static Web Apps、App Service、Functions +- **错误配置的访问控制**:匿名访问、过宽的 RBAC 角色、暴露的 SAS token +- **可枚举的元数据或 API**:租户信息、订阅信息、目录对象、存储容器 +- **泄露的凭据或令牌**:在代码仓库、CI/CD、日志或公开文档中发现 + +在 Azure 中,未经身份验证的枚举通常会先从以下方向入手: + +1. **识别公开资产** + - 公开域名 + - 可访问的 storage endpoints + - 暴露的 App Service / Function endpoints + +2. **检查匿名访问** + - Storage container/blob 是否允许匿名读取 + - Static website 是否暴露敏感文件 + - API 是否返回过多信息 + +3. **利用暴露的信息继续扩展** + - 从元数据、错误消息、响应头中收集线索 + - 枚举租户、用户、组、应用注册 + - 查找可用于后续访问的凭据、token、连接字符串 + +这些技术通常用于在不依赖认证的情况下建立最初的 foothold,并为后续的权限提升、横向移动或持久化提供起点。 ``` UserName Exists -------- ------ user@company.com True ``` -你也可以使用一个文本文件,每行包含一个电子邮件地址: +你还可以使用一个每行包含一个 email 地址的文本文件: ``` user@company.com user2@company.com @@ -74,7 +103,7 @@ external.user_outlook.com#EXT#@company.onmicrosoft.com # Invoke user enumeration Get-Content .\users.txt | Invoke-AADIntUserEnumerationAsOutsider -Method Normal ``` -当前有 **4 种不同的枚举方法** 可供选择。你可以在 `Get-Help Invoke-AADIntUserEnumerationAsOutsider` 中找到信息: +Currenlty there are **4 different enumeration methods** to choose from. You can find information in `Get-Help Invoke-AADIntUserEnumerationAsOutsider`: It supports following enumeration methods: Normal, Login, Autologon, and RST2. @@ -85,11 +114,11 @@ It supports following enumeration methods: Normal, Login, Autologon, and RST2. - The **Autologon** method doesn't seem to work with all tenants anymore. Probably requires that DesktopSSO or directory sync is enabled. -发现有效用户名后,你可以获取**关于用户的信息**: +After discovering the valid usernames you can get **info about a user** with: ```bash Get-AADIntLoginInformation -UserName root@corp.onmicrosoft.com ``` -该脚本 [**o365spray**](https://github.com/0xZDH/o365spray) 还可以让你判断 **某个邮箱是否有效**. +脚本 [**o365spray**](https://github.com/0xZDH/o365spray) 还允许你发现 **某个 email 是否有效**。 ```bash git clone https://github.com/0xZDH/o365spray cd o365spray @@ -100,15 +129,15 @@ python3 ./o365spray.py --enum -d carloshacktricks.onmicrosoft.com -u carlos # Check a list of emails python3 ./o365spray.py --enum -d carloshacktricks.onmicrosoft.com -U /tmp/users.txt ``` -**通过 Microsoft Teams 进行用户枚举** +**通过 Microsoft Teams 进行 User Enumeration** 另一个很好的信息来源是 Microsoft Teams。 -Microsoft Teams 的 API 允许搜索用户。特别是 "user search" 端点 **externalsearchv3** 和 **searchUsers** 可用于请求有关已加入 Teams 的用户账户的一般信息。 +Microsoft Teams 的 API 允许搜索 users。特别是 “user search” 端点 **externalsearchv3** 和 **searchUsers** 可用于请求已加入 Teams 的 user accounts 的一般信息。 -根据 API 的响应,可以区分不存在的用户和拥有有效 Teams 订阅的现有用户。 +根据 API 响应,可以区分不存在的 users 和存在且拥有有效 Teams subscription 的 users。 -脚本 [**TeamsEnum**](https://github.com/lucidra-security/TeamsEnum) 可用于针对 Teams API 验证一组给定的用户名,但你需要一个有 Teams 访问权限的用户来使用它。 +脚本 [**TeamsEnum**](https://github.com/lucidra-security/TeamsEnum) 可用于针对 Teams API 验证一组给定的 usernames,但你需要一个具有 Teams 访问权限的 user 才能使用它。 ```bash # Install git clone https://github.com/lucidra-security/TeamsEnum @@ -118,13 +147,51 @@ python3 -m pip install -r requirements.txt # Login and ask for password python3 ./TeamsEnum.py -a password -u -f inputlist.txt -o teamsenum-output.json ``` -请提供 src/pentesting-cloud/azure-security/az-unauthenticated-enum-and-initial-entry/README.md 的内容,我将按要求翻译成中文。 +## Azure unauthenticated enumeration and initial entry + +Azure is a cloud computing platform from Microsoft that offers a wide range of services, including computing, storage, databases, networking, and more. In this section, we will discuss how to perform unauthenticated enumeration and initial entry in Azure environments. + +### Azure Services and Resources + +Azure provides a variety of services and resources that can be accessed without authentication under certain circumstances. These may include: + +- Publicly exposed storage accounts +- Misconfigured Azure Active Directory applications +- Insecure APIs and endpoints +- Overly permissive access controls + +### Enumeration Techniques + +Common enumeration techniques in Azure include: + +- Discovering publicly accessible resources +- Identifying leaked credentials or secrets +- Enumerating Azure Active Directory tenants and users +- Searching for exposed management interfaces + +### Initial Entry + +Initial entry in Azure environments often involves exploiting misconfigurations, weak access controls, or exposed credentials to gain a foothold. Common vectors include: + +- Abusing publicly exposed services +- Using leaked or weak credentials +- Leveraging misconfigured role assignments +- Exploiting insecure application integrations + +### Defensive Considerations + +To reduce the risk of unauthenticated enumeration and initial entry, organizations should: + +- Restrict public exposure of sensitive resources +- Enforce strong authentication and authorization +- Regularly audit Azure configurations +- Monitor for suspicious access patterns ``` [-] user1@domain - Target user not found. Either the user does not exist, is not Teams-enrolled or is configured to not appear in search results (personal accounts only) [+] user2@domain - User2 | Company (Away, Mobile) [+] user3@domain - User3 | Company (Available, Desktop) ``` -此外可以枚举现有用户的可用性信息,例如: +此外,还可以枚举现有用户的可用性信息,例如: - Available - Away @@ -132,11 +199,44 @@ python3 ./TeamsEnum.py -a password -u -f inputlist.txt -o teamsenum-o - Busy - Offline -如果配置了**外出自动回复消息**,也可以使用 TeamsEnum 检索该消息。如果指定了输出文件,外出自动回复消息会自动保存到 JSON 文件中: +如果配置了 **out-of-office message**,也可以使用 TeamsEnum 检索该消息。如果指定了输出文件,out-of-office messages 会自动存储在 JSON 文件中: ``` jq . teamsenum-output.json ``` -请提供 src/pentesting-cloud/azure-security/az-unauthenticated-enum-and-initial-entry/README.md 的内容,我将按要求翻译为中文。 +## Azure Security - Unauthenticated Enum and Initial Entry + +Azure services can be enumerated unauthenticated by design if they are intended to be public, such as: + +- **Storage Accounts** (e.g. blobs, file shares, queues, tables) +- **Web Apps** (public endpoints) +- **Function Apps** (some endpoints) +- **Container Registries** (publicly accessible) +- **Virtual Machine metadata endpoints** in some cases +- **Public DNS records** and other exposed resources + +Common unauthenticated enumeration techniques include: + +- Checking for **public storage containers** and listing blobs +- Accessing **metadata endpoints** from within a VM or SSRF +- Enumerating **subdomains** and **DNS records** +- Probing **public APIs** and endpoints for information disclosure +- Searching for **misconfigured** resources that expose data + +Initial entry in Azure often happens through: + +- **Leaked credentials** or tokens +- **Weak or reused passwords** +- **Misconfigured** public services +- **Over-permissive** IAM/RBAC assignments +- **Exposed management interfaces** or secrets in code repositories + +When assessing Azure environments, focus on: + +- Identifying **publicly exposed** assets +- Looking for **anonymous access** paths +- Reviewing **access controls** and **role assignments** +- Checking for **secrets** in blobs, files, configs, and pipelines +- Enumerating **subscriptions**, **resource groups**, and **services** available to the current identity ```json { "email": "user2@domain", @@ -191,9 +291,10 @@ jq . teamsenum-output.json az-password-spraying.md {{#endref}} -## Azure Services using domains +## 使用 domains 的 Azure Services -还可以尝试在常见的 Azure 子域中查找 **Azure services exposed**,例如这篇 [post:](https://www.netspi.com/blog/technical-blog/cloud-penetration-testing/enumerating-azure-services/) 中记录的那些: +也可以尝试在常见的 azure 子域名中查找**暴露的 Azure services**,例如这篇 [post: +](https://www.netspi.com/blog/technical-blog/cloud-penetration-testing/enumerating-azure-services/) 中记录的那些: - App Services: `azurewebsites.net` - App Services – Management: `scm.azurewebsites.net` @@ -214,30 +315,69 @@ az-password-spraying.md - Search Appliance: `search.windows.net` - API Services: `azure-api.net` -你可以使用来自 [**MicroBust**](https://github.com/NetSPI/MicroBurst) 的一个方法来实现该目的。该函数会在多个 **azure domains:** 中搜索基础域名(以及一些变体)。 +你可以使用来自 [**MicroBust**](https://github.com/NetSPI/MicroBurst) 的一种方法来实现这个目标。这个 function 会在多个 **azure domains:** 中搜索 base domain name(以及一些变体): ```bash Import-Module .\MicroBurst\MicroBurst.psm1 -Verbose Invoke-EnumerateAzureSubDomains -Base corp -Verbose ``` ## Phishing -- [**Common Phishing**](https://book.hacktricks.wiki/en/generic-methodologies-and-resources/phishing-methodology/index.html) 用于获取 credentials 或通过 [OAuth Apps](az-oauth-apps-phishing.md) +- [**Common Phishing**](https://book.hacktricks.wiki/en/generic-methodologies-and-resources/phishing-methodology/index.html) for credentials or via [OAuth Apps](az-oauth-apps-phishing.md) - [**Device Code Authentication** Phishing](az-device-code-authentication-phishing.md) +### Exchange Online direct-to-tenant SMTP spoofing + +如果目标使用 **Exchange Online / EOP**,但其公网 **MX** 指向一个 **third-party mail gateway**(Mimecast、Proofpoint、Mailgun、on-prem filtering 等),测试 Exchange Online 是否仍然接受直接发送到租户主机 `*.mail.protection.outlook.com` 的邮件。在这种情况下,攻击者可以**跳过外部网关**,直接向 EOP 提交 phishing 邮件。 + +这对 **initial access / phishing** 很有用,因为即使伪造的发件人未通过 **SPF**、**DKIM** 和 **DMARC**,邮件仍然可能送达。对于内部发件人,Outlook 也可能将伪造的发件人解析为真实员工,从而增加信任度。 + +**Recon / triage:** +```bash +# If the MX already points to Microsoft, this specific path is usually not the issue +dig +short MX target.com + +# Typical vulnerable pattern: the MX points to a third-party filter +# 10 mxb.eu.mailgun.org. +``` +直接的 EOP host 通常是 tenant-specific 的 `mail.protection.outlook.com` 名称(例如 `target-com.mail.protection.outlook.com`)。你通常可以从 public tenant/domain enumeration 和与 Exchange 相关的 autodiscover responses 中恢复 tenant 命名模式。 + +**Minimal PoC:** +```powershell +Send-MailMessage -SmtpServer target-com.mail.protection.outlook.com -To victim@target.com -From ceo@target.com -Subject "Urgent" -Body "Review the attached payment change" -BodyAsHTML +``` +**Validation signals:** +- Mail is sent to `*.mail.protection.outlook.com` instead of the public MX host. +- 消息被投递,尽管 headers 显示 `spf=fail`、`dkim=none`、`dmarc=fail` 或 `compauth=none` 等失败。 +- 一个 secure Partner connector 通常会在 `RCPT TO` 阶段以 `5.7.51 TenantInboundAttribution; Rejecting.` 拒绝。 + +**Technical notes / defensive hunting:** +- **Enhanced Filtering for Connectors** 有助于 Exchange 正确归因原始 sender,但它本身**不是**阻止 direct-to-tenant delivery 的边界。 +- Microsoft 在外部 MX 位于 Exchange Online 前面时,文档中建议两种实用控制: +- 创建一个 **Partner inbound connector**,设置 `SenderDomains *` 并使用 `RestrictDomainsToCertificate` 或 `RestrictDomainsToIPAddresses`,这样只有被批准的 gateway 才能向该 tenant 投递。 +- 创建一个 **priority 0 transport rule**,将入站邮件隔离,除非 sender IP 属于已批准的 gateway ranges **或** `X-MS-Exchange-Organization-AuthAs` 包含 `Internal`。 +- 检查邮件:**Received** 显示 `*.mail.protection.outlook.com` 作为第一个 Microsoft hop,但 sender-authentication headers 仍然显示 **SPF/DKIM/DMARC failures**。 +- 如果 target 仍然允许 **Direct Send**,禁用它主要只能减少 **internal** sender spoofing;它不能替代用于任意 **external** spoofing 的 connector / transport-rule 缓解措施。 + ## Filesystem Credentials -The **`az cli`** stores a lot of interesting information inside **`/.Azure`**: -- **`azureProfile.json`** 包含过去登录用户的信息 -- **`clouds.config`** 包含有关订阅的信息 -- **`service_principal_entries.json`** 包含应用的 **credentials**(tenant id,clients 和 secret) +**`az cli`** 会在 **`/.Azure`** 中存储很多有趣的信息: +- **`azureProfile.json`** 包含过去已登录用户的信息 +- **`clouds.config`** 包含 subscriptions 信息 +- **`service_principal_entries.json`** 包含 applications **credentials**(tenant id、clients 和 secret) - **`msal_token_cache.json`** 包含 **access tokens 和 refresh tokens** -注意,在 macOS 和 linux 上,这些文件以**未受保护**的明文方式存储。 +注意,在 macOS 和 linux 中,这些文件是 **unprotected** 的,且以明文存储。 -## 参考资料 + + +## References - [https://aadinternals.com/post/just-looking/](https://aadinternals.com/post/just-looking/) - [https://www.securesystems.de/blog/a-fresh-look-at-user-enumeration-in-microsoft-teams/](https://www.securesystems.de/blog/a-fresh-look-at-user-enumeration-in-microsoft-teams/) - [https://www.netspi.com/blog/technical-blog/cloud-penetration-testing/enumerating-azure-services/](https://www.netspi.com/blog/technical-blog/cloud-penetration-testing/enumerating-azure-services/) +- [https://labs.infoguard.ch/posts/ghost-sender/](https://labs.infoguard.ch/posts/ghost-sender/) +- [https://learn.microsoft.com/en-us/exchange/mail-flow-best-practices/manage-mail-flow-using-third-party-cloud](https://learn.microsoft.com/en-us/exchange/mail-flow-best-practices/manage-mail-flow-using-third-party-cloud) +- [https://learn.microsoft.com/en-us/defender-office-365/anti-phishing-policies-about](https://learn.microsoft.com/en-us/defender-office-365/anti-phishing-policies-about) +- [https://techcommunity.microsoft.com/blog/exchange/direct-send-vs-sending-directly-to-an-exchange-online-tenant/4439865](https://techcommunity.microsoft.com/blog/exchange/direct-send-vs-sending-directly-to-an-exchange-online-tenant/4439865) {{#include ../../../banners/hacktricks-training.md}}