Service Execution
Adversaries may abuse the Windows service control manager to execute malicious commands or payloads. The Windows service control manager (services.exe) is an interface to manage and manipulate services. Adversaries can create new services or modify existing ones to execute malicious binaries, scripts, or commands. Tools such as sc.exe, PsExec, and Net can be used locally or against remote targets. PsExec creates a temporary service (PSEXESVC) that executes the specified payload as SYSTEM. This technique is commonly used by ransomware families (NotPetya, Bad Rabbit, Ragnar Locker), APT groups (Chimera, APT39), and C2 frameworks (Cobalt Strike, Brute Ratel C4) for lateral movement, privilege escalation, and persistence.
// Detection 1: New service created with suspicious binary path
let SuspiciousPaths = dynamic([
"\\Temp\\", "\\tmp\\", "\\Users\\Public\\", "\\AppData\\Local\\Temp\\",
"\\Downloads\\", "\\Desktop\\", "\\ProgramData\\"
]);
let SuspiciousBinaries = dynamic([
"cmd.exe", "powershell.exe", "pwsh.exe", "mshta.exe", "wscript.exe",
"cscript.exe", "rundll32.exe", "regsvr32.exe", "certutil.exe",
"bitsadmin.exe", "msbuild.exe", "wmic.exe"
]);
// Service installation events via Security log (Event ID 4697) or System log (Event ID 7045)
SecurityEvent
| where TimeGenerated > ago(24h)
| where EventID == 4697
| extend ServiceName = tostring(EventData.ServiceName)
| extend ServiceFileName = tostring(EventData.ServiceFileName)
| extend ServiceAccountName = tostring(EventData.ServiceAccount)
| extend SubjectUserName = tostring(EventData.SubjectUserName)
| extend SubjectDomainName = tostring(EventData.SubjectDomainName)
| where ServiceFileName has_any (SuspiciousPaths)
or ServiceFileName has_any (SuspiciousBinaries)
or ServiceFileName matches regex @"\\[a-z0-9]{8,16}\.exe"
or ServiceName matches regex @"^[a-z0-9]{6,12}$"
| project TimeGenerated, Computer, EventID, ServiceName, ServiceFileName, ServiceAccountName, SubjectUserName, SubjectDomainName
| union (
// Detection 2: sc.exe or PsExec creating or starting services
DeviceProcessEvents
| where Timestamp > ago(24h)
| where FileName =~ "sc.exe"
| where ProcessCommandLine has_any ("create", "start", "config", "binpath")
| where ProcessCommandLine has_any (SuspiciousPaths)
or ProcessCommandLine has_any (SuspiciousBinaries)
or ProcessCommandLine has_any ("cmd /c", "cmd.exe /c", "powershell", "\\\\\\\\")
| project TimeGenerated=Timestamp, Computer=DeviceName, EventID=int(null),
ServiceName=tostring(split(ProcessCommandLine, " ")[2]),
ServiceFileName=ProcessCommandLine,
ServiceAccountName="",
SubjectUserName=AccountName,
SubjectDomainName=AccountDomain
)
| union (
// Detection 3: PsExec service signature (PSEXESVC)
DeviceProcessEvents
| where Timestamp > ago(24h)
| where FileName =~ "PSEXESVC.exe"
or ProcessCommandLine has "psexec"
or InitiatingProcessFileName =~ "PsExec.exe"
or InitiatingProcessFileName =~ "PsExec64.exe"
| project TimeGenerated=Timestamp, Computer=DeviceName, EventID=int(null),
ServiceName="PSEXESVC",
ServiceFileName=ProcessCommandLine,
ServiceAccountName="SYSTEM",
SubjectUserName=AccountName,
SubjectDomainName=AccountDomain
)
| sort by TimeGenerated desc Data Sources
Required Tables
False Positives
- Legitimate software installers (antivirus, monitoring agents, backup solutions) that register Windows services during installation
- IT administrative tools (PsExec used by sysadmins for remote management, SCCM/Intune deploying service-based software)
- Security software and EDR agents that create services for kernel drivers or protection modules
- Legitimate automation frameworks (Ansible, Chef, Puppet) that deploy services as part of configuration management
- Application deployment pipelines in CI/CD environments creating temporary services for testing
References (10)
- https://attack.mitre.org/techniques/T1569/002/
- https://docs.microsoft.com/windows/win32/services/service-control-manager
- https://technet.microsoft.com/en-us/sysinternals/bb897553.aspx
- https://github.com/redcanaryco/atomic-red-team/blob/master/atomics/T1569.002/T1569.002.md
- https://www.trellix.com/en-us/about/newsroom/stories/research/darkgate-opens-organizations-to-attack.html
- https://www.talos-intelligence.com/blog/nyetya-potentially-devastating-wiper-masquerading-ransomware
- https://www.sophos.com/en-us/threat-center/threat-analyses/active-adversary-playbook-2021
- https://research.nccgroup.com/2021/01/12/abused-legitimate-remote-administration-tools-in-targeted-intrusions/
- https://github.com/SigmaHQ/sigma/blob/master/rules/windows/builtin/security/win_security_service_installation.yml
- https://learn.microsoft.com/en-us/defender-endpoint/advanced-hunting-deviceprocessevents-table
Unlock Pro Content
Get the full detection package for T1569.002 including response playbook, investigation guide, and atomic red team tests.