MS-SCMR (Service Control Manager Remote Protocol) for Lateral Movement
Requirements
- Credentials (password, NT hash, Kerberos TGT) of a member of the local Administrators group on the target machine.
- Read-write SMB share access.
- Remote SCM RPC interface enabled the target machine (always by default).
- SMB share enabled on the target machine (always by default but 445/TCP might be filtered on firewall).
Description
Through the MS-SCMR (RPC) protocol, Windows allows remote communication with another machine's Service Control Manager (SCM). This protocol is invoked using a named pipe ntsvcs
via SMB IPC$
share.
It allows, among other things, remote startup of services. This capability ultimately allows the user to execute code on another machine (by creating a service), which is the basis for techniques like PsExec and SmbExec. PsExec and SmbExec are well-known attacks designed to establish a pseudo-interactive "shell" on the target machine. Both attacks require access to SMB share of the target host (445/TCP).
By default, using service execution techniques a user needs to be a local administrator on the target machine to remotely interact with SCM via RPC. Windows services executed by the local administrator by default run in the context of SYSTEM user. Logon via MS-SCMR (RPC call) is of the Network type (no reusable credentials).
PsExec
IMPORTANT: A user who wants to use PsExec on a remote machine must have read-write access to at least one SMB share. Without remote SMB access, it is not possible to use PsExec.
Linux:
Windows (SysInternals - PsExec.exe):
PsExec works by writing an .exe
binary to the writable SMB share on the target host. Then, SCM is called remotely (via named pipe) to execute the binary using created service. Binary creates a named pipe accessible via SMB. This named pipe is used by the user to execute commands remotely and read the output. Two-way communication is established via SMB.
Caveats:
- A generic binary is often detected by AV.
- PsExec leaves artifacts behind on SMB share that require manual cleaning. The uploaded binary is not automatically removed.
SmbExec
Linux:
Unlike PsExec, SmbExec doesn't transfer a detectable binary to the target host. Instead of using a malicious binary, SmbExec launches a new service (using SCM remotely via named pipe) with each new command. It executes the command in the binPath
parameter of the service and closes the service. It just executes each desired command as a new service. Output is read via SMB share. There is no leftover on disk.
SmbExec is stealthier alternative to easy to detect PsExec. Nevertheless, it is important to remember that an event log is created for every command executed (service creation).
Caveats
- Each command run by SmbExec is a separate service. Therefore, there is no real session. Loading modules in PowerShell makes no sense. You have to load and call the module in a single command.
- There's no
cd
command. Again - there's no real session.
Raw Service Execution (ScExec)
You can use the standard Windows tool sc.exe
to run a service on a remote machine. It can be a single shell command or, for example, a reverse-shell binary sent over SMB.
Linux (impacket-services
is basically a Linux port of native sc.exe
):
Windows:
IMPORTANT: Watch out for spaces in arguments. They are necessary!