Az - Unauthenticated Enum & Initial Entry
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
- 查看 subscription plans!
- 加入 💬 Discord group 或者 telegram group 或 关注 我们的 Twitter 🐦 @hacktricks_live.
- 通过向 HackTricks 和 HackTricks Cloud github 仓库 提交 PRs 来分享 hacking tricks。
Azure 租户
Tenant Enumeration
有一些 public Azure APIs,攻击者只要知道 租户的域名 就可以查询以收集更多信息。你可以直接查询这些 API,或使用 PowerShell 库 AADInternals (Install-Module AADInternals):
- 登录信息,包括租户 ID
Get-AADIntTenantID -Domain <domain>(main APIlogin.microsoftonline.com/<domain>/.well-known/openid-configuration)- 租户中所有有效域名
Get-AADIntTenantDomains -Domain <domain>(main APIautodiscover-s.outlook.com/autodiscover/autodiscover.svc)- 用户的登录信息。如果
NameSpaceType是Managed,表示使用 EntraID Get-AADIntLoginInformation -UserName <UserName>(main APIlogin.microsoftonline.com/GetUserRealm.srf?login=<UserName>)
你可以使用 AADInternals 的 仅一条命令 来查询整个 Azure 租户的信息:
# Doesn't work in macos because 'Resolve-DnsName' doesn't exist
Invoke-AADIntReconAsOutsider -DomainName corp.onmicrosoft.com | Format-Table
## Output Example of the Azure tenant info:
Tenant brand: Company Ltd
Tenant name: company
Tenant id: 1937e3ab-38de-a735-a830-3075ea7e5b39
DesktopSSO enabled: True
Name DNS MX SPF Type STS
---- --- -- --- ---- ---
company.com True True True Federated sts.company.com
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 的状态。启用后,该功能便于确定目标组织中是否存在(枚举)特定用户。
此外,输出还列出了与目标租户关联的所有已验证域名及其各自的身份类型。对于 federated domains,会显示所使用身份提供者的 Fully Qualified Domain Name (FQDN),通常为 ADFS 服务器。“MX” 列表明邮件是否路由到 Exchange Online,而 “SPF” 列则表示是否将 Exchange Online 列为邮件发送者。需要注意的是,当前的侦察功能不会解析 SPF 记录中的 “include” 语句,这可能导致假阴性。
User Enumeration
Tip
请注意,即使租户为同一用户使用多个邮箱,username is unique。这意味着它只会在用户关联的域上生效,而不会在其他域上生效。
可以检查某个 username 是否存在于租户内。这也包括来宾用户,其 username 的格式为:
<email>#EXT#@<tenant name>.onmicrosoft.com
该邮箱为用户的邮箱地址,其中 “@” 被替换为下划线 “_”。
使用 AADInternals,你可以轻松检查该用户是否存在:
# 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/路径/标签。
UserName Exists
-------- ------
user@company.com True
你也可以使用一个文本文件,每行包含一个电子邮件地址:
user@company.com
user2@company.com
admin@company.com
admin2@company.com
external.user_gmail.com#EXT#@company.onmicrosoft.com
external.user_outlook.com#EXT#@company.onmicrosoft.com
# Invoke user enumeration
Get-Content .\users.txt | Invoke-AADIntUserEnumerationAsOutsider -Method Normal
当前有 4 种不同的枚举方法 可供选择。你可以在 Get-Help Invoke-AADIntUserEnumerationAsOutsider 中找到信息:
It supports following enumeration methods: Normal, Login, Autologon, and RST2.
-
The Normal method seems currently work with all tenants. Previously it required Desktop SSO (aka Seamless SSO) to be enabled for at least one domain.
-
The Login method works with any tenant, but enumeration queries will be logged to Azure AD sign-in log as failed login events!
-
The Autologon method doesn’t seem to work with all tenants anymore. Probably requires that DesktopSSO or directory sync is enabled.
发现有效用户名后,你可以获取关于用户的信息:
Get-AADIntLoginInformation -UserName root@corp.onmicrosoft.com
该脚本 o365spray 还可以让你判断 某个邮箱是否有效.
git clone https://github.com/0xZDH/o365spray
cd o365spray
python3 -m pip install -r requirements.txt
# Check 1 email
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。
Microsoft Teams 的 API 允许搜索用户。特别是 “user search” 端点 externalsearchv3 和 searchUsers 可用于请求有关已加入 Teams 的用户账户的一般信息。
根据 API 的响应,可以区分不存在的用户和拥有有效 Teams 订阅的现有用户。
脚本 TeamsEnum 可用于针对 Teams API 验证一组给定的用户名,但你需要一个有 Teams 访问权限的用户来使用它。
# Install
git clone https://github.com/lucidra-security/TeamsEnum
cd TeamsEnum
python3 -m pip install -r requirements.txt
# Login and ask for password
python3 ./TeamsEnum.py -a password -u <username> -f inputlist.txt -o teamsenum-output.json
请提供 src/pentesting-cloud/azure-security/az-unauthenticated-enum-and-initial-entry/README.md 的内容,我将按要求翻译成中文。
[-] 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
- DoNotDisturb
- Busy
- Offline
如果配置了外出自动回复消息,也可以使用 TeamsEnum 检索该消息。如果指定了输出文件,外出自动回复消息会自动保存到 JSON 文件中:
jq . teamsenum-output.json
请提供 src/pentesting-cloud/azure-security/az-unauthenticated-enum-and-initial-entry/README.md 的内容,我将按要求翻译为中文。
{
"email": "user2@domain",
"exists": true,
"info": [
{
"tenantId": "[REDACTED]",
"isShortProfile": false,
"accountEnabled": true,
"featureSettings": {
"coExistenceMode": "TeamsOnly"
},
"userPrincipalName": "user2@domain",
"givenName": "user2@domain",
"surname": "",
"email": "user2@domain",
"tenantName": "Company",
"displayName": "User2",
"type": "Federated",
"mri": "8:orgid:[REDACTED]",
"objectId": "[REDACTED]"
}
],
"presence": [
{
"mri": "8:orgid:[REDACTED]",
"presence": {
"sourceNetwork": "Federated",
"calendarData": {
"outOfOfficeNote": {
"message": "Dear sender. I am out of the office until March 23rd with limited access to my email. I will respond after my return.Kind regards, User2",
"publishTime": "2023-03-15T21:44:42.0649385Z",
"expiry": "2023-04-05T14:00:00Z"
},
"isOutOfOffice": true
},
"capabilities": ["Audio", "Video"],
"availability": "Away",
"activity": "Away",
"deviceType": "Mobile"
},
"etagMatch": false,
"etag": "[REDACTED]",
"status": 20000
}
]
}
Password Spraying / Brute-Force
Azure Services using domains
还可以尝试在常见的 Azure 子域中查找 Azure services exposed,例如这篇 post: 中记录的那些:
- App Services:
azurewebsites.net - App Services – Management:
scm.azurewebsites.net - App Services:
p.azurewebsites.net - App Services:
cloudapp.net - Storage Accounts-Files:
file.core.windows.net - Storage Accounts-Blobs:
blob.core.windows.net - Storage Accounts-Queues:
queue.core.windows.net - Storage Accounts-Tables:
table.core.windows.net - Databases-Redis:
redis.cache.windows.net - Databases-Cosmos DB:
documents.azure.com - Databases-MSSQL:
database.windows.net - Key Vaults:
vault.azure.net - Microsoft Hosted Domain:
onmicrosoft.com - Email:
mail.protection.outlook.com - SharePoint:
sharepoint.com - CDN:
azureedge.net - Search Appliance:
search.windows.net - API Services:
azure-api.net
你可以使用来自 MicroBust 的一个方法来实现该目的。该函数会在多个 azure domains: 中搜索基础域名(以及一些变体)。
Import-Module .\MicroBurst\MicroBurst.psm1 -Verbose
Invoke-EnumerateAzureSubDomains -Base corp -Verbose
Phishing
- Common Phishing 用于获取 credentials 或通过 OAuth Apps
- Device Code Authentication Phishing
Filesystem Credentials
The az cli stores a lot of interesting information inside <HOME>/.Azure:
azureProfile.json包含过去登录用户的信息clouds.config包含有关订阅的信息service_principal_entries.json包含应用的 credentials(tenant id,clients 和 secret)msal_token_cache.json包含 access tokens 和 refresh tokens
注意,在 macOS 和 linux 上,这些文件以未受保护的明文方式存储。
参考资料
- https://aadinternals.com/post/just-looking/
- 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/
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
- 查看 subscription plans!
- 加入 💬 Discord group 或者 telegram group 或 关注 我们的 Twitter 🐦 @hacktricks_live.
- 通过向 HackTricks 和 HackTricks Cloud github 仓库 提交 PRs 来分享 hacking tricks。
HackTricks Cloud

