Abnormal Process ID or Lock File Created
Identifies the creation of a Process ID (PID), lock or reboot file created in temporary file storage paradigm (tmpfs) directory /var/run. On Linux, the PID files typically hold the process ID to track previous copies running and manage other tasks. Certain Linux malware use the /var/run directory for holding data, executables and other tasks, disguising itself or these files as legitimate PID files.
Elastic rule (View on GitHub)
1[metadata]
2creation_date = "2022/05/11"
3integration = ["endpoint"]
4maturity = "production"
5updated_date = "2024/05/21"
6
7[rule]
8author = ["Elastic"]
9description = """
10Identifies the creation of a Process ID (PID), lock or reboot file created in temporary file storage paradigm (tmpfs)
11directory /var/run. On Linux, the PID files typically hold the process ID to track previous copies running and manage
12other tasks. Certain Linux malware use the /var/run directory for holding data, executables and other tasks, disguising
13itself or these files as legitimate PID files.
14"""
15false_positives = [
16 """
17 False-Positives (FP) can appear if the PID file is legitimate and holding a process ID as intended. To
18 differentiate, if the PID file is an executable or larger than 10 bytes, it should be ruled suspicious.
19 """,
20]
21from = "now-9m"
22index = ["logs-endpoint.events.*", "endgame-*"]
23language = "kuery"
24license = "Elastic License v2"
25name = "Abnormal Process ID or Lock File Created"
26note = """## Triage and analysis
27
28### Investigating Abnormal Process ID or Lock File Created
29
30Linux applications may need to save their process identification number (PID) for various purposes: from signaling that a program is running to serving as a signal that a previous instance of an application didn't exit successfully. PID files contain its creator process PID in an integer value.
31
32Linux lock files are used to coordinate operations in files so that conflicts and race conditions are prevented.
33
34This rule identifies the creation of PID, lock, or reboot files in the /var/run/ directory. Attackers can masquerade malware, payloads, staged data for exfiltration, and more as legitimate PID files.
35
36#### Possible investigation steps
37
38- Retrieve the file and determine if it is malicious:
39 - Check the contents of the PID files. They should only contain integer strings.
40 - Check the file type of the lock and PID files to determine if they are executables. This is only observed in malicious files.
41 - Check the size of the subject file. Legitimate PID files should be under 10 bytes.
42 - Check if the lock or PID file has high entropy. This typically indicates an encrypted payload.
43 - Analysts can use tools like `ent` to measure entropy.
44 - Examine the reputation of the SHA-256 hash in the PID file. Use a database like VirusTotal to identify additional pivots and artifacts for investigation.
45- Trace the file's creation to ensure it came from a legitimate or authorized process.
46- Investigate other alerts associated with the user/host during the past 48 hours.
47- Investigate any abnormal account behavior, such as command executions, file creations or modifications, and network connections.
48- Investigate any abnormal behavior by the subject process such as network connections, file modifications, and any spawned child processes.
49
50### False positive analysis
51
52- False positives can appear if the PID file is legitimate and holding a process ID as intended. If the PID file is an executable or has a file size that's larger than 10 bytes, it should be ruled suspicious.
53- If this activity is expected and noisy in your environment, consider adding exceptions — preferably with a combination of file name and process executable conditions.
54
55### Response and remediation
56
57- Initiate the incident response process based on the outcome of the triage.
58- Isolate the involved host to prevent further post-compromise behavior.
59- 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.
60- Block the identified indicators of compromise (IoCs).
61- Take actions to terminate processes and connections used by the attacker.
62- Run a full antimalware scan. This may reveal additional artifacts left in the system, persistence mechanisms, and malware components.
63- Determine the initial vector abused by the attacker and take action to prevent reinfection through the same vector.
64- 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).
65"""
66references = [
67 "https://www.sandflysecurity.com/blog/linux-file-masquerading-and-malicious-pids-sandfly-1-2-6-update/",
68 "https://twitter.com/GossiTheDog/status/1522964028284411907",
69 "https://exatrack.com/public/Tricephalic_Hellkeeper.pdf",
70 "https://www.elastic.co/security-labs/a-peek-behind-the-bpfdoor",
71]
72risk_score = 47
73rule_id = "cac91072-d165-11ec-a764-f661ea17fbce"
74setup = """## Setup
75
76This rule requires data coming in from Elastic Defend.
77
78### Elastic Defend Integration Setup
79Elastic Defend is integrated into the Elastic Agent using Fleet. Upon configuration, the integration allows the Elastic Agent to monitor events on your host and send data to the Elastic Security app.
80
81#### Prerequisite Requirements:
82- Fleet is required for Elastic Defend.
83- To configure Fleet Server refer to the [documentation](https://www.elastic.co/guide/en/fleet/current/fleet-server.html).
84
85#### The following steps should be executed in order to add the Elastic Defend integration on a Linux System:
86- Go to the Kibana home page and click "Add integrations".
87- In the query bar, search for "Elastic Defend" and select the integration to see more details about it.
88- Click "Add Elastic Defend".
89- Configure the integration name and optionally add a description.
90- Select the type of environment you want to protect, either "Traditional Endpoints" or "Cloud Workloads".
91- 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).
92- We suggest selecting "Complete EDR (Endpoint Detection and Response)" as a configuration setting, that provides "All events; all preventions"
93- 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.
94For more details on Elastic Agent configuration settings, refer to the [helper guide](https://www.elastic.co/guide/en/fleet/8.10/agent-policy.html).
95- Click "Save and Continue".
96- 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.
97For more details on Elastic Defend refer to the [helper guide](https://www.elastic.co/guide/en/security/current/install-endpoint.html).
98"""
99severity = "medium"
100tags = [
101 "Domain: Endpoint",
102 "OS: Linux",
103 "Use Case: Threat Detection",
104 "Tactic: Execution",
105 "Threat: BPFDoor",
106 "Resources: Investigation Guide",
107 "Data Source: Elastic Defend",
108 "Data Source: Elastic Endgame",
109]
110timestamp_override = "event.ingested"
111type = "new_terms"
112
113query = '''
114host.os.type:linux and event.category:file and event.action:(creation or file_create_event) and
115user.id:0 and file.extension:(pid or lock or reboot) and file.path:(/var/run/* or /run/*) and (
116 (process.name : (
117 bash or dash or sh or tcsh or csh or zsh or ksh or fish or ash or touch or nano or vim or vi or editor or mv or cp)
118 ) or (
119 process.executable : (
120 ./* or /tmp/* or /var/tmp/* or /dev/shm/* or /var/run/* or /boot/* or /srv/* or /run/*
121 ))
122) and not process.name : (go or git or containerd* or snap-confine or cron or crond or sshd or unattended-upgrade or
123vzctl or ifup or rpcbind or runc or gitlab-runner-helper or elastic-agent or metricbeat) and
124not file.name : (jem.*.pid)
125'''
126
127
128[[rule.threat]]
129framework = "MITRE ATT&CK"
130[[rule.threat.technique]]
131id = "T1106"
132name = "Native API"
133reference = "https://attack.mitre.org/techniques/T1106/"
134
135
136[rule.threat.tactic]
137id = "TA0002"
138name = "Execution"
139reference = "https://attack.mitre.org/tactics/TA0002/"
140
141[rule.new_terms]
142field = "new_terms_fields"
143value = ["host.id", "process.executable", "file.path"]
144[[rule.new_terms.history_window_start]]
145field = "history_window_start"
146value = "now-14d"
Triage and analysis
Investigating Abnormal Process ID or Lock File Created
Linux applications may need to save their process identification number (PID) for various purposes: from signaling that a program is running to serving as a signal that a previous instance of an application didn't exit successfully. PID files contain its creator process PID in an integer value.
Linux lock files are used to coordinate operations in files so that conflicts and race conditions are prevented.
This rule identifies the creation of PID, lock, or reboot files in the /var/run/ directory. Attackers can masquerade malware, payloads, staged data for exfiltration, and more as legitimate PID files.
Possible investigation steps
- Retrieve the file and determine if it is malicious:
- Check the contents of the PID files. They should only contain integer strings.
- Check the file type of the lock and PID files to determine if they are executables. This is only observed in malicious files.
- Check the size of the subject file. Legitimate PID files should be under 10 bytes.
- Check if the lock or PID file has high entropy. This typically indicates an encrypted payload.
- Analysts can use tools like
ent
to measure entropy.
- Analysts can use tools like
- Examine the reputation of the SHA-256 hash in the PID file. Use a database like VirusTotal to identify additional pivots and artifacts for investigation.
- Trace the file's creation to ensure it came from a legitimate or authorized process.
- Investigate other alerts associated with the user/host during the past 48 hours.
- Investigate any abnormal account behavior, such as command executions, file creations or modifications, and network connections.
- Investigate any abnormal behavior by the subject process such as network connections, file modifications, and any spawned child processes.
False positive analysis
- False positives can appear if the PID file is legitimate and holding a process ID as intended. If the PID file is an executable or has a file size that's larger than 10 bytes, it should be ruled suspicious.
- If this activity is expected and noisy in your environment, consider adding exceptions — preferably with a combination of file name and process executable conditions.
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.
- Block the identified indicators of compromise (IoCs).
- Take actions to terminate processes and connections used by the attacker.
- 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).
References
Related rules
- Binary Executed from Shared Memory Directory
- Process Started from Process ID (PID) File
- BPF filter applied using TC
- Conhost Spawned By Suspicious Parent Process
- Execution of File Written or Modified by PDF Reader