Translated ['src/network-services-pentesting/135-pentesting-msrpc.md'] t

This commit is contained in:
Translator 2025-07-16 20:32:17 +00:00
parent 7ef71704bf
commit 0b23c3763c

View File

@ -26,7 +26,7 @@ Annotation: Messenger Service
UUID: 00000000-0000-0000-0000-000000000000
Binding: ncadg_ip_udp:<IP>[1028]
```
通过特定协议启用对RPC定位服务的访问ncacn_ip_tcp和ncadg_ip_udp用于通过端口135访问ncacn_np用于SMB连接ncacn_http用于基于Web的RPC通信。以下命令示例展示了利用Metasploit模块审计和与MSRPC服务交互主要集中在端口135
通过特定协议启用对RPC定位服务的访问ncacn_ip_tcp和ncadg_ip_udp用于通过端口135访问ncacn_np用于SMB连接以及ncacn_http用于基于Web的RPC通信。以下命令示例展示了利用Metasploit模块审计和与MSRPC服务交互主要集中在端口135
```bash
use auxiliary/scanner/dcerpc/endpoint_mapper
use auxiliary/scanner/dcerpc/hidden
@ -34,7 +34,7 @@ use auxiliary/scanner/dcerpc/management
use auxiliary/scanner/dcerpc/tcp_dcerpc_auditor
rpcdump.py <IP> -p 135
```
所有选项除了 `tcp_dcerpc_auditor` 都是专门针对端口 135 上的 MSRPC 进行攻击设计的。
所有选项除了 `tcp_dcerpc_auditor` 都是专门针对端口 135 上的 MSRPC 进行攻击的。
#### 显著的 RPC 接口
@ -83,8 +83,78 @@ rpcdump.py <IP> -p 135
来自 [rpctools](https://resources.oreilly.com/examples/9780596510305/tree/master/tools/rpctools) 的 **rpcdump.exe** 可以与此端口交互。
### 自动化接口枚举与动态客户端生成 (NtObjectManager)
PowerShell 大师 **James Forshaw** 在开源的 *NtObjectManager* 模块中暴露了大多数 Windows RPC 内部结构。使用它,您可以在几秒钟内将任何 RPC 服务器 DLL / EXE 转换为 **功能齐全的客户端存根**,无需 IDL、MIDL 或手动反序列化。
```powershell
# Install the module once
Install-Module NtObjectManager -Force
# Parse every RPC interface exported by the target binary
$rpcinterfaces = Get-RpcServer "C:\Windows\System32\efssvc.dll"
$rpcinterfaces | Format-Table Name,Uuid,Version,Procedures
# Inspect a single procedure (opnum 0)
$rpcinterfaces[0].Procedures[0] | Format-List *
```
典型输出准确地暴露了参数类型,如同它们在 **MIDL** 中出现的那样(例如 `FC_C_WSTRING``FC_LONG``FC_BIND_CONTEXT`)。
一旦你知道了接口,你可以 **生成一个准备编译的 C# 客户端**
```powershell
# Reverse the MS-EFSR (EfsRpc*) interface into C#
Format-RpcClient $rpcinterfaces[0] -Namespace MS_EFSR -OutputPath .\MS_EFSR.cs
```
在生成的存根中,您将找到以下方法:
```csharp
public int EfsRpcOpenFileRaw(out Marshal.NdrContextHandle ctx, string FileName, int Flags) {
// marshals parameters & calls opnum 0
}
```
PowerShell 助手 `Get-RpcClient` 可以创建一个 **交互式客户端对象**,以便您可以立即调用该过程:
```powershell
$client = Get-RpcClient $rpcinterfaces[0]
Connect-RpcClient $client -stringbinding 'ncacn_np:127.0.0.1[\\pipe\\efsrpc]' `
-AuthenticationLevel PacketPrivacy `
-AuthenticationType WinNT # NTLM auth
# Invoke the procedure → returns an authenticated context handle
$ctx = New-Object Marshal.NdrContextHandle
$client.EfsRpcOpenFileRaw([ref]$ctx, "\\\127.0.0.1\test", 0)
```
身份验证Kerberos / NTLM和加密级别`PacketIntegrity``PacketPrivacy`,…)可以通过 `Connect-RpcClient` cmdlet 直接提供 这对于 **绕过保护高权限命名管道的安全描述符** 理想。
---
### 上下文感知 RPC 模糊测试 (MS-RPC-Fuzzer)
静态接口知识很好,但你真正想要的是 **覆盖引导模糊测试**,它理解 *上下文句柄* 和复杂的参数链。开源的 **MS-RPC-Fuzzer** 项目正是自动化了这个工作流程:
1. 枚举目标二进制文件导出的每个接口/过程(`Get-RpcServer`)。
2. 为每个接口生成动态客户端(`Format-RpcClient`)。
3. 随机化输入参数(宽字符串长度、整数范围、枚举),同时尊重原始 **NDR 类型**
4. 跟踪一个调用返回的 *上下文句柄*,以自动提供后续过程。
5. 对所选传输ALPC、TCP、HTTP 或命名管道)发起高频调用。
6. 记录退出状态/故障/超时,并导出 **Neo4j** 导入文件以可视化 *接口 → 过程 → 参数* 关系和崩溃集群。
示例运行(命名管道目标):
```powershell
Invoke-MSRPCFuzzer -Pipe "\\.\pipe\efsrpc" -Auth NTLM `
-MinLen 1 -MaxLen 0x400 `
-Iterations 100000 `
-OutDir .\results
```
一个单一的越界写入或意外异常将立即显示出触发它的确切 opnum + 模糊负载——这是一个稳定的概念验证利用的完美起点。
> ⚠️ 许多 RPC 服务在以 **NT AUTHORITY\SYSTEM** 身份运行的进程中执行。这里的任何内存安全问题通常会转化为本地特权提升或(当通过 SMB/135 暴露时)*远程代码执行*。
---
## 参考文献
- [Automating MS-RPC vulnerability research (2025, Incendium.rocks)](https://www.incendium.rocks/posts/Automating-MS-RPC-Vulnerability-Research/)
- [MS-RPC-Fuzzer context-aware RPC fuzzer](https://github.com/warpnet/MS-RPC-Fuzzer)
- [NtObjectManager PowerShell module](https://github.com/googleprojectzero/sandbox-attacksurface-analysis-tools/tree/master/NtObjectManager)
- [https://www.cyber.airbus.com/the-oxid-resolver-part-1-remote-enumeration-of-network-interfaces-without-any-authentication/](https://www.cyber.airbus.com/the-oxid-resolver-part-1-remote-enumeration-of-network-interfaces-without-any-authentication/)
- [https://www.cyber.airbus.com/the-oxid-resolver-part-2-accessing-a-remote-object-inside-dcom/](https://www.cyber.airbus.com/the-oxid-resolver-part-2-accessing-a-remote-object-inside-dcom/)
- [https://0xffsec.com/handbook/services/msrpc/](https://0xffsec.com/handbook/services/msrpc/)