Event ID 7045
Event ID 7045: New Service Installed (System)
A service was installed in the system
- Log source
- System
- How to enable it
- On by default. Written by the Service Control Manager to the System log
- Category
- Persistence
- Priority
- High
- Typical volume
- Low
- MITRE ATT&CK
-
- T1543.003 Create or Modify System Process: Windows Service
- T1569.002 System Services: Service Execution
- T1021.002 Remote Services: SMB/Windows Admin Shares
- T1685 Disable or Modify Tools
T1685 replaces T1562, T1562.001, T1562.006, which older guides still use.
What Event ID 7045 means
7045 is written by the Service Control Manager to the System log whenever a service is created. It needs no audit policy, which makes it available on nearly every Windows computer you will ever investigate, including ones that nobody prepared.
The System log is also smaller and quieter than the Security log, so events survive for months instead of hours. Intruders who clear Security often forget System, and on many hosts 7045 is the oldest surviving evidence of the intrusion.
ImagePath is the field that matters. A legitimate service points to a signed program in Program Files or System32. Anything with a shell, an encoded command, a loopback share or a random name in the Windows folder deserves an immediate look.
Key fields to inspect
| Field | Meaning | Suspicious when |
|---|---|---|
ServiceName | Name of the service. | PSEXESVC, a random name of 7 to 16 letters, or BTOBTO (smbexec's historic default). |
ImagePath | Program and arguments. | %COMSPEC% /Q /c, \\127.0.0.1\ADMIN$, powershell with -enc, or an .exe directly in C:\Windows. |
ServiceType | Kind of service, in words and in the system's language. | kernel mode driver from a user or temporary folder. |
StartType | When it starts, in words. | demand start for a one-off service, auto start for persistence. |
AccountName | Account it runs under. Empty for drivers. | LocalSystem for an unfamiliar program. |
Service patterns left by common tools
| Tool | What ImagePath or ServiceName looks like | Note |
|---|---|---|
Sysinternals PsExec | PSEXESVC, %SystemRoot%\PSEXESVC.exe | The name can be changed with -r |
Impacket psexec | Random 4-letter name, random 8-letter .exe in C:\Windows | Copied over ADMIN$ |
Impacket smbexec | %COMSPEC% /Q /c echo ... > \\127.0.0.1\C$\__output | One service per command |
Cobalt Strike jump psexec | 7 random characters, \\host\ADMIN$\name.exe | Configurable |
Cobalt Strike psexec_psh | %COMSPEC% /b /c start /b /min powershell -nop -w hidden -encodedcommand | No file on disk |
Detection queries
Find services with a shell, a share, an encoded command or a random program in the Windows folder. Adjust names and thresholds to your environment. About these queries.
Splunk SPL
index=windows source="XmlWinEventLog:System" EventCode=7045
| regex ImagePath="(?i)(comspec|cmd(\.exe)?\s+/|powershell|ADMIN\$|127\.0\.0\.1|\\\\Temp\\\\|\\\\Users\\\\|^(%systemroot%|C:\\\\Windows)\\\\[A-Za-z]{6,12}\.exe$)"
| table _time Computer ServiceName ImagePath ServiceType StartType AccountName Microsoft Sentinel KQL
Event
| where EventLog == "System" and EventID == 7045
| extend ServiceName = extract(@'Name="ServiceName">([^<]*)<', 1, EventData)
| extend ImagePath = extract(@'Name="ImagePath">([^<]*)<', 1, EventData)
| extend AccountName = extract(@'Name="AccountName">([^<]*)<', 1, EventData)
| where ImagePath matches regex @"(?i)(comspec|cmd(\.exe)?\s+/|powershell|ADMIN\$|127\.0\.0\.1|\\Temp\\|\\Users\\)"
| project TimeGenerated, Computer, ServiceName, ImagePath, AccountName PowerShell
Get-WinEvent -FilterHashtable @{ LogName = 'System'; Id = 7045; StartTime = (Get-Date).AddDays(-90) } |
ForEach-Object { $d = @{ Time = $_.TimeCreated }; ([xml]$_.ToXml()).Event.EventData.Data | ForEach-Object { $d[$_.Name] = $_.'#text' }; [pscustomobject]$d } |
Select-Object Time, ServiceName, ImagePath, StartType, AccountName | Format-List Attack scenarios
Lateral movement with PsExec and its relatives
The attacker copies a program to ADMIN$, creates a service and starts it. 7045 appears on the target, with 7036 for the start and stop, and the service is often removed a moment later.
Privilege escalation with named pipes
The getsystem technique creates a service such as cmd.exe /c echo x > \\.\pipe\x to make SYSTEM connect to a pipe. The path gives it away immediately.
Vulnerable driver
A kernel mode driver with an unfamiliar name is installed from a temporary folder minutes before protection stops working.
Investigation checklist
- Copy the program in ImagePath before it is removed, and hash it.
- Find the type 3 logon (4624) and 4672 in the preceding seconds.
- Decode any encoded PowerShell in the path.
- Search the System log of every host for the same name or path.
- If a driver is involved, check it against the Microsoft vulnerable driver blocklist.
Common benign causes
- Software and driver installation and updates.
- Approved administration with PsExec, which is worth replacing.
- Agents that reinstall their driver at each update.
Event ID 7045 FAQ
Does event 7045 show who installed the service?
The event data has no subject account. The Security element of the event header may contain the SID of the caller. Event 4697 in the Security log has the account and logon session if its audit subcategory is enabled.
How do I detect PsExec with event 7045?
Look for PSEXESVC in ServiceName or ImagePath. Since the name can be changed, also look for any new demand-start service that runs a program directly from C:\Windows, with a network logon seconds before.
Why is 7045 useful when the Security log was cleared?
It is stored in the System log, which is a separate file and is often left alone. If that was cleared too, event 104 records the action.