Suspicious File Creation via Kworker
This rule monitors for a file creation event originating from a kworker parent process. kworker, or kernel worker, processes are part of the kernel's workqueue mechanism. They are responsible for executing work that has been scheduled to be done in kernel space, which might include tasks like handling interrupts, background activities, and other kernel-related tasks. Attackers may attempt to evade detection by masquerading as a kernel worker process.
Elastic rule (View on GitHub)
1[metadata]
2creation_date = "2023/10/26"
3integration = ["endpoint"]
4maturity = "production"
5updated_date = "2024/07/18"
6
7[transform]
8[[transform.osquery]]
9label = "Osquery - Retrieve File Listing Information"
10query = "SELECT * FROM file WHERE path = {{file.path}}\n"
11
12[[transform.osquery]]
13label = "Osquery - Retrieve Additional File Listing Information"
14query = """
15SELECT f.path, u.username AS file_owner, g.groupname AS group_owner, datetime(f.atime, 'unixepoch') AS
16file_last_access_time, datetime(f.mtime, 'unixepoch') AS file_last_modified_time, datetime(f.ctime, 'unixepoch') AS
17file_last_status_change_time, datetime(f.btime, 'unixepoch') AS file_created_time, f.size AS size_bytes FROM file f LEFT
18JOIN users u ON f.uid = u.uid LEFT JOIN groups g ON f.gid = g.gid WHERE path = {{file.path}}
19"""
20
21[[transform.osquery]]
22label = "Osquery - Retrieve Running Processes by User"
23query = "SELECT pid, username, name FROM processes p JOIN users u ON u.uid = p.uid ORDER BY username"
24
25[[transform.osquery]]
26label = "Osquery - Retrieve Crontab Information"
27query = "SELECT * FROM crontab"
28
29[[transform.osquery]]
30label = "Osquery - Retrieve Listening Ports"
31query = "SELECT pid, address, port, socket, protocol, path FROM listening_ports"
32
33[[transform.osquery]]
34label = "Osquery - Retrieve Open Sockets"
35query = "SELECT pid, family, remote_address, remote_port, socket, state FROM process_open_sockets"
36
37[[transform.osquery]]
38label = "Osquery - Retrieve Information for a Specific User"
39query = "SELECT * FROM users WHERE username = {{user.name}}"
40
41[[transform.osquery]]
42label = "Osquery - Investigate the Account Authentication Status"
43query = "SELECT * FROM logged_in_users WHERE user = {{user.name}}"
44
45
46[rule]
47author = ["Elastic"]
48description = """
49This rule monitors for a file creation event originating from a kworker parent process. kworker, or kernel worker,
50processes are part of the kernel's workqueue mechanism. They are responsible for executing work that has been scheduled
51to be done in kernel space, which might include tasks like handling interrupts, background activities, and other
52kernel-related tasks. Attackers may attempt to evade detection by masquerading as a kernel worker process.
53"""
54from = "now-9m"
55index = ["logs-endpoint.events.*"]
56language = "eql"
57license = "Elastic License v2"
58name = "Suspicious File Creation via Kworker"
59note = """## Triage and analysis
60
61### Investigating Suspicious File Creation via Kworker
62
63Kworker, or kernel worker, processes are part of the kernel's workqueue mechanism. They are responsible for executing work that has been scheduled to be done in kernel space, which might include tasks like handling interrupts, background activities, and other kernel-related tasks.
64
65Attackers may attempt to evade detection by masquerading as a kernel worker process.
66
67This rule monitors for suspicious file creation events through the kworker process. This is not common, and could indicate malicious behaviour.
68
69> **Note**:
70> 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.
71> This investigation guide uses [placeholder fields](https://www.elastic.co/guide/en/security/current/osquery-placeholder-fields.html) to dynamically pass alert data into Osquery queries. Placeholder fields were introduced in Elastic Stack version 8.7.0. If you're using Elastic Stack version 8.6.0 or earlier, you'll need to manually adjust this investigation guide's queries to ensure they properly run.
72
73#### Possible Investigation Steps
74
75- Investigate the file that was created or modified through OSQuery.
76 - $osquery_0
77 - $osquery_1
78- Investigate the script execution chain (parent process tree) for unknown processes. Examine their executable files for prevalence and whether they are located in expected locations.
79 - $osquery_2
80- Investigate other alerts associated with the user/host during the past 48 hours.
81- Validate the activity is not related to planned patches, updates, network administrator activity, or legitimate software installations.
82- Investigate whether the altered scripts call other malicious scripts elsewhere on the file system.
83 - If scripts or executables were dropped, retrieve the files and determine if they are malicious:
84 - Use a private sandboxed malware analysis system to perform analysis.
85 - Observe and collect information about the following activities:
86 - Attempts to contact external domains and addresses.
87 - Check if the domain is newly registered or unexpected.
88 - Check the reputation of the domain or IP address.
89 - File access, modification, and creation activities.
90 - Cron jobs, services and other persistence mechanisms.
91 - $osquery_3
92- Investigate abnormal behaviors by the subject process/user such as network connections, file modifications, and any other spawned child processes.
93 - Investigate listening ports and open sockets to look for potential command and control traffic or data exfiltration.
94 - $osquery_4
95 - $osquery_5
96 - Identify the user account that performed the action, analyze it, and check whether it should perform this kind of action.
97 - $osquery_6
98- Investigate whether the user is currently logged in and active.
99 - $osquery_7
100
101### False Positive Analysis
102
103- If this activity is related to new benign software installation activity, consider adding exceptions — preferably with a combination of user and command line conditions.
104- If this activity is related to a system administrator that performed these actions for administrative purposes, consider adding exceptions for this specific administrator user account.
105- Try to understand the context of the execution by thinking about the user, machine, or business purpose. A small number of endpoints, such as servers with unique software, might appear unusual but satisfy a specific business need.
106
107### Related Rules
108
109- Suspicious Kworker UID Elevation - 7dfaaa17-425c-4fe7-bd36-83705fde7c2b
110- Network Activity Detected via Kworker - 25d917c4-aa3c-4111-974c-286c0312ff95
111
112### Response and remediation
113
114- Initiate the incident response process based on the outcome of the triage.
115- Isolate the involved host to prevent further post-compromise behavior.
116- If the triage identified malware, search the environment for additional compromised hosts.
117 - Implement temporary network rules, procedures, and segmentation to contain the malware.
118 - Stop suspicious processes.
119 - Immediately block the identified indicators of compromise (IoCs).
120 - Inspect the affected systems for additional malware backdoors like reverse shells, reverse proxies, or droppers that attackers could use to reinfect the system.
121- 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.
122- Run a full antimalware scan. This may reveal additional artifacts left in the system, persistence mechanisms, and malware components.
123- Determine the initial vector abused by the attacker and take action to prevent reinfection through the same vector.
124- Leverage the incident response data and logging to improve the mean time to detect (MTTD) and the mean time to respond (MTTR).
125"""
126risk_score = 47
127rule_id = "ae343298-97bc-47bc-9ea2-5f2ad831c16e"
128setup = """## Setup
129
130This rule requires data coming in from Elastic Defend.
131
132### Elastic Defend Integration Setup
133Elastic Defend is integrated into the Elastic Agent using Fleet. Upon configuration, the integration allows
134the Elastic Agent to monitor events on your host and send data to the Elastic Security app.
135
136#### Prerequisite Requirements:
137- Fleet is required for Elastic Defend.
138- To configure Fleet Server refer to the [documentation](https://www.elastic.co/guide/en/fleet/current/fleet-server.html).
139
140#### The following steps should be executed in order to add the Elastic Defend integration on a Linux System:
141- Go to the Kibana home page and click Add integrations.
142- In the query bar, search for Elastic Defend and select the integration to see more details about it.
143- Click Add Elastic Defend.
144- Configure the integration name and optionally add a description.
145- Select the type of environment you want to protect, either Traditional Endpoints or Cloud Workloads.
146- Select a configuration preset. Each preset comes with different default settings for Elastic Agent, you can further customize these later by configuring the Elastic Defend integration policy. [Helper guide](https://www.elastic.co/guide/en/security/current/configure-endpoint-integration-policy.html).
147- We suggest to select "Complete EDR (Endpoint Detection and Response)" as a configuration setting, that provides "All events; all preventions"
148- Enter a name for the agent policy in New agent policy name. If other agent policies already exist, you can click the Existing hosts tab and select an existing policy instead.
149For more details on Elastic Agent configuration settings, refer to the [helper guide](https://www.elastic.co/guide/en/fleet/8.10/agent-policy.html).
150- Click Save and Continue.
151- To complete the integration, select Add Elastic Agent to your hosts and continue to the next section to install the Elastic Agent on your hosts.
152For more details on Elastic Defend refer to the [helper guide](https://www.elastic.co/guide/en/security/current/install-endpoint.html).
153"""
154severity = "medium"
155tags = [
156 "Domain: Endpoint",
157 "OS: Linux",
158 "Use Case: Threat Detection",
159 "Tactic: Persistence",
160 "Tactic: Defense Evasion",
161 "Data Source: Elastic Defend",
162]
163timestamp_override = "event.ingested"
164type = "eql"
165query = '''
166file where host.os.type == "linux" and event.action in ("creation", "file_create_event") and
167 process.name : "kworker*" and not (
168 (process.name : "kworker*kcryptd*") or
169 (file.path : (
170 "/var/log/*", "/var/crash/*", "/var/run/*", "/var/lib/systemd/coredump/*", "/var/spool/*",
171 "/var/lib/nfs/nfsdcltrack/main.sqlite-journal", "/proc/*/cwd/core.*", "/var/run/apport.lock",
172 "/var/spool/abrt/ccpp-*"
173 )
174 )
175 )
176'''
177
178[[rule.threat]]
179framework = "MITRE ATT&CK"
180
181[[rule.threat.technique]]
182id = "T1547"
183name = "Boot or Logon Autostart Execution"
184reference = "https://attack.mitre.org/techniques/T1547/"
185
186[rule.threat.tactic]
187id = "TA0003"
188name = "Persistence"
189reference = "https://attack.mitre.org/tactics/TA0003/"
190
191[[rule.threat]]
192framework = "MITRE ATT&CK"
193
194[[rule.threat.technique]]
195id = "T1014"
196name = "Rootkit"
197reference = "https://attack.mitre.org/techniques/T1014/"
198
199[rule.threat.tactic]
200id = "TA0005"
201name = "Defense Evasion"
202reference = "https://attack.mitre.org/tactics/TA0005/"
Triage and analysis
Investigating Suspicious File Creation via Kworker
Kworker, or kernel worker, processes are part of the kernel's workqueue mechanism. They are responsible for executing work that has been scheduled to be done in kernel space, which might include tasks like handling interrupts, background activities, and other kernel-related tasks.
Attackers may attempt to evade detection by masquerading as a kernel worker process.
This rule monitors for suspicious file creation events through the kworker process. This is not common, and could indicate malicious behaviour.
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. This investigation guide uses placeholder fields to dynamically pass alert data into Osquery queries. Placeholder fields were introduced in Elastic Stack version 8.7.0. If you're using Elastic Stack version 8.6.0 or earlier, you'll need to manually adjust this investigation guide's queries to ensure they properly run.
Possible Investigation Steps
- Investigate the file that was created or modified through OSQuery.
- $osquery_0
- $osquery_1
- Investigate the script execution chain (parent process tree) for unknown processes. Examine their executable files for prevalence and whether they are located in expected locations.
- $osquery_2
- Investigate other alerts associated with the user/host during the past 48 hours.
- Validate the activity is not related to planned patches, updates, network administrator activity, or legitimate software installations.
- Investigate whether the altered scripts call other malicious scripts elsewhere on the file system.
- If scripts or executables were dropped, retrieve the files and determine if they are malicious:
- Use a private sandboxed malware analysis system to perform analysis.
- Observe and collect information about the following activities:
- Attempts to contact external domains and addresses.
- Check if the domain is newly registered or unexpected.
- Check the reputation of the domain or IP address.
- File access, modification, and creation activities.
- Cron jobs, services and other persistence mechanisms.
- $osquery_3
- Attempts to contact external domains and addresses.
- Observe and collect information about the following activities:
- Use a private sandboxed malware analysis system to perform analysis.
- If scripts or executables were dropped, retrieve the files and determine if they are malicious:
- Investigate abnormal behaviors by the subject process/user such as network connections, file modifications, and any other spawned child processes.
- Investigate listening ports and open sockets to look for potential command and control traffic or data exfiltration.
- $osquery_4
- $osquery_5
- Identify the user account that performed the action, analyze it, and check whether it should perform this kind of action.
- $osquery_6
- Investigate listening ports and open sockets to look for potential command and control traffic or data exfiltration.
- Investigate whether the user is currently logged in and active.
- $osquery_7
False Positive Analysis
- If this activity is related to new benign software installation activity, consider adding exceptions — preferably with a combination of user and command line conditions.
- If this activity is related to a system administrator that performed these actions for administrative purposes, consider adding exceptions for this specific administrator user account.
- Try to understand the context of the execution by thinking about the user, machine, or business purpose. A small number of endpoints, such as servers with unique software, might appear unusual but satisfy a specific business need.
Related Rules
- Suspicious Kworker UID Elevation - 7dfaaa17-425c-4fe7-bd36-83705fde7c2b
- Network Activity Detected via Kworker - 25d917c4-aa3c-4111-974c-286c0312ff95
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.
- If the triage identified malware, search the environment for additional compromised hosts.
- Implement temporary network rules, procedures, and segmentation to contain the malware.
- Stop suspicious processes.
- Immediately block the identified indicators of compromise (IoCs).
- Inspect the affected systems for additional malware backdoors like reverse shells, reverse proxies, or droppers that attackers could use to reinfect the system.
- 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.
- 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.
- Leverage the incident response data and logging to improve the mean time to detect (MTTD) and the mean time to respond (MTTR).
Related rules
- Deprecated - Potential Process Injection via LD_PRELOAD Environment Variable
- RPM Package Installed by Unusual Parent Process
- DPKG Package Installed by Unusual Parent Process
- Process Capability Set via setcap Utility
- Process Spawned from Message-of-the-Day (MOTD)