vitwervit/coerce_filter
GitHub: vitwervit/coerce_filter
通过 Windows RPC Filter 阻断 AD 环境中用于 NTLM Relay 攻击的强制认证 RPC 接口,并提供基于 GPO 的域级自动化部署方案。
Stars: 0 | Forks: 0
# RPC 强制认证过滤器
用于阻止在强制认证攻击(NTLM Relay)中使用的 RPC 接口。
## 覆盖的攻击向量
| 攻击 | 协议 | UUID |
|-----------------|-----------|----------------------------------------|
| PrinterBug | MS-RPRN | `12345678-1234-ABCD-EF00-0123456789AB` |
| PrinterBug | MS-RPRN | `c681d488-d850-11d0-8c52-00c04fd90f7e` |
| AsyncPrintBug | MS-PAR | `76f03f96-cdfd-44fc-a22c-64950a001209` |
| PetitPotam | MS-EFSR | `df1941c5-fe89-4e79-bf10-463657acf44d` |
| PetitPotam | MS-EFSR | `c8cb7687-e6d3-11d2-a958-00c04f682e16` |
| DFSCoerce | MS-DFSNM | `4fc742e0-4a10-11cf-8273-00aa004ae673` |
| ShadowCoerce | MS-FSRVP | `a8e0653c-2744-4389-a61d-7373df8b2292` |
| EventLog coerce | MS-EVEN | `82273fdc-e32a-18c3-3f78-827929dc23ea` |
| EventLog coerce | MS-EVEN6 | `f6beaff7-1e19-4fbb-9f8f-b89e2018337c` |
## 对基础设施的影响
| 功能 | 应用后的结果 |
|------------------|---------------------------|
| 通过 DC 打印 (Print Spooler) | ❌ 不工作 |
| 通过独立 print-server 打印 (非 DC) | ✅ 正常工作 |
| 域身份验证 | ✅ 不受影响 |
| 组策略 | ✅ 不受影响 |
| DC 之间的复制 | ✅ 不受影响 |
| DFS (文件访问, `\\domain\share`) | ✅ 正常工作 — MS-DFSC 通过 SMB 进行,而非 RPC |
| DFS 管理 (`dfsmgmt.msc`, PowerShell) | ❌ 不工作 — MS-DFSNM 已被阻止 |
| EFS (文件加密) | ⚠️ 需检查 — MS-EFSR 已被阻止 |
| VSS 卷影副本 | ⚠️ 需检查 — MS-FSRVP 已被阻止 |
### 打印建议
在将过滤器应用于 DC 之前:
```
:: Отключить Print Spooler на контроллерах домена
sc config spooler start= disabled
net stop spooler
```
打印应该通过非 DC 的专用 print-server 进行。
无论是否使用此过滤器,这都是正确的做法。
## 持久化
RPC 过滤器**在重启后会被重置**。为了保持持续生效,必须通过 GPO + Scheduled Task 设置开机自动运行(参见“部署”部分)。
## 部署到域中的所有计算机
推荐方式:**GPO + Scheduled Task**。
GPO 将脚本分发到主机,Scheduled Task 确保在每次开机时以 SYSTEM 身份运行,且先于任何用户登录。
### 步骤 1 — 将脚本放置在 SYSVOL 中
```
\\corp.local\SYSVOL\corp.local\scripts\rpc_coerce_filter.cmd
```
### 步骤 2 — 创建 GPO
1. 打开 `gpmc.msc`
2. 右键点击目标 OU (或整个域) → **Create a GPO and Link it here**
3. 命名为:`RPC Coercion Filter`
### 步骤 3 — GPO:将脚本复制到主机
`Computer Configuration → Preferences → Windows Settings → Files`
| 字段 | 值 |
|------|----------|
| Action | Replace |
| Source | `\\corp.local\SYSVOL\corp.local\scripts\rpc_coerce_filter.cmd` |
| Destination | `C:\Windows\System32\rpc_coerce_filter.cmd` |
### 步骤 4 — GPO:创建 Scheduled Task(持久化)
`Computer Configuration → Preferences → Control Panel Settings → Scheduled Tasks`
`→ New → Scheduled Task (At least Windows 7)`
| 字段 | 值 |
|------|----------|
| Action | Replace |
| Name | RPC Coercion Filter |
| Run As | SYSTEM |
| Run with highest privileges | ✅ |
| Trigger | At startup |
| Execute | `netsh.exe` |
| Arguments | `-f C:\Windows\System32\rpc_coerce_filter.cmd` |
| Stop task if runs longer than | 5 minutes |
### 步骤 5 — GPO:Immediate Task(无需重启直接应用)
`Scheduled Tasks → New → Immediate Task (At least Windows 7)`
保持相同的设置,将触发器设为日期为过去时间的 **Once** —
这样它会在主机下一次应用 GPO 时立即执行。
### 步骤 6 — 强制应用 GPO
```
$computers = Get-ADComputer -Filter * | Select-Object -ExpandProperty Name
Invoke-Command -ComputerName $computers -ScriptBlock {
gpupdate /force
} -ErrorAction SilentlyContinue
```
## 验证应用情况
### 在单台机器上
```
netsh rpc filter show filter
```
应该有 9 条包含 `actiontype = block` 的规则。
### 在域中的所有机器上
```
$computers = Get-ADComputer -Filter * | Select-Object -ExpandProperty Name
Invoke-Command -ComputerName $computers -ScriptBlock {
$task = Get-ScheduledTask -TaskName "RPC Coercion Filter" -ErrorAction SilentlyContinue
$filters = (netsh rpc filter show filter 2>&1 | Select-String "actiontype\s*=\s*block").Count
[PSCustomObject]@{
Computer = $env:COMPUTERNAME
TaskExists = ($null -ne $task)
TaskState = if ($task) { $task.State } else { "Missing" }
FilterCount = $filters
Status = if ($filters -eq 9) { "OK" } else { "MISSING" }
}
} -ErrorAction SilentlyContinue | Sort-Object Status | Format-Table -AutoSize
```
## 移除过滤器
### 在单台机器上
```
netsh rpc filter
delete filter filterkey=all
quit
```
### 在域中的所有机器上
```
$computers = Get-ADComputer -Filter * | Select-Object -ExpandProperty Name
Invoke-Command -ComputerName $computers -ScriptBlock {
netsh rpc filter
delete filter filterkey=all
quit
} -ErrorAction SilentlyContinue
```
### 移除 Scheduled Task
```
Invoke-Command -ComputerName $computers -ScriptBlock {
Unregister-ScheduledTask -TaskName "RPC Coercion Filter" -Confirm:$false -ErrorAction SilentlyContinue
} -ErrorAction SilentlyContinue
```
标签:AI合规, RPC, Terraform 安全, TLS, 活动目录, 系统加固, 防御工具