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"]
  4maturity = "production"
  5updated_date = "2024/10/15"
  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]
 46language = "eql"
 47license = "Elastic License v2"
 48name = "Service Control Spawned via Script Interpreter"
 49note = """## Triage and analysis
 50
 51### Investigating Service Control Spawned via Script Interpreter
 52
 53Windows services are background processes that run with SYSTEM privileges and provide specific functionality or support to other applications and system components.
 54
 55The `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.
 56
 57> **Note**:
 58> 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.
 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- Examine the command line, registry changes events, and Windows events related to service activities (for example, 4697 and/or 7045) for suspicious characteristics.
 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
 74### False positive analysis
 75
 76- 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.
 77
 78### Response and remediation
 79
 80- Initiate the incident response process based on the outcome of the triage.
 81- Isolate the involved host to prevent further post-compromise behavior.
 82- 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.
 83- Delete the service or restore it to the original configuration.
 84- Run a full antimalware scan. This may reveal additional artifacts left in the system, persistence mechanisms, and malware components.
 85- Determine the initial vector abused by the attacker and take action to prevent reinfection through the same vector.
 86- 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).
 87"""
 88references = ["https://www.elastic.co/security-labs/invisible-miners-unveiling-ghostengine"]
 89risk_score = 21
 90rule_id = "e8571d5f-bea1-46c2-9f56-998de2d3ed95"
 91severity = "low"
 92tags = [
 93    "Domain: Endpoint",
 94    "OS: Windows",
 95    "Use Case: Threat Detection",
 96    "Tactic: Privilege Escalation",
 97    "Tactic: Defense Evasion",
 98    "Tactic: Execution",
 99    "Data Source: Elastic Endgame",
100    "Resources: Investigation Guide",
101    "Data Source: Elastic Defend",
102    "Data Source: System",
103    "Data Source: Microsoft Defender for Endpoint",
104]
105timestamp_override = "event.ingested"
106type = "eql"
107
108query = '''
109/* This rule is not compatible with Sysmon due to user.id issues */
110
111process where host.os.type == "windows" and event.type == "start" and
112  (process.name : "sc.exe" or ?process.pe.original_file_name == "sc.exe") and
113  process.parent.name : ("cmd.exe", "wscript.exe", "rundll32.exe", "regsvr32.exe",
114                         "wmic.exe", "mshta.exe","powershell.exe", "pwsh.exe") and
115  process.args:("config", "create", "start", "delete", "stop", "pause") and
116  /* exclude SYSTEM SID - look for service creations by non-SYSTEM user */
117  not user.id : "S-1-5-18"
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 = "TA0004"
136name = "Privilege Escalation"
137reference = "https://attack.mitre.org/tactics/TA0004/"
138[[rule.threat]]
139framework = "MITRE ATT&CK"
140[[rule.threat.technique]]
141id = "T1047"
142name = "Windows Management Instrumentation"
143reference = "https://attack.mitre.org/techniques/T1047/"
144
145[[rule.threat.technique]]
146id = "T1059"
147name = "Command and Scripting Interpreter"
148reference = "https://attack.mitre.org/techniques/T1059/"
149[[rule.threat.technique.subtechnique]]
150id = "T1059.001"
151name = "PowerShell"
152reference = "https://attack.mitre.org/techniques/T1059/001/"
153
154[[rule.threat.technique.subtechnique]]
155id = "T1059.003"
156name = "Windows Command Shell"
157reference = "https://attack.mitre.org/techniques/T1059/003/"
158
159[[rule.threat.technique.subtechnique]]
160id = "T1059.005"
161name = "Visual Basic"
162reference = "https://attack.mitre.org/techniques/T1059/005/"
163
164
165
166[rule.threat.tactic]
167id = "TA0002"
168name = "Execution"
169reference = "https://attack.mitre.org/tactics/TA0002/"
170[[rule.threat]]
171framework = "MITRE ATT&CK"
172[[rule.threat.technique]]
173id = "T1218"
174name = "System Binary Proxy Execution"
175reference = "https://attack.mitre.org/techniques/T1218/"
176[[rule.threat.technique.subtechnique]]
177id = "T1218.010"
178name = "Regsvr32"
179reference = "https://attack.mitre.org/techniques/T1218/010/"
180
181[[rule.threat.technique.subtechnique]]
182id = "T1218.011"
183name = "Rundll32"
184reference = "https://attack.mitre.org/techniques/T1218/011/"
185
186
187
188[rule.threat.tactic]
189id = "TA0005"
190name = "Defense Evasion"
191reference = "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.
  • 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

to-top