Service Control Spawned via Script Interpreter
Identifies Service Control (sc.exe) spawning from script interpreter processes to create, modify, or start services. This can potentially indicate an attempt to elevate privileges or maintain persistence.
Elastic rule (View on GitHub)
1[metadata]
2creation_date = "2020/02/18"
3integration = ["endpoint", "system", "windows", "m365_defender", "crowdstrike"]
4maturity = "production"
5updated_date = "2024/11/02"
6min_stack_version = "8.14.0"
7min_stack_comments = "Breaking change at 8.14.0 for the Windows Integration."
8
9[transform]
10[[transform.osquery]]
11label = "Osquery - Retrieve All Services"
12query = "SELECT description, display_name, name, path, pid, service_type, start_type, status, user_account FROM services"
13
14[[transform.osquery]]
15label = "Osquery - Retrieve Services Running on User Accounts"
16query = """
17SELECT description, display_name, name, path, pid, service_type, start_type, status, user_account FROM services WHERE
18NOT (user_account LIKE '%LocalSystem' OR user_account LIKE '%LocalService' OR user_account LIKE '%NetworkService' OR
19user_account == null)
20"""
21
22[[transform.osquery]]
23label = "Osquery - Retrieve Service Unsigned Executables with Virustotal Link"
24query = """
25SELECT concat('https://www.virustotal.com/gui/file/', sha1) AS VtLink, name, description, start_type, status, pid,
26services.path FROM services JOIN authenticode ON services.path = authenticode.path OR services.module_path =
27authenticode.path JOIN hash ON services.path = hash.path WHERE authenticode.result != 'trusted'
28"""
29
30
31[rule]
32author = ["Elastic"]
33description = """
34Identifies Service Control (sc.exe) spawning from script interpreter processes to create, modify, or start services.
35This can potentially indicate an attempt to elevate privileges or maintain persistence.
36"""
37from = "now-9m"
38index = [
39 "logs-endpoint.events.process-*",
40 "logs-system.security*",
41 "winlogbeat-*",
42 "logs-windows.forwarded*",
43 "endgame-*",
44 "logs-m365_defender.event-*",
45 "logs-crowdstrike.fdr*"
46]
47language = "eql"
48license = "Elastic License v2"
49name = "Service Control Spawned via Script Interpreter"
50note = """## Triage and analysis
51
52### Investigating Service Control Spawned via Script Interpreter
53
54Windows services are background processes that run with SYSTEM privileges and provide specific functionality or support to other applications and system components.
55
56The `sc.exe` command line utility is used to manage and control Windows services on a local or remote computer. Attackers may use `sc.exe` to create, modify, and start services to elevate their privileges from administrator to SYSTEM.
57
58> **Note**:
59> This investigation guide uses the [Osquery Markdown Plugin](https://www.elastic.co/guide/en/security/master/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- Examine the command line, registry changes events, and Windows events related to service activities (for example, 4697 and/or 7045) for suspicious characteristics.
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
75### False positive analysis
76
77- This activity is not inherently malicious if it occurs in isolation. As long as the analyst did not identify suspicious activity related to the user, host, and service, such alerts can be dismissed.
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"""
89references = ["https://www.elastic.co/security-labs/invisible-miners-unveiling-ghostengine"]
90risk_score = 21
91rule_id = "e8571d5f-bea1-46c2-9f56-998de2d3ed95"
92severity = "low"
93tags = [
94 "Domain: Endpoint",
95 "OS: Windows",
96 "Use Case: Threat Detection",
97 "Tactic: Privilege Escalation",
98 "Tactic: Defense Evasion",
99 "Tactic: Execution",
100 "Data Source: Elastic Endgame",
101 "Resources: Investigation Guide",
102 "Data Source: Elastic Defend",
103 "Data Source: System",
104 "Data Source: Microsoft Defender for Endpoint",
105 "Data Source: Crowdstrike",
106]
107timestamp_override = "event.ingested"
108type = "eql"
109
110query = '''
111/* This rule is not compatible with Sysmon due to user.id issues */
112
113process where host.os.type == "windows" and event.type == "start" and
114 (process.name : "sc.exe" or ?process.pe.original_file_name == "sc.exe") and
115 process.parent.name : ("cmd.exe", "wscript.exe", "rundll32.exe", "regsvr32.exe",
116 "wmic.exe", "mshta.exe","powershell.exe", "pwsh.exe") and
117 process.args:("config", "create", "start", "delete", "stop", "pause") and
118 /* exclude SYSTEM SID - look for service creations by non-SYSTEM user */
119 not user.id : "S-1-5-18"
120'''
121
122
123[[rule.threat]]
124framework = "MITRE ATT&CK"
125[[rule.threat.technique]]
126id = "T1543"
127name = "Create or Modify System Process"
128reference = "https://attack.mitre.org/techniques/T1543/"
129[[rule.threat.technique.subtechnique]]
130id = "T1543.003"
131name = "Windows Service"
132reference = "https://attack.mitre.org/techniques/T1543/003/"
133
134
135
136[rule.threat.tactic]
137id = "TA0004"
138name = "Privilege Escalation"
139reference = "https://attack.mitre.org/tactics/TA0004/"
140[[rule.threat]]
141framework = "MITRE ATT&CK"
142[[rule.threat.technique]]
143id = "T1047"
144name = "Windows Management Instrumentation"
145reference = "https://attack.mitre.org/techniques/T1047/"
146
147[[rule.threat.technique]]
148id = "T1059"
149name = "Command and Scripting Interpreter"
150reference = "https://attack.mitre.org/techniques/T1059/"
151[[rule.threat.technique.subtechnique]]
152id = "T1059.001"
153name = "PowerShell"
154reference = "https://attack.mitre.org/techniques/T1059/001/"
155
156[[rule.threat.technique.subtechnique]]
157id = "T1059.003"
158name = "Windows Command Shell"
159reference = "https://attack.mitre.org/techniques/T1059/003/"
160
161[[rule.threat.technique.subtechnique]]
162id = "T1059.005"
163name = "Visual Basic"
164reference = "https://attack.mitre.org/techniques/T1059/005/"
165
166
167
168[rule.threat.tactic]
169id = "TA0002"
170name = "Execution"
171reference = "https://attack.mitre.org/tactics/TA0002/"
172[[rule.threat]]
173framework = "MITRE ATT&CK"
174[[rule.threat.technique]]
175id = "T1218"
176name = "System Binary Proxy Execution"
177reference = "https://attack.mitre.org/techniques/T1218/"
178[[rule.threat.technique.subtechnique]]
179id = "T1218.010"
180name = "Regsvr32"
181reference = "https://attack.mitre.org/techniques/T1218/010/"
182
183[[rule.threat.technique.subtechnique]]
184id = "T1218.011"
185name = "Rundll32"
186reference = "https://attack.mitre.org/techniques/T1218/011/"
187
188
189
190[rule.threat.tactic]
191id = "TA0005"
192name = "Defense Evasion"
193reference = "https://attack.mitre.org/tactics/TA0005/"
Triage and analysis
Investigating Service Control Spawned via Script Interpreter
Windows services are background processes that run with SYSTEM privileges and provide specific functionality or support to other applications and system components.
The sc.exe
command line utility is used to manage and control Windows services on a local or remote computer. Attackers may use sc.exe
to create, modify, and start services to elevate their privileges from administrator to SYSTEM.
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.
- Examine the command line, registry changes events, and Windows events related to service activities (for example, 4697 and/or 7045) for suspicious characteristics.
- 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.
False positive analysis
- This activity is not inherently malicious if it occurs in isolation. As long as the analyst did not identify suspicious activity related to the user, host, and service, such alerts can be dismissed.
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).
References
Related rules
- Bypass UAC via Event Viewer
- UAC Bypass Attempt via Windows Directory Masquerading
- UAC Bypass via DiskCleanup Scheduled Task Hijack
- Suspicious MS Office Child Process
- Suspicious MS Outlook Child Process