Suspicious Service was Installed in the System

Identifies the creation of a new Windows service with suspicious Service command values. Windows services typically run as SYSTEM and can be used for privilege escalation and persistence.

Elastic rule (View on GitHub)

  1[metadata]
  2creation_date = "2022/08/30"
  3integration = ["system", "windows"]
  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[[transform.osquery]]
 31label = "Osquery - Retrieve All Non-Microsoft Drivers with Virustotal Link"
 32query = """
 33SELECT concat('https://www.virustotal.com/gui/file/', sha1) AS VtLink, class, description, directory, image,
 34issuer_name, manufacturer, service, signed, subject_name FROM drivers JOIN authenticode ON drivers.image =
 35authenticode.path JOIN hash ON drivers.image = hash.path WHERE NOT (provider == "Microsoft" AND signed == "1")
 36"""
 37
 38[[transform.osquery]]
 39label = "Osquery - Retrieve All Unsigned Drivers with Virustotal Link"
 40query = """
 41SELECT concat('https://www.virustotal.com/gui/file/', sha1) AS VtLink, class, description, directory, image,
 42issuer_name, manufacturer, service, signed, subject_name FROM drivers JOIN authenticode ON drivers.image =
 43authenticode.path JOIN hash ON drivers.image = hash.path WHERE signed == "0"
 44"""
 45
 46
 47[rule]
 48author = ["Elastic"]
 49description = """
 50Identifies the creation of a new Windows service with suspicious Service command values. Windows services typically run
 51as SYSTEM and can be used for privilege escalation and persistence.
 52"""
 53from = "now-9m"
 54index = ["winlogbeat-*", "logs-system.*", "logs-windows.*"]
 55language = "eql"
 56license = "Elastic License v2"
 57name = "Suspicious Service was Installed in the System"
 58note = """## Triage and analysis
 59
 60### Investigating Suspicious Service was Installed in the System
 61
 62Attackers may create new services to execute system shells and other command execution utilities to elevate their privileges from administrator to SYSTEM. They can also configure services to execute these utilities with persistence payloads.
 63
 64This rule looks for suspicious services being created with suspicious traits compatible with the above behavior.
 65
 66> **Note**:
 67> 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.
 68#### Possible investigation steps
 69
 70- 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.
 71- 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).
 72  - Examine the created and existent services, the executables or drivers referenced, and command line arguments for suspicious entries.
 73    - $osquery_0
 74    - $osquery_1
 75    - $osquery_2
 76    - $osquery_3
 77    - $osquery_4
 78  - 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.
 79- Identify the user account that performed the action and whether it should perform this kind of action.
 80- Contact the account owner and confirm whether they are aware of this activity.
 81- Investigate other alerts associated with the user/host during the past 48 hours.
 82- Assess whether this behavior is prevalent in the environment by looking for similar occurrences across hosts.
 83
 84
 85### False positive analysis
 86
 87- Certain services such as PSEXECSVC may happen legitimately. The security team should address any potential benign true positive (B-TP) by excluding the relevant FP by pattern.
 88
 89### Response and remediation
 90
 91- Initiate the incident response process based on the outcome of the triage.
 92- Isolate the involved host to prevent further post-compromise behavior.
 93- 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.
 94- Delete the service.
 95- Run a full antimalware scan. This may reveal additional artifacts left in the system, persistence mechanisms, and malware components.
 96- Determine the initial vector abused by the attacker and take action to prevent reinfection through the same vector.
 97- 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).
 98"""
 99risk_score = 47
100rule_id = "da87eee1-129c-4661-a7aa-57d0b9645fad"
101severity = "medium"
102tags = [
103    "Domain: Endpoint",
104    "OS: Windows",
105    "Use Case: Threat Detection",
106    "Tactic: Persistence",
107    "Resources: Investigation Guide",
108    "Data Source: System",
109]
110timestamp_override = "event.ingested"
111type = "eql"
112
113query = '''
114any where
115  (event.code : "4697" and
116   (winlog.event_data.ServiceFileName : 
117           ("*COMSPEC*", "*\\127.0.0.1*", "*Admin$*", "*powershell*", "*rundll32*", "*cmd.exe*", "*PSEXESVC*", 
118            "*echo*", "*RemComSvc*", "*.bat*", "*.cmd*", "*certutil*", "*vssadmin*", "*certmgr*", "*bitsadmin*", 
119            "*\\Users\\*", "*\\Windows\\Temp\\*", "*\\Windows\\Tasks\\*", "*\\PerfLogs\\*", "*\\Windows\\Debug\\*",
120            "*regsvr32*", "*msbuild*") or
121   winlog.event_data.ServiceFileName regex~ """%systemroot%\\[a-z0-9]+\.exe""")) or
122
123  (event.code : "7045" and
124   winlog.event_data.ImagePath : (
125       "*COMSPEC*", "*\\127.0.0.1*", "*Admin$*", "*powershell*", "*rundll32*", "*cmd.exe*", "*PSEXESVC*",
126       "*echo*", "*RemComSvc*", "*.bat*", "*.cmd*", "*certutil*", "*vssadmin*", "*certmgr*", "*bitsadmin*",
127       "*\\Users\\*", "*\\Windows\\Temp\\*", "*\\Windows\\Tasks\\*", "*\\PerfLogs\\*", "*\\Windows\\Debug\\*",
128       "*regsvr32*", "*msbuild*"))
129'''
130
131
132[[rule.threat]]
133framework = "MITRE ATT&CK"
134[[rule.threat.technique]]
135id = "T1543"
136name = "Create or Modify System Process"
137reference = "https://attack.mitre.org/techniques/T1543/"
138[[rule.threat.technique.subtechnique]]
139id = "T1543.003"
140name = "Windows Service"
141reference = "https://attack.mitre.org/techniques/T1543/003/"
142
143
144
145[rule.threat.tactic]
146id = "TA0003"
147name = "Persistence"
148reference = "https://attack.mitre.org/tactics/TA0003/"

Triage and analysis

Investigating Suspicious Service was Installed in the System

Attackers may create new services to execute system shells and other command execution utilities to elevate their privileges from administrator to SYSTEM. They can also configure services to execute these utilities with persistence payloads.

This rule looks for suspicious services being created with suspicious traits 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
      • $osquery_3
      • $osquery_4
    • 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

  • Certain services such as PSEXECSVC may happen legitimately. The security team should address any potential benign true positive (B-TP) by excluding the relevant FP by pattern.

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.
  • 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