File made Immutable by Chattr

Detects a file being made immutable using the chattr binary. Making a file immutable means it cannot be deleted or renamed, no link can be created to this file, most of the file's metadata can not be modified, and the file can not be opened in write mode. Threat actors will commonly utilize this to prevent tampering or modification of their malicious files or any system files they have modified for purposes of persistence (e.g .ssh, /etc/passwd, etc.).

Elastic rule (View on GitHub)

  1[metadata]
  2creation_date = "2022/07/22"
  3integration = ["endpoint", "sentinel_one_cloud_funnel"]
  4maturity = "production"
  5updated_date = "2025/03/20"
  6
  7[rule]
  8author = ["Elastic"]
  9description = """
 10Detects a file being made immutable using the chattr binary. Making a file immutable means it cannot be deleted or
 11renamed, no link can be created to this file, most of the file's metadata can not be modified, and the file can not be
 12opened in write mode. Threat actors will commonly utilize this to prevent tampering or modification of their malicious
 13files or any system files they have modified for purposes of persistence (e.g .ssh, /etc/passwd, etc.).
 14"""
 15from = "now-9m"
 16index = ["auditbeat-*", "endgame-*", "logs-endpoint.events.process*", "logs-sentinel_one_cloud_funnel.*"]
 17language = "eql"
 18license = "Elastic License v2"
 19max_signals = 33
 20name = "File made Immutable by Chattr"
 21note = """## Triage and analysis
 22
 23> **Disclaimer**:
 24> This investigation guide was created using generative AI technology and has been reviewed to improve its accuracy and relevance. While every effort has been made to ensure its quality, we recommend validating the content and adapting it to suit your specific environment and operational needs.
 25
 26### Investigating File made Immutable by Chattr
 27
 28The `chattr` command in Linux is used to change file attributes, including making files immutable, which prevents modifications or deletions. Adversaries exploit this to secure malicious files or altered system files against tampering, aiding persistence. The detection rule identifies suspicious use of `chattr` by monitoring process executions, filtering out benign parent processes, and focusing on those altering immutability attributes, thus highlighting potential misuse.
 29
 30### Possible investigation steps
 31
 32- Review the process execution details to confirm the use of the chattr command with arguments altering immutability, specifically looking for "+i" or "-i" in process.args.
 33- Identify the file(s) targeted by the chattr command to determine if they are critical system files or files commonly targeted by threat actors, such as .ssh or /etc/passwd.
 34- Investigate the parent process of the chattr execution by examining process.parent.executable and process.parent.name to determine if it is a known benign process or potentially malicious.
 35- Check the user context under which the chattr command was executed to assess if it aligns with expected administrative activity or if it indicates unauthorized access.
 36- Correlate the event with other security alerts or logs to identify any related suspicious activities, such as unauthorized access attempts or changes to other system files.
 37- Evaluate the risk and impact of the immutable file(s) on system operations and security posture, considering the potential for persistence or defense evasion by threat actors.
 38
 39### False positive analysis
 40
 41- System processes like systemd and cf-agent may invoke chattr for legitimate reasons, such as system maintenance or configuration management. To handle these, exclude these processes by adding them to the exception list in the detection rule.
 42- Scheduled tasks or scripts that use chattr to manage file attributes for security or operational purposes can trigger false positives. Identify these tasks and exclude their parent processes from the rule.
 43- Administrative actions performed by authorized users, such as securing configuration files, might be flagged. Regularly review and update the list of known benign parent processes to prevent unnecessary alerts.
 44- Security tools or agents that modify file attributes as part of their protection mechanisms can cause false positives. Ensure these tools are recognized and excluded by their executable paths or parent process names.
 45
 46### Response and remediation
 47
 48- Isolate the affected system from the network to prevent further spread or communication with potential command and control servers.
 49- Identify and terminate any malicious processes associated with the `chattr` command to stop further unauthorized file modifications.
 50- Restore the affected files from a known good backup, ensuring that any immutable attributes set by the attacker are removed.
 51- Conduct a thorough review of user accounts and permissions on the affected system to ensure no unauthorized access or privilege escalation has occurred.
 52- Implement file integrity monitoring to detect unauthorized changes to critical system files, enhancing detection capabilities for similar threats.
 53- Escalate the incident to the security operations team for further investigation and to determine if additional systems are compromised.
 54- Review and update security policies and configurations to prevent unauthorized use of the `chattr` command, such as restricting its execution to trusted administrators only."""
 55risk_score = 47
 56rule_id = "968ccab9-da51-4a87-9ce2-d3c9782fd759"
 57setup = """## Setup
 58
 59This rule requires data coming in from one of the following integrations:
 60- Elastic Defend
 61- Auditbeat
 62
 63### Elastic Defend Integration Setup
 64Elastic 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.
 65
 66#### Prerequisite Requirements:
 67- Fleet is required for Elastic Defend.
 68- To configure Fleet Server refer to the [documentation](https://www.elastic.co/guide/en/fleet/current/fleet-server.html).
 69
 70#### The following steps should be executed in order to add the Elastic Defend integration on a Linux System:
 71- Go to the Kibana home page and click "Add integrations".
 72- In the query bar, search for "Elastic Defend" and select the integration to see more details about it.
 73- Click "Add Elastic Defend".
 74- Configure the integration name and optionally add a description.
 75- Select the type of environment you want to protect, either "Traditional Endpoints" or "Cloud Workloads".
 76- 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).
 77- We suggest selecting "Complete EDR (Endpoint Detection and Response)" as a configuration setting, that provides "All events; all preventions"
 78- 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.
 79For more details on Elastic Agent configuration settings, refer to the [helper guide](https://www.elastic.co/guide/en/fleet/8.10/agent-policy.html).
 80- Click "Save and Continue".
 81- 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.
 82For more details on Elastic Defend refer to the [helper guide](https://www.elastic.co/guide/en/security/current/install-endpoint.html).
 83
 84### Auditbeat Setup
 85Auditbeat is a lightweight shipper that you can install on your servers to audit the activities of users and processes on your systems. For example, you can use Auditbeat to collect and centralize audit events from the Linux Audit Framework. You can also use Auditbeat to detect changes to critical files, like binaries and configuration files, and identify potential security policy violations.
 86
 87#### The following steps should be executed in order to add the Auditbeat on a Linux System:
 88- Elastic provides repositories available for APT and YUM-based distributions. Note that we provide binary packages, but no source packages.
 89- To install the APT and YUM repositories follow the setup instructions in this [helper guide](https://www.elastic.co/guide/en/beats/auditbeat/current/setup-repositories.html).
 90- To run Auditbeat on Docker follow the setup instructions in the [helper guide](https://www.elastic.co/guide/en/beats/auditbeat/current/running-on-docker.html).
 91- To run Auditbeat on Kubernetes follow the setup instructions in the [helper guide](https://www.elastic.co/guide/en/beats/auditbeat/current/running-on-kubernetes.html).
 92- For complete “Setup and Run Auditbeat” information refer to the [helper guide](https://www.elastic.co/guide/en/beats/auditbeat/current/setting-up-and-running.html).
 93
 94#### Custom Ingest Pipeline
 95For versions <8.2, you need to add a custom ingest pipeline to populate `event.ingested` with @timestamp for non-elastic-agent indexes, like auditbeats/filebeat/winlogbeat etc. For more details to add a custom ingest pipeline refer to the [guide](https://www.elastic.co/guide/en/fleet/current/data-streams-pipeline-tutorial.html).
 96"""
 97severity = "medium"
 98tags = [
 99    "Domain: Endpoint",
100    "OS: Linux",
101    "Use Case: Threat Detection",
102    "Tactic: Defense Evasion",
103    "Data Source: Elastic Endgame",
104    "Data Source: Elastic Defend",
105    "Data Source: SentinelOne",
106    "Resources: Investigation Guide",
107]
108timestamp_override = "event.ingested"
109type = "eql"
110
111query = '''
112process where host.os.type == "linux" and event.type == "start" and process.parent.executable != null and
113process.executable : "/usr/bin/chattr" and process.args : ("-*i*", "+*i*") and not (
114  process.parent.executable: ("/lib/systemd/systemd", "/usr/local/uems_agent/bin/*", "/usr/lib/systemd/systemd") or
115  process.parent.name in (
116    "systemd", "cf-agent", "ntpdate", "xargs", "px", "preinst", "auth", "cf-agent", "dcservice", "dcagentupgrader",
117    "sudo", "ephemeral-disk-warning"
118  )
119)
120'''
121
122
123[[rule.threat]]
124framework = "MITRE ATT&CK"
125[[rule.threat.technique]]
126id = "T1222"
127name = "File and Directory Permissions Modification"
128reference = "https://attack.mitre.org/techniques/T1222/"
129[[rule.threat.technique.subtechnique]]
130id = "T1222.002"
131name = "Linux and Mac File and Directory Permissions Modification"
132reference = "https://attack.mitre.org/techniques/T1222/002/"
133
134
135
136[rule.threat.tactic]
137id = "TA0005"
138name = "Defense Evasion"
139reference = "https://attack.mitre.org/tactics/TA0005/"
...
toml

Disclaimer: This investigation guide was created using generative AI technology and has been reviewed to improve its accuracy and relevance. While every effort has been made to ensure its quality, we recommend validating the content and adapting it to suit your specific environment and operational needs.

The chattr command in Linux is used to change file attributes, including making files immutable, which prevents modifications or deletions. Adversaries exploit this to secure malicious files or altered system files against tampering, aiding persistence. The detection rule identifies suspicious use of chattr by monitoring process executions, filtering out benign parent processes, and focusing on those altering immutability attributes, thus highlighting potential misuse.

  • Review the process execution details to confirm the use of the chattr command with arguments altering immutability, specifically looking for "+i" or "-i" in process.args.
  • Identify the file(s) targeted by the chattr command to determine if they are critical system files or files commonly targeted by threat actors, such as .ssh or /etc/passwd.
  • Investigate the parent process of the chattr execution by examining process.parent.executable and process.parent.name to determine if it is a known benign process or potentially malicious.
  • Check the user context under which the chattr command was executed to assess if it aligns with expected administrative activity or if it indicates unauthorized access.
  • Correlate the event with other security alerts or logs to identify any related suspicious activities, such as unauthorized access attempts or changes to other system files.
  • Evaluate the risk and impact of the immutable file(s) on system operations and security posture, considering the potential for persistence or defense evasion by threat actors.
  • System processes like systemd and cf-agent may invoke chattr for legitimate reasons, such as system maintenance or configuration management. To handle these, exclude these processes by adding them to the exception list in the detection rule.
  • Scheduled tasks or scripts that use chattr to manage file attributes for security or operational purposes can trigger false positives. Identify these tasks and exclude their parent processes from the rule.
  • Administrative actions performed by authorized users, such as securing configuration files, might be flagged. Regularly review and update the list of known benign parent processes to prevent unnecessary alerts.
  • Security tools or agents that modify file attributes as part of their protection mechanisms can cause false positives. Ensure these tools are recognized and excluded by their executable paths or parent process names.
  • Isolate the affected system from the network to prevent further spread or communication with potential command and control servers.
  • Identify and terminate any malicious processes associated with the chattr command to stop further unauthorized file modifications.
  • Restore the affected files from a known good backup, ensuring that any immutable attributes set by the attacker are removed.
  • Conduct a thorough review of user accounts and permissions on the affected system to ensure no unauthorized access or privilege escalation has occurred.
  • Implement file integrity monitoring to detect unauthorized changes to critical system files, enhancing detection capabilities for similar threats.
  • Escalate the incident to the security operations team for further investigation and to determine if additional systems are compromised.
  • Review and update security policies and configurations to prevent unauthorized use of the chattr command, such as restricting its execution to trusted administrators only.

Related rules

to-top