System Shells via Services
Windows services typically run as SYSTEM and can be used as a privilege escalation opportunity. Malware or penetration testers may run a shell as a service to gain SYSTEM permissions.
Elastic rule (View on GitHub)
1[metadata]
2creation_date = "2020/02/18"
3integration = ["endpoint", "windows", "system", "sentinel_one_cloud_funnel", "m365_defender", "crowdstrike"]
4maturity = "production"
5updated_date = "2026/09/18"
6[transform]
7[[transform.osquery]]
8label = "Osquery - Retrieve All Services"
9query = "SELECT description, display_name, name, path, pid, service_type, start_type, status, user_account FROM services"
10
11[[transform.osquery]]
12label = "Osquery - Retrieve Services Running on User Accounts"
13query = """
14SELECT description, display_name, name, path, pid, service_type, start_type, status, user_account FROM services WHERE
15NOT (user_account LIKE '%LocalSystem' OR user_account LIKE '%LocalService' OR user_account LIKE '%NetworkService' OR
16user_account == null)
17"""
18
19[[transform.osquery]]
20label = "Osquery - Retrieve Service Unsigned Executables with Virustotal Link"
21query = """
22SELECT concat('https://www.virustotal.com/gui/file/', sha1) AS VtLink, name, description, start_type, status, pid,
23services.path FROM services JOIN authenticode ON services.path = authenticode.path OR services.module_path =
24authenticode.path JOIN hash ON services.path = hash.path WHERE authenticode.result != 'trusted'
25"""
26
27
28[rule]
29author = ["Elastic"]
30description = """
31Windows services typically run as SYSTEM and can be used as a privilege escalation opportunity. Malware or penetration
32testers may run a shell as a service to gain SYSTEM permissions.
33"""
34from = "now-9m"
35index = [
36 "endgame-*",
37 "logs-crowdstrike.fdr*",
38 "logs-endpoint.events.process-*",
39 "logs-m365_defender.event-*",
40 "logs-sentinel_one_cloud_funnel.*",
41 "logs-system.security*",
42 "logs-windows.forwarded*",
43 "logs-windows.sysmon_operational-*",
44 "winlogbeat-*",
45]
46language = "eql"
47license = "Elastic License v2"
48name = "System Shells via Services"
49note = """## Triage and analysis
50
51### Investigating System Shells via Services
52
53Attackers may configure existing services or create new ones to execute system shells to elevate their privileges from administrator to SYSTEM. They can also configure services to execute these shells with persistence payloads.
54
55This rule looks for system shells being spawned by `services.exe`, which is compatible with the above behavior.
56
57> **Note**:
58> This investigation guide uses the [Osquery Markdown Plugin](https://www.elastic.co/guide/en/security/current/invest-guide-run-osquery.html) introduced in Elastic Stack version 8.5.0. Older Elastic Stack versions will display unrendered Markdown in this guide.
59
60#### Possible investigation steps
61
62- Investigate the process execution chain (parent process tree) for unknown processes. Examine their executable files for prevalence, whether they are located in expected locations, and if they are signed with valid digital signatures.
63- Identify how the service was created or modified. Look for registry changes events or Windows events related to service activities (for example, 4697 and/or 7045).
64 - Examine the created and existent services, the executables or drivers referenced, and command line arguments for suspicious entries.
65 - $osquery_0
66 - $osquery_1
67 - $osquery_2
68 - Retrieve the referenced files' SHA-256 hash values using the PowerShell `Get-FileHash` cmdlet and search for the existence and reputation of the hashes in resources like VirusTotal, Hybrid-Analysis, CISCO Talos, Any.run, etc.
69- Identify the user account that performed the action and whether it should perform this kind of action.
70- Contact the account owner and confirm whether they are aware of this activity.
71- Investigate other alerts associated with the user/host during the past 48 hours.
72- Assess whether this behavior is prevalent in the environment by looking for similar occurrences across hosts.
73- Check for commands executed under the spawned shell.
74
75### False positive analysis
76
77- This activity should not happen legitimately. The security team should address any potential benign true positive (B-TP), as this configuration can put the user and the domain at risk.
78
79### Response and remediation
80
81- Initiate the incident response process based on the outcome of the triage.
82- Isolate the involved host to prevent further post-compromise behavior.
83- Investigate credential exposure on systems compromised or used by the attacker to ensure all compromised accounts are identified. Reset passwords for these accounts and other potentially compromised credentials, such as email, business systems, and web services.
84- Delete the service or restore it to the original configuration.
85- Run a full antimalware scan. This may reveal additional artifacts left in the system, persistence mechanisms, and malware components.
86- Determine the initial vector abused by the attacker and take action to prevent reinfection through the same vector.
87- Using the incident response data, update logging and audit policies to improve the mean time to detect (MTTD) and the mean time to respond (MTTR).
88"""
89
90setup = """## Setup
91
92This rule is designed for data generated by [Elastic Defend](https://www.elastic.co/security/endpoint-security), which provides native endpoint detection and response, along with event enrichments designed to work with our detection rules.
93
94Setup instructions: https://ela.st/install-elastic-defend
95
96### Additional data sources
97
98This rule also supports the following third-party data sources. For setup instructions, refer to the links below:
99
100- [CrowdStrike](https://ela.st/crowdstrike-integration)
101- [Microsoft Defender XDR](https://ela.st/m365-defender)
102- [SentinelOne Cloud Funnel](https://ela.st/sentinel-one-cloud-funnel)
103- [Sysmon Event ID 1 - Process Creation](https://ela.st/sysmon-event-1-setup)
104- [Windows Process Creation Logs](https://ela.st/audit-process-creation)
105"""
106
107risk_score = 47
108rule_id = "0022d47d-39c7-4f69-a232-4fe9dc7a3acd"
109severity = "medium"
110tags = [
111 "Domain: Endpoint",
112 "OS: Windows",
113 "Use Case: Threat Detection",
114 "Tactic: Persistence",
115 "Tactic: Execution",
116 "Resources: Investigation Guide",
117 "Data Source: Elastic Endgame",
118 "Data Source: Elastic Defend",
119 "Data Source: SentinelOne",
120 "Data Source: Microsoft Defender XDR",
121 "Data Source: Windows Security Event Logs",
122 "Data Source: Crowdstrike",
123 "Data Source: Sysmon",
124 "Noise: High",
125 "Performance: Normal",
126 "Profile: Aggressive",
127 "Rule Type: Event Correlation (EQL)",
128 "Platform: Windows",
129 "Resources: Osquery",
130]
131timestamp_override = "event.ingested"
132type = "eql"
133
134query = '''
135process where host.os.type == "windows" and event.type == "start" and
136 process.parent.name : "services.exe" and
137 process.name : ("cmd.exe", "powershell.exe", "pwsh.exe", "powershell_ise.exe") and
138
139 /* Third party FP's */
140 not process.args : "NVDisplay.ContainerLocalSystem"
141'''
142
143
144[[rule.threat]]
145framework = "MITRE ATT&CK"
146
147[[rule.threat.technique]]
148id = "T1543"
149name = "Create or Modify System Process"
150reference = "https://attack.mitre.org/techniques/T1543/"
151
152[[rule.threat.technique.subtechnique]]
153id = "T1543.003"
154name = "Windows Service"
155reference = "https://attack.mitre.org/techniques/T1543/003/"
156
157[rule.threat.tactic]
158id = "TA0003"
159name = "Persistence"
160reference = "https://attack.mitre.org/tactics/TA0003/"
161
162[[rule.threat]]
163framework = "MITRE ATT&CK"
164
165[[rule.threat.technique]]
166id = "T1059"
167name = "Command and Scripting Interpreter"
168reference = "https://attack.mitre.org/techniques/T1059/"
169
170[[rule.threat.technique.subtechnique]]
171id = "T1059.001"
172name = "PowerShell"
173reference = "https://attack.mitre.org/techniques/T1059/001/"
174
175[[rule.threat.technique.subtechnique]]
176id = "T1059.003"
177name = "Windows Command Shell"
178reference = "https://attack.mitre.org/techniques/T1059/003/"
179
180[[rule.threat.technique]]
181id = "T1569"
182name = "System Services"
183reference = "https://attack.mitre.org/techniques/T1569/"
184
185[[rule.threat.technique.subtechnique]]
186id = "T1569.002"
187name = "Service Execution"
188reference = "https://attack.mitre.org/techniques/T1569/002/"
189
190[rule.threat.tactic]
191id = "TA0002"
192name = "Execution"
193reference = "https://attack.mitre.org/tactics/TA0002/"
Triage and analysis
Investigating System Shells via Services
Attackers may configure existing services or create new ones to execute system shells to elevate their privileges from administrator to SYSTEM. They can also configure services to execute these shells with persistence payloads.
This rule looks for system shells being spawned by services.exe, which is compatible with the above behavior.
Note: This investigation guide uses the Osquery Markdown Plugin introduced in Elastic Stack version 8.5.0. Older Elastic Stack versions will display unrendered Markdown in this guide.
Possible investigation steps
- Investigate the process execution chain (parent process tree) for unknown processes. Examine their executable files for prevalence, whether they are located in expected locations, and if they are signed with valid digital signatures.
- Identify how the service was created or modified. Look for registry changes events or Windows events related to service activities (for example, 4697 and/or 7045).
- Examine the created and existent services, the executables or drivers referenced, and command line arguments for suspicious entries.
- $osquery_0
- $osquery_1
- $osquery_2
- Retrieve the referenced files' SHA-256 hash values using the PowerShell
Get-FileHashcmdlet and search for the existence and reputation of the hashes in resources like VirusTotal, Hybrid-Analysis, CISCO Talos, Any.run, etc.
- Examine the created and existent services, the executables or drivers referenced, and command line arguments for suspicious entries.
- Identify the user account that performed the action and whether it should perform this kind of action.
- Contact the account owner and confirm whether they are aware of this activity.
- Investigate other alerts associated with the user/host during the past 48 hours.
- Assess whether this behavior is prevalent in the environment by looking for similar occurrences across hosts.
- Check for commands executed under the spawned shell.
False positive analysis
- This activity should not happen legitimately. The security team should address any potential benign true positive (B-TP), as this configuration can put the user and the domain at risk.
Response and remediation
- Initiate the incident response process based on the outcome of the triage.
- Isolate the involved host to prevent further post-compromise behavior.
- Investigate credential exposure on systems compromised or used by the attacker to ensure all compromised accounts are identified. Reset passwords for these accounts and other potentially compromised credentials, such as email, business systems, and web services.
- Delete the service or restore it to the original configuration.
- Run a full antimalware scan. This may reveal additional artifacts left in the system, persistence mechanisms, and malware components.
- Determine the initial vector abused by the attacker and take action to prevent reinfection through the same vector.
- Using the incident response data, update logging and audit policies to improve the mean time to detect (MTTD) and the mean time to respond (MTTR).
Related rules
- Disabling Windows Defender Security Settings via PowerShell
- Enumeration Command Spawned via WMIPrvSE
- Execution via GitHub Actions Runner
- Suspicious CertUtil Commands
- Suspicious Cmd Execution via WMI