PSExec is a tool designed for system administrators, facilitating remote command execution, and is part of the Sysinternals Suite. However, this tool is frequently exploited for lateral movement by Threat Actors.
If PSEXEC is legitimately used within your environment, it’s advisable to establish a custom path for its installation. By doing so, you can specifically search for executions of PSEXEC from other directories.
When executingPSEXEC :
RelativeTargetName
contains the strings*-stdin
,*-stdout
or*-stderr
RelativeTargetName
contains the stringpsexecsvc*
When executing PSEXEC from Impacketpsexec.py (uses a version of RemCom):
RelativeTargetName
can contain:*Remcom_Communication
RemCom_stdin*
RemCom_stderr*
RemCom_stdout*
svcctl
ShareName
with the value\\\\*\\IPC$*
(\*\IPC$)The executable dropped in the shareadmin$
:
ShareName
=\\\\*\\Admin$*
RelativeTargetName
with a name ending with*.exe
or*.dll
AccessMask
with the value0x2
When executingPSEXEC :
ImagePath
=*PSEXESVC.exe
(PSEXESVC.exe is copied to the %SystemRoot% directory by default)ServiceName
=*PSEXESVC*
(make sure ServiceName is parsed in EventID 7036, you may see 'PSEXESVC service state has changed' when starting and stopping psexec)You can search for windows Security EventID 4624 (LogonType 3) near the time when EventID 7045 (or 4697) is logged on the machine to get the source address of the remote computer by pivoting on the SID of the user in EventID 7045
IfPSEXEC is executed with the -r argument (Specifies the name of the remote service to create or interact with), we won’t see the ServiceName PSEXECSVC in the EventID 7045, we should still see:
user mode service
demand start
or3
LocalSystem
or0x10
and with Sysmon EventID 1 we should still be able to detect default PSEXEC from microsoft with the field OriginalFileName =*psexesvc.exe*
with the process_name different thanPSEXESVC.exe*
or*psexec*.
Service creation from psexec.py impacket and psexec Metasploit is more difficult to detect, we should see a randomly generated string of 8 upper and lowercase letters for psexec of Metasploit in the fieldServiceName
of the EventID 4697 or a randomly generated string of 16 upper and lowercase letters for psexec of Metasploit in the fieldServiceName
of the EventID 7045 (and 4 upper and lowercase letters for psexec from impacket - may generate too many false positives)
An operation was attempted on a privileged object:
*PSEXESVC*
Registry value set:
*\SOFTWARE\Sysinternals\PsExec\EulaAccepted*
Detect one of these keywords in the fieldCommandLine
orprocess
(should include process name with full path and command line executed) or even ScriptBlockText (powershell script content):
*PSEXECSVC*
*PsExec.exe*
*PsExec64.exe*
* -accepteula -nobanner -d cmd.exe /c*
(common argument)*ps.exe -accepteula*
(common argument)*psexec.exe * -r *
(if we just want to see the use of a custom name)*psexec64.exe * -r *
(if we just want to see the use of a custom name)*.exe -i -s cmd.exe
(psexec command arguments -i -s to execute as SYSTEM)*remcom.exe*
(remcom)*.exe" \\* /user:* /pwd:* cmd.exe*
(remcom common argument)*smb-psexec.nse*
(nmap nse script)*psexec_ms17_010.rb*
(metasploit)*ms17_010_psexec.*
(metasploit)*/psexec.json*
(metasploit)*\psexec.json*
(metasploit)*PsExecLiveImplant*
(koadic)*/exec_psexec*
(koadic)*psexec.py*
(impacket)*impacket-psexec*
(impacket)*psexec_windows.exe*
(impacket)*jump-exec psexec*
(havoc)*/Jump-exec/Psexec*
(havoc)*PsExecLog.log*
(gofetch)*Invoke-PsExec*
(empire + AutoRDPwn)*\tools\psexec.rb*
(empire)*/tools/psexec.rb*
(empire)*/smb/psexec.rb*
(empire)*\smb\psexec.rb*
(empire)*-PsExecCmd*
(empire)*PSEXEC_PSH*
(angrypuppy)*Ladon psexec*
(ladon)*jump psexec_psh*
(cobaltstrike)*jump psexec64*
(cobaltstrike)*bpsexec_psh*
(pycobalt)*bpsexec_command*
(pycobalt)*invoke-psexecpayload*
(poshc2)*PsExecMenu(*
(Redpeanut)*sharppsexec*
(Redpeanut)*SharpPsExecManager*
(Redpeanut)*SharpPsExecService*
(Redpeanut)*Commands/PsExecCommand.*
(SharpC2)*SharpNoPSExec*
(SharpNoPSEXEC)* --target=* --payload=*cmd.exe /c*
(SharpNoPSEXEC)*Plugins\Execution\PSExec*
(TokenVator)*LateralMovement_PassTheTicket_ByPsexec.py*
(ViperC2)*Lateral/PSExec.cs*
(WheresMyImplant)*Lateral\PSExec.cs*
(WheresMyImplant)*wmiexec.py*
(wmiexec)*smbexec.py*
(smbexec)*dcomexec.py*
(impacket)These keywords are taken from theThreatHunting-keywords project, more keywords are available for each psexec like tools in the csv.
While I have provided a detailed overview of the detection for PSEXEC, i will not be offering such comprehensive summaries for each individual tool here (may be reserved for another post)
All the keywords above also apply to the file manipulation events using the field TargetFilename
ProcessName =*PSEXEC*
(depends on the usage)
Pipe creation/access by PSEXEC, psexec.py, RemCom, PAExec, CSExec:PipeName
start with:
psexec*
psexesvc*
paexec*
remcom*
csexec*
or ends with:
*-stdin
*-stderr
*-stdout
On the target machine, when PSEXEC is used, the PSEXEC named pipe will contain the attacker’s hostname. During DFIR investigations, you can also search for a file with the structurePsExec-SOURCE_HOSTNAME-XXXXXXXX.key
in the MFT, which is created on the target machine. For a detailed guide on hunting for suspicious named pipes, check outghttps://mthcht.medium.com/threat-hunting-suspicious-named-pipes-a4206e8a4bc8
Some of the psexec like tools from metasploit or impacket can trigger alerts from Microsoft Defender, identify the signature names associated with these psexec like tools for your Anti-Virus or EDR solution your environment.
signatures:
VirTool:Win32/RemoteExec
VirTool:Win64/RemoteExec
*psexec*
All the windows logs and forensic artefact can be collected with DFIR-ORC
When aiming to identify PSEXEC usage on a remote machine, enhance detection accuracy by correlating and incorporating the source IP address, originating user, and source workstation in your alerts to help your analysts in their investigations.
PSExec is commonly utilized in various environments, which often complicates the task of distinguishing or detecting malicious activities associated with its use, ensure that you implement a strict policy regarding the use of PSEXEC. By clearly defining the rules for its installation and usage, you can more easily detect deviations from these guidelines, enabling quicker identification of unauthorized activities
Threat Detection Engineering and DFIR Insights