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/05/04"
  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"""
 90
 91setup = """## Setup
 92
 93This 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.
 94
 95Setup instructions: https://ela.st/install-elastic-defend
 96
 97### Additional data sources
 98
 99This rule also supports the following third-party data sources. For setup instructions, refer to the links below:
100
101- [CrowdStrike](https://ela.st/crowdstrike-integration)
102- [Microsoft Defender XDR](https://ela.st/m365-defender)
103- [SentinelOne Cloud Funnel](https://ela.st/sentinel-one-cloud-funnel)
104- [Sysmon Event ID 1 - Process Creation](https://ela.st/sysmon-event-1-setup)
105- [Windows Process Creation Logs](https://ela.st/audit-process-creation)
106"""
107
108risk_score = 47
109rule_id = "0022d47d-39c7-4f69-a232-4fe9dc7a3acd"
110severity = "medium"
111tags = [
112    "Domain: Endpoint",
113    "OS: Windows",
114    "Use Case: Threat Detection",
115    "Tactic: Persistence",
116    "Tactic: Execution",
117    "Resources: Investigation Guide",
118    "Data Source: Elastic Endgame",
119    "Data Source: Elastic Defend",
120    "Data Source: SentinelOne",
121    "Data Source: Microsoft Defender XDR",
122    "Data Source: Windows Security Event Logs",
123    "Data Source: Crowdstrike",
124    "Data Source: Sysmon",
125]
126timestamp_override = "event.ingested"
127type = "eql"
128
129query = '''
130process where host.os.type == "windows" and event.type == "start" and
131  process.parent.name : "services.exe" and
132  process.name : ("cmd.exe", "powershell.exe", "pwsh.exe", "powershell_ise.exe") and
133
134  /* Third party FP's */
135  not process.args : "NVDisplay.ContainerLocalSystem"
136'''
137
138
139[[rule.threat]]
140framework = "MITRE ATT&CK"
141
142[[rule.threat.technique]]
143id = "T1543"
144name = "Create or Modify System Process"
145reference = "https://attack.mitre.org/techniques/T1543/"
146
147[[rule.threat.technique.subtechnique]]
148id = "T1543.003"
149name = "Windows Service"
150reference = "https://attack.mitre.org/techniques/T1543/003/"
151
152[rule.threat.tactic]
153id = "TA0003"
154name = "Persistence"
155reference = "https://attack.mitre.org/tactics/TA0003/"
156
157[[rule.threat]]
158framework = "MITRE ATT&CK"
159
160[[rule.threat.technique]]
161id = "T1059"
162name = "Command and Scripting Interpreter"
163reference = "https://attack.mitre.org/techniques/T1059/"
164
165[[rule.threat.technique.subtechnique]]
166id = "T1059.001"
167name = "PowerShell"
168reference = "https://attack.mitre.org/techniques/T1059/001/"
169
170[[rule.threat.technique.subtechnique]]
171id = "T1059.003"
172name = "Windows Command Shell"
173reference = "https://attack.mitre.org/techniques/T1059/003/"
174
175[[rule.threat.technique]]
176id = "T1569"
177name = "System Services"
178reference = "https://attack.mitre.org/techniques/T1569/"
179
180[[rule.threat.technique.subtechnique]]
181id = "T1569.002"
182name = "Service Execution"
183reference = "https://attack.mitre.org/techniques/T1569/002/"
184
185[rule.threat.tactic]
186id = "TA0002"
187name = "Execution"
188reference = "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-FileHash cmdlet and search for the existence and reputation of the hashes in resources like VirusTotal, Hybrid-Analysis, CISCO Talos, Any.run, etc.
  • 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

to-top