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