LikeTonyHawk/Azure-Security-Monitoring-Lab
GitHub: LikeTonyHawk/Azure-Security-Monitoring-Lab
在 Azure 中搭建混合身份与安全监控实验环境,通过引入真实配置错误并用 Sentinel 和 KQL 进行检测,实践云安全检测工程与事件响应。
Stars: 0 | Forks: 0
# Azure 混合身份与安全监控实验室
在 Azure 中从零开始搭建的自主学习实验室。没有引导式操作指南,没有预配置环境。
## 本实验室涵盖的内容
| 阶段 | 重点 |
|---|---|
| 1 | Azure 基础 — resource group、VNet、预算控制 |
| 2 | Windows Server 2025 上的 Active Directory 域控制器 |
| 3 | 通过 Microsoft Entra Connect 进行混合身份同步 |
| 4 | Conditional Access 策略设计、执行与日志分析 |
| 5 | 故意配置错误、Sentinel 检测、KQL 威胁狩猎 |
## 环境
| 资源 | 详情 |
|---|---|
| Azure Subscription | Azure for Students($100 额度) |
| M365 Tenant | fk5xg7.onmicrosoft.com — E5 Developer(90天) |
| 区域 | East US 2 |
| VM | Standard_D2s_v3, Windows Server 2025 Datacenter |
| 域名 | lab.local |
| 同步 | Microsoft Entra Connect — Password Hash Sync,30分钟周期 |
## 阶段 2 — Active Directory
- 将 Windows Server 2025 VM 部署为域控制器
- 创建域 `lab.local`,并设置 OU 结构:`OU-Users`、`OU-Admins`、`OU-Workstations`
- 配置静态私有 IP (10.0.0.4) 并将 VNet DNS 指向 DC
- 设置 NSG 入站规则,解决了 subnet 和 NIC 级别之间的双重 NSG 冲突
## 阶段 3 — 混合身份
- 通过 PowerShell 将可路由的 UPN 后缀添加到 AD 林
- 使用 `Set-ADUser` 修正格式错误的 UPN
- 从 entra.microsoft.com 安装 Entra Connect(已不再位于 Microsoft Download Center)
- 验证同步:`Get-ADSyncScheduler` 返回 `SyncCycleEnabled: True`
- 所有 3 个用户均可在 Entra ID 中看到,且 **On-premises sync enabled: Yes**
## 阶段 4 — Conditional Access
构建并测试了三项策略:
| 策略 | 范围 | 控制 |
|---|---|---|
| CA001 — Require MFA | 所有用户 / 所有资源 | Require MFA |
| CA002 — Block Legacy Auth | 所有用户 / 所有资源 | Block legacy clients |
| CA003 — Block Untrusted Locations | 所有用户 / 所有资源 | Block non-trusted IPs |
通过无痕浏览器以同步的测试用户身份登录进行测试。通过 Entra 登录日志(错误代码 53003)中的 **Conditional Access tab** 验证了策略的执行。
## 阶段 5 — 配置错误与检测
### 检测栈
- Log Analytics Workspace (`law-security-lab`) 上的 Microsoft Sentinel
- Entra ID connector — 登录日志 + 审计日志
- Azure Activity connector — 资源更改跟踪
- Microsoft Defender for Cloud — 已启用 Servers 计划
### 引入的配置错误
**1. NSG 端口暴露**
- 创建了入站规则 `misconfig-inbound`:源 `0.0.0.0/0`,所有端口,所有协议,允许
- 将域控制器暴露给整个互联网
**2. Storage Account 公共访问**
- 在 `stlabsecurity` 上启用了匿名 blob 访问
- 创建了具有匿名读取访问权限的 container `public-data`
**3. MFA Bypass**
- 清除了 `bjones` 的 MFA 注册
- 将其从 CA001 中排除,并禁用了所有 CA 策略
- 记录了在没有 MFA 挑战的情况下成功登录的情况
### 使用的 KQL 查询
```
// NSG rule changes
AzureActivity
| where OperationNameValue contains "securityRules"
| project TimeGenerated, Caller, OperationNameValue, Properties
| order by TimeGenerated desc
```
```
// Storage account changes
AzureActivity
| where OperationNameValue contains "storageAccounts"
| project TimeGenerated, Caller, OperationNameValue, ActivityStatusValue
| order by TimeGenerated desc
```
```
// Sign-ins without MFA
SigninLogs
| where UserPrincipalName contains "bjones"
| project TimeGenerated, UserPrincipalName, AuthenticationRequirement, ConditionalAccessStatus
| order by TimeGenerated desc
```
### 日志证据 — NSG 配置错误
```
Time: 2026-06-29 18:40:17 UTC
Actor: kcampb67@wgu.edu
Operation: MICROSOFT.NETWORK/NETWORKSECURITYGROUPS/SECURITYRULES/WRITE
Resource: vm-dc02-nsg/misconfig-inbound
Rule: sourceAddressPrefix=0.0.0.0/0, destinationPortRange=*, access=Allow
```
## 克服的挑战
| 挑战 | 解决方案 |
|---|---|
| East US 区域被 Azure Policy 阻止 | 迁移至 East US 2 |
| B/A 系列 VM 配额限制为 0 | 使用了 Standard_D2s_v3 |
| 双重 NSG 冲突阻止 RDP | 向 subnet 和 NIC NSG 添加允许规则 |
| Entra ID 许可证页面无法访问 | 使用 M365 Developer Program 获取免费的 E5 租户 |
| GUI 输入导致 UPN 格式错误 | 通过 PowerShell `Set-ADUser` 修复 |
| Entra Connect 从 Download Center 迁出 | 在 entra.microsoft.com 找到 |
| 企业网络阻止端口 3389 | 通过 HTTPS 使用 Azure Bastion |
| VM 取消分配后同步停止 | 重启 ADSync,触发手动增量同步 |
## 使用的工具
Active Directory · Microsoft Entra ID · Entra Connect · Conditional Access · Microsoft Sentinel · Azure Activity Log · KQL · Microsoft Defender for Cloud · Azure NSG · Azure Bastion · PowerShell
标签:Active Directory, AI合规, Azure, Plaso, Terraform 安全, 安全实验环境, 安全运营中心, 混合身份验证, 网络映射