PsExec forensics: how PsExec works and the evidence it leaves on both hosts
How PsExec works and the evidence it leaves: PSEXESVC, event IDs 7045, 4624, 5145 and 4648, Prefetch and registry on both hosts, and its imitators.
PsExec is a free Microsoft Sysinternals tool that runs a program on a remote Windows computer: psexec \\server cmd.exe opens a command prompt on server as if you were sitting at it. Administrators have used it for twenty years, and so have attackers. MITRE ATT&CK lists it as software S0029, and ransomware operators routinely use it to push their encryptor to every machine in a domain at once.
For an investigator PsExec has a useful property: it cannot work without writing a file, creating a service and opening named pipes on the target, and the computer it runs from keeps its own records. This article walks through how PsExec works, then lists the evidence each step leaves on the source and the target, how imitators such as Impacket and attack frameworks differ, and how to separate an administrator's PsExec from an attacker's.
How PsExec works
When you run psexec \\target -u CORP\admin -p ... cmd.exe from a workstation, PsExec does five things:
- Authenticates to the target over SMB (TCP 445), with the credentials given or the current user's.
- Copies its service program, PSEXESVC.exe, to the target's
ADMIN$share, which isC:\Windows. - Creates and starts a service called PSEXESVC through the Service Control Manager's remote interface (the
svcctlnamed pipe onIPC$). - Talks to the service over named pipes: a control pipe named PSEXESVC and three pipes per session for the program's input and output, named after the source computer and process ID.
- Cleans up: when the program exits, PsExec stops and deletes the service and, normally, the PSEXESVC.exe file.
The program runs on the target as a child of PSEXESVC.exe. With -s it runs as SYSTEM; with -u it runs as the account given. The -r option renames the service and its pipes, which some attackers use to avoid the PSEXESVC name. Since version 2.1, PsExec encrypts its traffic, so the network shows SMB to port 445 and little else.
Every one of these steps leaves evidence, and because the process involves two computers, so does the evidence.
Evidence on the target computer
| Evidence | Where | What it shows |
|---|---|---|
| 4624 logon type 3 | Security log | The network logon from the source address, with the account |
| 4624 logon type 2 | Security log | When -u alternate credentials are used, the service logs the account on to run the program |
| 4672 | Security log | The session had administrative rights (required for ADMIN$) |
| 5140 for ADMIN$ and IPC$ | Security log, if File Share auditing is on | The shares opened, with source address |
| 5145 for PSEXESVC.exe, svcctl and PSEXESVC pipes | Security log, if Detailed File Share auditing is on | The file written to ADMIN$ and the pipes opened on IPC$ |
| 7045 service PSEXESVC | System log, always | Service File Name %SystemRoot%\PSEXESVC.exe, manual start, LocalSystem |
| 4697 | Security log, if Security System Extension auditing is on | The same service, plus the account and Logon ID that installed it |
| 7036 | System log | The PSEXESVC service entering the running and then stopped state |
| 4688 or Sysmon 1 | Security or Sysmon log | The program PsExec ran, with PSEXESVC.exe as its parent |
| Sysmon 17 and 18 | Sysmon log | The PSEXESVC pipes created and connected |
| Prefetch PSEXESVC.EXE | C:\Windows\Prefetch (workstations) | The service program ran, with run count and times |
| USN Journal and $MFT | NTFS | PSEXESVC.exe created in C:\Windows, then deleted |
| Amcache and ShimCache | Registry hives | PSEXESVC.exe present, with a SHA-1 in Amcache |
| Services key | SYSTEM hive | A leftover PSEXESVC key if the clean-up failed |
The most dependable of these is 7045: the System log is always on, any user can read it, and the service name and path are distinctive. A PSEXESVC service with a matching type 3 logon from the same address seconds earlier is PsExec, whoever ran it.
Evidence on the source computer
| Evidence | Where | What it shows |
|---|---|---|
| Sysinternals EULA key | NTUSER.DAT\Software\Sysinternals\PsExec, value EulaAccepted | This user ran PsExec at least once; the key's last-write time is the first acceptance |
| Prefetch PSEXEC.EXE | C:\Windows\Prefetch | PsExec ran, how often, and up to the last eight run times |
| 4688 or Sysmon 1 | Security or Sysmon log | The full command line: target, account, and the program run remotely |
| 4648 | Security log | With -u, explicit credentials used toward the target, naming the account and server |
| Amcache, ShimCache, BAM | Registry hives | psexec.exe path and hash, and for BAM a last-run time per user |
| Sysmon 3 | Sysmon log | Connections from psexec.exe to port 445 on each target |
| PowerShell history | PSReadLine history file | PsExec commands typed in a PowerShell console |
The command line, where it was logged, is the best single record: it names every target and the program run on each. The EULA key is the most persistent: it survives log roll-over and log clearing, and attackers rarely think to remove it. A copy of PsExec renamed to something innocent still writes the same key, because the key is created by the program, not by its file name.
The sequence in a timeline
Put the two sides together and a single PsExec run reads like this, within a few seconds:
SOURCE 4688 psexec.exe \\FS01 -s cmd.exe /c "whoami > C:\Windows\Temp\o.txt"
SOURCE 4648 explicit credentials toward FS01 (when -u is used)
TARGET 4624 logon type 3 from the source address, 4672 admin rights
TARGET 5140 \\*\ADMIN$ then \\*\IPC$ (if share auditing is on)
TARGET 5145 ADMIN$ PSEXESVC.exe written; IPC$ svcctl opened
TARGET 7045 service PSEXESVC, %SystemRoot%\PSEXESVC.exe, demand start
TARGET 7036 PSEXESVC entered the running state
TARGET 4688 cmd.exe, parent PSEXESVC.exe, running as SYSTEM
TARGET 7036 PSEXESVC entered the stopped state
TARGET USN PSEXESVC.exe deletedWhen ransomware operators use PsExec to deploy an encryptor, this sequence repeats across dozens or hundreds of targets within minutes, all from one or two source hosts. The source's Prefetch run count and the spread of 7045 events across the estate give the scale.
PsExec's imitators
Several attack tools copy the PsExec approach, admin share plus remote service, without using PsExec itself. They leave the same kinds of evidence with different names:
| Tool | Service name | Service File Name (7045) | Distinguishing evidence |
|---|---|---|---|
| Sysinternals PsExec | PSEXESVC (or the -r name) | %SystemRoot%\PSEXESVC.exe | EULA key on the source; PSEXESVC pipes |
| PAExec (open-source PsExec clone) | PAExec-pid-host | %SystemRoot%\PAExec-*.exe | Service and file names include the source host |
| Impacket psexec.py | Random four letters | Random-named .exe in C:\Windows | Random names; RemCom-based pipes |
| Impacket smbexec.py | Random or fixed short name | %COMSPEC% /Q /c echo <command> ^> \\127.0.0.1\C$\__output ... | A command line as the service path, output written to a file on C$ |
| Metasploit psexec | Random | Random .exe, or %COMSPEC% /b /c start ... powershell -nop -w hidden -enc ... | Encoded PowerShell in the service path |
| Cobalt Strike psexec / psexec_psh | Random | Random .exe on ADMIN$, or powershell -nop -w hidden -encodedcommand ... | Encoded PowerShell; random service names |
What they share is the core of the detection: a new service, installed over a network logon, whose program lives in C:\Windows with a random name or is a command line rather than an executable, often deleted within seconds. The event 7045 guide lists the signs that separate these from legitimate services.
Admin tool or attack?
PsExec use is not malicious by itself. The questions that separate administration from intrusion:
- Who and from where. IT staff running PsExec from a management server or their admin workstation is normal. The same tool run from a finance user's laptop, or by an account that has never used it before, is not.
- What it ran.
psexec \\host gpupdate /forceis administration.cmd.exe /cwith a download,vssadmin delete shadows,net user /add, or an unknown executable copied in first is not. - How many targets, how fast. Dozens of hosts in a minute from one source is deployment, by IT or by an attacker; check whether a change was scheduled.
- When. Outside working hours, or during an incident window already established from other evidence.
- What else happened on the source. Credential dumping, discovery commands, or a fresh logon from an unusual address on the source shortly before the PsExec run.
In a real investigation
PsExec did not appear in our Halden Freight lab case, but the attacker's final hop followed the same opening moves. Working on HF-WS02 at 22:12:18 UTC, they mapped HF-WS01's C$ share with net use, authenticating as svc_backup, a local administrator they had added to HF-WS01 less than three minutes before. Both machines kept a record of that moment: HF-WS01 logged a network logon (type 3) for svc_backup coming from 10.211.55.7, and HF-WS02 kept the command line plus a 4648 naming svc_backup and HF-WS01 as the target. About seventeen seconds after that, they attempted to pull the persistence script across from the admin share. Authenticating and connecting to an admin share is exactly where PsExec starts; with PsExec in place of a manual copy, HF-WS01's System log would next have shown the PSEXESVC service, and its Prefetch folder a PSEXESVC.EXE entry.
The lesson carries over directly. When the remote-service step is missing, the network logon, the admin share and the explicit credentials on the source are still there, and they are what links the two hosts.
Finding PsExec in Arcsentry
Arcsentry parses the Security, System and Sysmon logs, Prefetch, Amcache, ShimCache, BAM, the USN Journal and the registry (including the Sysinternals EULA keys) from every collected host into one case, so both sides of each PsExec run are in the same timeline. This AQL query on the System log lists services that match PsExec and its imitators:
filter event_code == "7045"
derive {svc = service_name, img = $imagepath, acct = $accountname}
filter svc ~= "(?i)psexesvc|paexec|remcom" || img ~= "(?i)(%comspec%|-enc|\\\\127\\.0\\.0\\.1\\\\)"
select {timestamp, svc, img, acct}
sort {timestamp}The AI investigator follows each hit back to its network logon, the source address and the source host's own records, and proposes the service name, file and source host as indicators across the case. For the wider picture of how attackers move between hosts, see the lateral movement evidence guide.
Frequently asked questions
What is PsExec?
PsExec is a free Microsoft Sysinternals command-line tool that runs programs on remote Windows computers. It copies a service program to the target's ADMIN$ share, starts it as a service called PSEXESVC, and relays the program's input and output over named pipes.
What is PSEXESVC?
PSEXESVC is the service PsExec creates on the target computer to run the requested program. Its program, PSEXESVC.exe, is copied to C:\Windows and normally deleted when the command finishes. A PSEXESVC service in the System log (event 7045) means PsExec was run against that computer.
Which event IDs show PsExec?
On the target: 7045 (service PSEXESVC installed), 4624 type 3 (network logon) with 4672, 4697 when service auditing is on, 5140 and 5145 for ADMIN$ and IPC$ when share auditing is on, and 4688 or Sysmon 1 for the process it ran. On the source: 4688 or Sysmon 1 for psexec.exe and 4648 when alternate credentials are used.
How can you tell if PsExec was run from a computer?
Check the user's NTUSER.DAT for the Sysinternals PsExec EulaAccepted value, Prefetch for PSEXEC.EXE, Amcache, ShimCache and BAM for psexec.exe, and process creation or PowerShell history for the command line, which names the targets.
Does PsExec leave evidence if the logs were cleared?
Yes. Clearing the logs writes events 1102 and 104, and Prefetch files, the USN Journal, Amcache, ShimCache and the Sysinternals EULA registry key all record PsExec independently of the event logs.
How we wrote this
Drafted with AI from evidence in our own lab, with Laura Pompeu responsible for the article. The evidence comes from Halden Freight office intrusion (Windows, two hosts), built and investigated in our lab, so every example can be checked against real records.
Sources
- PsExec (Sysinternals), Microsoft
- MITRE ATT&CK S0029: PsExec, MITRE
- MITRE ATT&CK T1569.002: System Services: Service Execution, MITRE
- Advanced security audit policy events 4624, 4648, 4697, 5140, 5145, Microsoft
- SANS DFIR poster: Hunt Evil (lateral movement artifacts), SANS Institute
See it on your own evidence. Free for 7 days.
Tell us what you want to investigate. A person replies within one business day with the download and a trial licence.
Request a trial