File Permission Modification in Writable Directory

Identifies file permission modifications in common writable directories by a non-root user. Adversaries often drop files or payloads into a writable directory and change permissions prior to execution.

Elastic rule (View on GitHub)

  1[metadata]
  2creation_date = "2020/04/21"
  3integration = ["endpoint"]
  4maturity = "production"
  5updated_date = "2025/01/24"
  6
  7[rule]
  8author = ["Elastic"]
  9description = """
 10Identifies file permission modifications in common writable directories by a non-root user. Adversaries often drop files
 11or payloads into a writable directory and change permissions prior to execution.
 12"""
 13false_positives = [
 14    """
 15    Certain programs or applications may modify files or change ownership in writable directories. These can be exempted
 16    by username.
 17    """,
 18]
 19from = "now-9m"
 20index = ["logs-endpoint.events.*"]
 21language = "kuery"
 22license = "Elastic License v2"
 23name = "File Permission Modification in Writable Directory"
 24risk_score = 21
 25rule_id = "9f9a2a82-93a8-4b1a-8778-1780895626d4"
 26setup = """## Setup
 27
 28This rule requires data coming in from one of the following integrations:
 29- Elastic Defend
 30- Auditbeat
 31
 32### Elastic Defend Integration Setup
 33Elastic 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.
 34
 35#### Prerequisite Requirements:
 36- Fleet is required for Elastic Defend.
 37- To configure Fleet Server refer to the [documentation](https://www.elastic.co/guide/en/fleet/current/fleet-server.html).
 38
 39#### The following steps should be executed in order to add the Elastic Defend integration on a Linux System:
 40- Go to the Kibana home page and click "Add integrations".
 41- In the query bar, search for "Elastic Defend" and select the integration to see more details about it.
 42- Click "Add Elastic Defend".
 43- Configure the integration name and optionally add a description.
 44- Select the type of environment you want to protect, either "Traditional Endpoints" or "Cloud Workloads".
 45- 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).
 46- We suggest selecting "Complete EDR (Endpoint Detection and Response)" as a configuration setting, that provides "All events; all preventions"
 47- 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.
 48For more details on Elastic Agent configuration settings, refer to the [helper guide](https://www.elastic.co/guide/en/fleet/8.10/agent-policy.html).
 49- Click "Save and Continue".
 50- 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.
 51For more details on Elastic Defend refer to the [helper guide](https://www.elastic.co/guide/en/security/current/install-endpoint.html).
 52
 53### Auditbeat Setup
 54Auditbeat 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.
 55
 56#### The following steps should be executed in order to add the Auditbeat on a Linux System:
 57- Elastic provides repositories available for APT and YUM-based distributions. Note that we provide binary packages, but no source packages.
 58- 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).
 59- 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).
 60- 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).
 61- 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).
 62"""
 63severity = "low"
 64tags = [
 65    "Domain: Endpoint",
 66    "OS: Linux",
 67    "Use Case: Threat Detection",
 68    "Tactic: Defense Evasion",
 69    "Data Source: Elastic Defend",
 70    "Resources: Investigation Guide",
 71]
 72timestamp_override = "event.ingested"
 73type = "new_terms"
 74
 75query = '''
 76host.os.type:linux and event.category:process and event.type:start and
 77process.name:(chattr or chgrp or chmod or chown) and process.working_directory:(/dev/shm or /tmp or /var/tmp) and
 78not process.parent.name:(
 79  apt-key or update-motd-updates-available or apt-get or java or pilot or PassengerAgent or nginx
 80)
 81'''
 82note = """## Triage and analysis
 83
 84> **Disclaimer**:
 85> 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.
 86
 87### Investigating File Permission Modification in Writable Directory
 88
 89In Linux environments, writable directories like /tmp or /var/tmp are often used for temporary file storage. Adversaries exploit these by modifying file permissions to execute malicious payloads. The detection rule identifies non-root users altering permissions in these directories using commands like chmod or chown, excluding benign processes, to flag potential threats. This helps in identifying unauthorized permission changes indicative of defense evasion tactics.
 90
 91### Possible investigation steps
 92
 93- Review the process details to identify the non-root user who executed the permission modification command (chattr, chgrp, chmod, or chown) in the specified writable directories (/dev/shm, /tmp, or /var/tmp).
 94- Examine the parent process of the detected command to determine if it is associated with any known malicious activity or if it deviates from typical user behavior, ensuring it is not one of the excluded benign processes (apt-key, update-motd-updates-available, apt-get).
 95- Investigate the specific file or directory whose permissions were altered to assess its legitimacy and check for any associated suspicious files or payloads.
 96- Analyze recent activities by the identified user to detect any other anomalous behavior or unauthorized access attempts that could indicate a broader compromise.
 97- Cross-reference the event with other security logs and alerts to identify any correlated incidents or patterns that might suggest a coordinated attack or persistent threat.
 98
 99### False positive analysis
100
101- System updates and maintenance scripts may trigger permission changes in writable directories. Exclude processes like apt-key, update-motd-updates-available, and apt-get to reduce noise from legitimate system activities.
102- Development and testing environments often involve frequent permission changes by non-root users. Consider excluding specific user accounts or processes known to be part of regular development workflows.
103- Automated backup or synchronization tools might modify file permissions as part of their operations. Identify and exclude these tools if they are verified to be non-threatening.
104- Custom scripts or applications that require permission changes for functionality should be reviewed and, if deemed safe, added to an exception list to prevent false alerts.
105- Regularly review and update the exclusion list to ensure it reflects current operational practices and does not inadvertently allow malicious activities.
106
107### Response and remediation
108
109- Immediately isolate the affected system from the network to prevent further unauthorized access or lateral movement.
110- Terminate any suspicious processes identified in the alert that are associated with unauthorized permission changes.
111- Revert any unauthorized file permission changes in the writable directories to their original state to prevent execution of malicious payloads.
112- Conduct a thorough scan of the affected directories (/dev/shm, /tmp, /var/tmp) for any malicious files or payloads and remove them.
113- Review user accounts and permissions to ensure that only authorized users have access to modify file permissions in sensitive directories.
114- Escalate the incident to the security operations team for further investigation and to determine if additional systems are affected.
115- Implement enhanced monitoring and logging for file permission changes in writable directories to detect similar threats in the future."""
116
117
118[[rule.threat]]
119framework = "MITRE ATT&CK"
120[[rule.threat.technique]]
121id = "T1222"
122name = "File and Directory Permissions Modification"
123reference = "https://attack.mitre.org/techniques/T1222/"
124
125
126[rule.threat.tactic]
127id = "TA0005"
128name = "Defense Evasion"
129reference = "https://attack.mitre.org/tactics/TA0005/"
130
131[rule.new_terms]
132field = "new_terms_fields"
133value = ["host.id", "process.parent.executable", "process.command_line"]
134[[rule.new_terms.history_window_start]]
135field = "history_window_start"
136value = "now-14d"

Triage and analysis

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.

Investigating File Permission Modification in Writable Directory

In Linux environments, writable directories like /tmp or /var/tmp are often used for temporary file storage. Adversaries exploit these by modifying file permissions to execute malicious payloads. The detection rule identifies non-root users altering permissions in these directories using commands like chmod or chown, excluding benign processes, to flag potential threats. This helps in identifying unauthorized permission changes indicative of defense evasion tactics.

Possible investigation steps

  • Review the process details to identify the non-root user who executed the permission modification command (chattr, chgrp, chmod, or chown) in the specified writable directories (/dev/shm, /tmp, or /var/tmp).
  • Examine the parent process of the detected command to determine if it is associated with any known malicious activity or if it deviates from typical user behavior, ensuring it is not one of the excluded benign processes (apt-key, update-motd-updates-available, apt-get).
  • Investigate the specific file or directory whose permissions were altered to assess its legitimacy and check for any associated suspicious files or payloads.
  • Analyze recent activities by the identified user to detect any other anomalous behavior or unauthorized access attempts that could indicate a broader compromise.
  • Cross-reference the event with other security logs and alerts to identify any correlated incidents or patterns that might suggest a coordinated attack or persistent threat.

False positive analysis

  • System updates and maintenance scripts may trigger permission changes in writable directories. Exclude processes like apt-key, update-motd-updates-available, and apt-get to reduce noise from legitimate system activities.
  • Development and testing environments often involve frequent permission changes by non-root users. Consider excluding specific user accounts or processes known to be part of regular development workflows.
  • Automated backup or synchronization tools might modify file permissions as part of their operations. Identify and exclude these tools if they are verified to be non-threatening.
  • Custom scripts or applications that require permission changes for functionality should be reviewed and, if deemed safe, added to an exception list to prevent false alerts.
  • Regularly review and update the exclusion list to ensure it reflects current operational practices and does not inadvertently allow malicious activities.

Response and remediation

  • Immediately isolate the affected system from the network to prevent further unauthorized access or lateral movement.
  • Terminate any suspicious processes identified in the alert that are associated with unauthorized permission changes.
  • Revert any unauthorized file permission changes in the writable directories to their original state to prevent execution of malicious payloads.
  • Conduct a thorough scan of the affected directories (/dev/shm, /tmp, /var/tmp) for any malicious files or payloads and remove them.
  • Review user accounts and permissions to ensure that only authorized users have access to modify file permissions in sensitive directories.
  • Escalate the incident to the security operations team for further investigation and to determine if additional systems are affected.
  • Implement enhanced monitoring and logging for file permission changes in writable directories to detect similar threats in the future.

Related rules

to-top