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 = "2025/03/20"
6
7[transform]
8[[transform.osquery]]
9label = "Osquery - Retrieve All Services"
10query = "SELECT description, display_name, name, path, pid, service_type, start_type, status, user_account FROM services"
11
12[[transform.osquery]]
13label = "Osquery - Retrieve Services Running on User Accounts"
14query = """
15SELECT description, display_name, name, path, pid, service_type, start_type, status, user_account FROM services WHERE
16NOT (user_account LIKE '%LocalSystem' OR user_account LIKE '%LocalService' OR user_account LIKE '%NetworkService' OR
17user_account == null)
18"""
19
20[[transform.osquery]]
21label = "Osquery - Retrieve Service Unsigned Executables with Virustotal Link"
22query = """
23SELECT concat('https://www.virustotal.com/gui/file/', sha1) AS VtLink, name, description, start_type, status, pid,
24services.path FROM services JOIN authenticode ON services.path = authenticode.path OR services.module_path =
25authenticode.path JOIN hash ON services.path = hash.path WHERE authenticode.result != 'trusted'
26"""
27
28
29[rule]
30author = ["Elastic"]
31description = """
32Windows services typically run as SYSTEM and can be used as a privilege escalation opportunity. Malware or penetration
33testers may run a shell as a service to gain SYSTEM permissions.
34"""
35from = "now-9m"
36index = [
37 "endgame-*",
38 "logs-crowdstrike.fdr*",
39 "logs-endpoint.events.process-*",
40 "logs-m365_defender.event-*",
41 "logs-sentinel_one_cloud_funnel.*",
42 "logs-system.security*",
43 "logs-windows.forwarded*",
44 "logs-windows.sysmon_operational-*",
45 "winlogbeat-*",
46]
47language = "eql"
48license = "Elastic License v2"
49name = "System Shells via Services"
50note = """## Triage and analysis
51
52### Investigating System Shells via Services
53
54Attackers 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.
55
56This rule looks for system shells being spawned by `services.exe`, which is compatible with the above behavior.
57
58> **Note**:
59> 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.
60
61#### Possible investigation steps
62
63- 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.
64- 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).
65 - Examine the created and existent services, the executables or drivers referenced, and command line arguments for suspicious entries.
66 - $osquery_0
67 - $osquery_1
68 - $osquery_2
69 - 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.
70- Identify the user account that performed the action and whether it should perform this kind of action.
71- Contact the account owner and confirm whether they are aware of this activity.
72- Investigate other alerts associated with the user/host during the past 48 hours.
73- Assess whether this behavior is prevalent in the environment by looking for similar occurrences across hosts.
74- Check for commands executed under the spawned shell.
75
76### False positive analysis
77
78- 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.
79
80### Response and remediation
81
82- Initiate the incident response process based on the outcome of the triage.
83- Isolate the involved host to prevent further post-compromise behavior.
84- 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.
85- Delete the service or restore it to the original configuration.
86- Run a full antimalware scan. This may reveal additional artifacts left in the system, persistence mechanisms, and malware components.
87- Determine the initial vector abused by the attacker and take action to prevent reinfection through the same vector.
88- 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).
89"""
90risk_score = 47
91rule_id = "0022d47d-39c7-4f69-a232-4fe9dc7a3acd"
92severity = "medium"
93tags = [
94 "Domain: Endpoint",
95 "OS: Windows",
96 "Use Case: Threat Detection",
97 "Tactic: Persistence",
98 "Tactic: Execution",
99 "Resources: Investigation Guide",
100 "Data Source: Elastic Endgame",
101 "Data Source: Elastic Defend",
102 "Data Source: SentinelOne",
103 "Data Source: Microsoft Defender for Endpoint",
104 "Data Source: Windows Security Event Logs",
105 "Data Source: Crowdstrike",
106 "Data Source: Sysmon",
107]
108timestamp_override = "event.ingested"
109type = "eql"
110
111query = '''
112process where host.os.type == "windows" and event.type == "start" and
113 process.parent.name : "services.exe" and
114 process.name : ("cmd.exe", "powershell.exe", "pwsh.exe", "powershell_ise.exe") and
115
116 /* Third party FP's */
117 not process.args : "NVDisplay.ContainerLocalSystem"
118'''
119
120
121[[rule.threat]]
122framework = "MITRE ATT&CK"
123[[rule.threat.technique]]
124id = "T1543"
125name = "Create or Modify System Process"
126reference = "https://attack.mitre.org/techniques/T1543/"
127[[rule.threat.technique.subtechnique]]
128id = "T1543.003"
129name = "Windows Service"
130reference = "https://attack.mitre.org/techniques/T1543/003/"
131
132
133
134[rule.threat.tactic]
135id = "TA0003"
136name = "Persistence"
137reference = "https://attack.mitre.org/tactics/TA0003/"
138[[rule.threat]]
139framework = "MITRE ATT&CK"
140[[rule.threat.technique]]
141id = "T1059"
142name = "Command and Scripting Interpreter"
143reference = "https://attack.mitre.org/techniques/T1059/"
144[[rule.threat.technique.subtechnique]]
145id = "T1059.001"
146name = "PowerShell"
147reference = "https://attack.mitre.org/techniques/T1059/001/"
148
149[[rule.threat.technique.subtechnique]]
150id = "T1059.003"
151name = "Windows Command Shell"
152reference = "https://attack.mitre.org/techniques/T1059/003/"
153
154
155
156[rule.threat.tactic]
157id = "TA0002"
158name = "Execution"
159reference = "https://attack.mitre.org/tactics/TA0002/"
toml
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-FileHash
cmdlet 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
- New ActiveSyncAllowedDeviceID Added via PowerShell
- Persistence via WMI Event Subscription
- Web Shell Detection: Script Process Child of Common Web Processes
- Adding Hidden File Attribute via Attrib
- Clearing Windows Console History