# MSRPC (Microsoft Remote Procedure Call) Pentesting

## MSRPC (Microsoft Remote Procedure Call) Pentesting <a href="#msrpc-microsoft-remote-procedure-call-pentesting" id="msrpc-microsoft-remote-procedure-call-pentesting"></a>

It is also known as a function call or a subroutine call. Default ports are 135, 593.

### Enumeration <a href="#enumeration" id="enumeration"></a>

```
nmap --script msrpc-enum -p 135 <target-ip>
```

#### RPC Endpoints <a href="#rpc-endpoints" id="rpc-endpoints"></a>

To enumerate RPC endpoints, use `impacket-rpcdump`.

```
impacket-rpcdump -port 135 <target-ip> | grep -E 'MS-EFSRPC|MS-RPRN|MS-PAR'
```

* **MS-EFSRPC**: It might be vulnerable to **PetitPotam**.
* **MS-RPRN**, **MS-PAR**: It might be vulnerable to **PrintNightmare**.

#### Metasploit <a href="#metasploit" id="metasploit"></a>

```
msfconsole
msf> use auxiliary/scanner/dcerpc/endpoint_mapper
msf> use auxiliary/scanner/dcerpc/hidden
msf> use auxiliary/scanner/dcerpc/management
msf> use auxiliary/scanner/dcerpc/tcp_dcerpc_auditor
```

### Connect <a href="#connect" id="connect"></a>

```
# Anonymous logon
rpcclient -N -U "" <target-ip>
rpcclient -N -U "" -p 593 <target-ip>
rpcclient -N -U "" dc.example.local

# Specify username
# -W: Workgroup
# -N: No password
rpcclient -U username <target-ip>
rpcclient -W WORKGROUP -U username <target-ip>
rpcclient -U username -N <target-ip>

# -k: Kerberos authentication
rpcclient -k <target-ip>
```

#### Commands <a href="#commands" id="commands"></a>

```
# Server info
rpcclient $> srvinfo

# Enumerate domains
rpcclient $> enumdomains
# Enumerate domain users
rpcclient $> enumdomusers
# Enumerate domain groups
rpcclient $> enumdomgroups

# Domain info
rpcclient $> querydominfo

# Current username
rpcclient $> getusername

# If the current user has permission to change another user password, we can change another user password.
rpcclient $> setuserinfo2 <another_user> 23 <new_password>
```
