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