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"]
  4maturity = "production"
  5updated_date = "2024/05/21"
  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 = """
 32Identifies Service Control (sc.exe) spawning from script interpreter processes to create, modify, or start services.
 33This can potentially indicate an attempt to elevate privileges or maintain persistence.
 34"""
 35from = "now-9m"
 36index = ["logs-endpoint.events.process-*", "logs-system.*", "winlogbeat-*", "logs-windows.*", "endgame-*"]
 37language = "eql"
 38license = "Elastic License v2"
 39name = "Service Control Spawned via Script Interpreter"
 40note = """## Triage and analysis
 41
 42### Investigating Service Control Spawned via Script Interpreter
 43
 44Windows services are background processes that run with SYSTEM privileges and provide specific functionality or support to other applications and system components.
 45
 46The `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.
 47
 48> **Note**:
 49> 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.
 50
 51#### Possible investigation steps
 52
 53- 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.
 54- Examine the command line, registry changes events, and Windows events related to service activities (for example, 4697 and/or 7045) for suspicious characteristics.
 55  - Examine the created and existent services, the executables or drivers referenced, and command line arguments for suspicious entries.
 56    - $osquery_0
 57    - $osquery_1
 58    - $osquery_2
 59  - 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.
 60- Identify the user account that performed the action and whether it should perform this kind of action.
 61- Contact the account owner and confirm whether they are aware of this activity.
 62- Investigate other alerts associated with the user/host during the past 48 hours.
 63- Assess whether this behavior is prevalent in the environment by looking for similar occurrences across hosts.
 64
 65### False positive analysis
 66
 67- 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.
 68
 69### Response and remediation
 70
 71- Initiate the incident response process based on the outcome of the triage.
 72- Isolate the involved host to prevent further post-compromise behavior.
 73- 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.
 74- Delete the service or restore it to the original configuration.
 75- Run a full antimalware scan. This may reveal additional artifacts left in the system, persistence mechanisms, and malware components.
 76- Determine the initial vector abused by the attacker and take action to prevent reinfection through the same vector.
 77- 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).
 78"""
 79risk_score = 21
 80rule_id = "e8571d5f-bea1-46c2-9f56-998de2d3ed95"
 81severity = "low"
 82tags = [
 83    "Domain: Endpoint",
 84    "OS: Windows",
 85    "Use Case: Threat Detection",
 86    "Tactic: Privilege Escalation",
 87    "Tactic: Defense Evasion",
 88    "Tactic: Execution",
 89    "Data Source: Elastic Endgame",
 90    "Resources: Investigation Guide",
 91    "Data Source: Elastic Defend",
 92]
 93timestamp_override = "event.ingested"
 94type = "eql"
 95
 96query = '''
 97/* This rule is not compatible with Sysmon due to user.id issues */
 98
 99process where host.os.type == "windows" and event.type == "start" and
100  (process.name : "sc.exe" or process.pe.original_file_name == "sc.exe") and
101  process.parent.name : ("cmd.exe", "wscript.exe", "rundll32.exe", "regsvr32.exe",
102                         "wmic.exe", "mshta.exe","powershell.exe", "pwsh.exe") and
103  process.args:("config", "create", "start", "delete", "stop", "pause") and
104  /* exclude SYSTEM SID - look for service creations by non-SYSTEM user */
105  not user.id : "S-1-5-18"
106'''
107
108
109[[rule.threat]]
110framework = "MITRE ATT&CK"
111[[rule.threat.technique]]
112id = "T1543"
113name = "Create or Modify System Process"
114reference = "https://attack.mitre.org/techniques/T1543/"
115[[rule.threat.technique.subtechnique]]
116id = "T1543.003"
117name = "Windows Service"
118reference = "https://attack.mitre.org/techniques/T1543/003/"
119
120
121
122[rule.threat.tactic]
123id = "TA0004"
124name = "Privilege Escalation"
125reference = "https://attack.mitre.org/tactics/TA0004/"
126[[rule.threat]]
127framework = "MITRE ATT&CK"
128[[rule.threat.technique]]
129id = "T1047"
130name = "Windows Management Instrumentation"
131reference = "https://attack.mitre.org/techniques/T1047/"
132
133[[rule.threat.technique]]
134id = "T1059"
135name = "Command and Scripting Interpreter"
136reference = "https://attack.mitre.org/techniques/T1059/"
137[[rule.threat.technique.subtechnique]]
138id = "T1059.001"
139name = "PowerShell"
140reference = "https://attack.mitre.org/techniques/T1059/001/"
141
142[[rule.threat.technique.subtechnique]]
143id = "T1059.003"
144name = "Windows Command Shell"
145reference = "https://attack.mitre.org/techniques/T1059/003/"
146
147[[rule.threat.technique.subtechnique]]
148id = "T1059.005"
149name = "Visual Basic"
150reference = "https://attack.mitre.org/techniques/T1059/005/"
151
152
153
154[rule.threat.tactic]
155id = "TA0002"
156name = "Execution"
157reference = "https://attack.mitre.org/tactics/TA0002/"
158[[rule.threat]]
159framework = "MITRE ATT&CK"
160[[rule.threat.technique]]
161id = "T1218"
162name = "System Binary Proxy Execution"
163reference = "https://attack.mitre.org/techniques/T1218/"
164[[rule.threat.technique.subtechnique]]
165id = "T1218.010"
166name = "Regsvr32"
167reference = "https://attack.mitre.org/techniques/T1218/010/"
168
169[[rule.threat.technique.subtechnique]]
170id = "T1218.011"
171name = "Rundll32"
172reference = "https://attack.mitre.org/techniques/T1218/011/"
173
174
175
176[rule.threat.tactic]
177id = "TA0005"
178name = "Defense Evasion"
179reference = "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).

Related rules

to-top