hacktricks/src/network-services-pentesting/135-pentesting-msrpc.md

93 lines
5.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 135, 593 - Pentesting MSRPC
{{#include ../banners/hacktricks-training.md}}
## 基本信息
Microsoft 远程过程调用 (MSRPC) 协议是一种客户端-服务器模型,使程序能够请求位于另一台计算机上的程序提供服务,而无需了解网络的具体细节。该协议最初源于开源软件,后来由 Microsoft 开发并获得版权。
RPC 端点映射器可以通过 TCP 和 UDP 端口 135 访问SMB 在 TCP 139 和 445使用空会话或经过身份验证的会话以及作为 TCP 端口 593 上的 Web 服务。
```
135/tcp open msrpc Microsoft Windows RPC
```
## MSRPC是如何工作的
由客户端应用程序发起MSRPC过程涉及调用本地存根过程然后与客户端运行时库交互以准备并将请求传输到服务器。这包括将参数转换为标准网络数据表示格式。如果服务器是远程的传输协议的选择由运行时库决定确保RPC通过网络栈传递。
![https://0xffsec.com/handbook/images/msrpc.png](https://0xffsec.com/handbook/images/msrpc.png)
## **识别暴露的RPC服务**
通过查询RPC定位服务和各个端点可以确定通过TCP、UDP、HTTP和SMB暴露的RPC服务。工具如rpcdump有助于识别独特的RPC服务以**IFID**值表示,揭示服务细节和通信绑定:
```
D:\rpctools> rpcdump [-p port] <IP>
**IFID**: 5a7b91f8-ff00-11d0-a9b2-00c04fb6e6fc version 1.0
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
```bash
use auxiliary/scanner/dcerpc/endpoint_mapper
use auxiliary/scanner/dcerpc/hidden
use auxiliary/scanner/dcerpc/management
use auxiliary/scanner/dcerpc/tcp_dcerpc_auditor
rpcdump.py <IP> -p 135
```
所有选项除了 `tcp_dcerpc_auditor` 都是专门针对端口 135 上的 MSRPC 进行攻击设计的。
#### 显著的 RPC 接口
- **IFID**: 12345778-1234-abcd-ef00-0123456789ab
- **命名管道**: `\pipe\lsarpc`
- **描述**: LSA 接口,用于枚举用户。
- **IFID**: 3919286a-b10c-11d0-9ba8-00c04fd92ef5
- **命名管道**: `\pipe\lsarpc`
- **描述**: LSA 目录服务 (DS) 接口,用于枚举域和信任关系。
- **IFID**: 12345778-1234-abcd-ef00-0123456789ac
- **命名管道**: `\pipe\samr`
- **描述**: LSA SAMR 接口,用于访问公共 SAM 数据库元素(例如,用户名)并强行破解用户密码,无论账户锁定策略如何。
- **IFID**: 1ff70682-0a51-30e8-076d-740be8cee98b
- **命名管道**: `\pipe\atsvc`
- **描述**: 任务调度程序,用于远程执行命令。
- **IFID**: 338cd001-2244-31f1-aaaa-900038001003
- **命名管道**: `\pipe\winreg`
- **描述**: 远程注册表服务,用于访问和修改系统注册表。
- **IFID**: 367abb81-9844-35f1-ad32-98f038001003
- **命名管道**: `\pipe\svcctl`
- **描述**: 服务控制管理器和服务器服务,用于远程启动和停止服务以及执行命令。
- **IFID**: 4b324fc8-1670-01d3-1278-5a47bf6ee188
- **命名管道**: `\pipe\srvsvc`
- **描述**: 服务控制管理器和服务器服务,用于远程启动和停止服务以及执行命令。
- **IFID**: 4d9f4ab8-7d1c-11cf-861e-0020af6e7c57
- **命名管道**: `\pipe\epmapper`
- **描述**: DCOM 接口,用于强行破解密码和通过 WM 收集信息。
### 识别 IP 地址
使用 [https://github.com/mubix/IOXIDResolver](https://github.com/mubix/IOXIDResolver),来自 [Airbus research](https://www.cyber.airbus.com/the-oxid-resolver-part-1-remote-enumeration-of-network-interfaces-without-any-authentication/),可以滥用 _**ServerAlive2**_ 方法在 _**IOXIDResolver**_ 接口内。
该方法已被用于从 HTB 盒子 _APT_ 获取接口信息作为 **IPv6** 地址。有关 0xdf APT 的详细信息,请参见 [这里](https://0xdf.gitlab.io/2021/04/10/htb-apt.html),它包括使用来自 [Impacket](https://github.com/SecureAuthCorp/impacket/) 的 rpcmap.py 的替代方法,使用 _stringbinding_(见上文)。
### 使用有效凭据执行 RCE
如果有有效用户的凭据,可以使用来自 impacket 框架的 [dcomexec.py](https://github.com/fortra/impacket/blob/master/examples/dcomexec.py) 在机器上执行远程代码。
**记得尝试不同的可用对象**
- ShellWindows
- ShellBrowserWindow
- MMC20
## 端口 593
来自 [rpctools](https://resources.oreilly.com/examples/9780596510305/tree/master/tools/rpctools) 的 **rpcdump.exe** 可以与此端口交互。
## 参考文献
- [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/)
{{#include ../banners/hacktricks-training.md}}