Executable Bit Set for Potential Persistence Script

This rule monitors for the addition of an executable bit for scripts that are located in directories which are commonly abused for persistence. An alert of this rule is an indicator that a persistence mechanism is being set up within your environment. Adversaries may create these scripts to execute malicious code at start-up, or at a set interval to gain persistence onto the system.

Elastic rule (View on GitHub)

  1[metadata]
  2creation_date = "2024/06/03"
  3integration = ["endpoint", "sentinel_one_cloud_funnel"]
  4maturity = "production"
  5updated_date = "2025/03/20"
  6
  7[rule]
  8author = ["Elastic"]
  9description = """
 10This rule monitors for the addition of an executable bit for scripts that are located in directories which are commonly
 11abused for persistence. An alert of this rule is an indicator that a persistence mechanism is being set up within your
 12environment. Adversaries may create these scripts to execute malicious code at start-up, or at a set interval to gain
 13persistence onto the system.
 14"""
 15from = "now-9m"
 16index = ["logs-endpoint.events.process*", "endgame-*", "logs-sentinel_one_cloud_funnel.*"]
 17language = "eql"
 18license = "Elastic License v2"
 19name = "Executable Bit Set for Potential Persistence Script"
 20note = """## Triage and analysis
 21
 22> **Disclaimer**:
 23> 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.
 24
 25### Investigating Executable Bit Set for Potential Persistence Script
 26
 27In Linux environments, scripts with executable permissions can be used to automate tasks, including system start-up processes. Adversaries exploit this by setting executable bits on scripts in directories typically used for persistence, allowing malicious code to run automatically. The detection rule identifies such activities by monitoring for changes in executable permissions in these directories, signaling potential unauthorized persistence attempts.
 28
 29### Possible investigation steps
 30
 31- Review the process details to identify the specific script or file that had its executable bit set, focusing on the process.args field to determine the exact file path.
 32- Examine the process.parent.executable field to understand the parent process that initiated the permission change, which can provide context on whether the action was part of a legitimate process or potentially malicious activity.
 33- Check the user account associated with the process to determine if the action was performed by a legitimate user or a compromised account.
 34- Investigate the history of the file in question, including recent modifications and the creation date, to assess if it aligns with known system changes or updates.
 35- Analyze the contents of the script or file to identify any suspicious or unauthorized code that could indicate malicious intent.
 36- Correlate this event with other recent alerts or logs from the same host to identify patterns or additional indicators of compromise that may suggest a broader persistence mechanism.
 37
 38### False positive analysis
 39
 40- System administrators or automated scripts may legitimately change executable permissions in directories like /etc/init.d or /etc/cron* for maintenance or updates. To handle these, create exceptions for known administrative scripts or processes that regularly perform these actions.
 41- Software installations or updates might trigger this rule when they modify startup scripts or configuration files. Users can mitigate this by excluding processes originating from trusted package managers or installation paths, such as /var/lib/dpkg.
 42- Custom user scripts in home directories, especially in /home/*/.config/autostart, may be flagged if users set them to run at startup. To reduce false positives, maintain a whitelist of user scripts that are known and approved for startup execution.
 43- Security tools or monitoring solutions might adjust permissions as part of their operations. Identify these tools and exclude their processes from triggering the rule to prevent unnecessary alerts.
 44
 45### Response and remediation
 46
 47- Immediately isolate the affected system from the network to prevent potential lateral movement by the adversary.
 48- Terminate any suspicious processes identified in the alert that are associated with unauthorized script execution.
 49- Remove or disable the executable permissions on the identified scripts to prevent further unauthorized execution.
 50- Conduct a thorough review of the affected directories to identify and remove any additional unauthorized scripts or files.
 51- Restore any modified system files or configurations from a known good backup to ensure system integrity.
 52- Monitor the system for any signs of re-infection or further unauthorized changes, focusing on the directories and processes highlighted in the alert.
 53- Escalate the incident to the security operations team for further investigation and to determine if additional systems are affected."""
 54references = [
 55    "https://www.intezer.com/blog/malware-analysis/hiddenwasp-malware-targeting-linux-systems/",
 56    "https://pberba.github.io/security/2022/02/06/linux-threat-hunting-for-persistence-initialization-scripts-and-shell-configuration/#8-boot-or-logon-initialization-scripts-rc-scripts",
 57    "https://www.cyberciti.biz/faq/how-to-enable-rc-local-shell-script-on-systemd-while-booting-linux-system/",
 58    "https://www.elastic.co/security-labs/sequel-on-persistence-mechanisms",
 59]
 60risk_score = 21
 61rule_id = "94418745-529f-4259-8d25-a713a6feb6ae"
 62setup = """## Setup
 63
 64This rule requires data coming in from Elastic Defend.
 65
 66### Elastic Defend Integration Setup
 67Elastic 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.
 68
 69#### Prerequisite Requirements:
 70- Fleet is required for Elastic Defend.
 71- To configure Fleet Server refer to the [documentation](https://www.elastic.co/guide/en/fleet/current/fleet-server.html).
 72
 73#### The following steps should be executed in order to add the Elastic Defend integration on a Linux System:
 74- Go to the Kibana home page and click "Add integrations".
 75- In the query bar, search for "Elastic Defend" and select the integration to see more details about it.
 76- Click "Add Elastic Defend".
 77- Configure the integration name and optionally add a description.
 78- Select the type of environment you want to protect, either "Traditional Endpoints" or "Cloud Workloads".
 79- 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).
 80- We suggest selecting "Complete EDR (Endpoint Detection and Response)" as a configuration setting, that provides "All events; all preventions"
 81- 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.
 82For more details on Elastic Agent configuration settings, refer to the [helper guide](https://www.elastic.co/guide/en/fleet/8.10/agent-policy.html).
 83- Click "Save and Continue".
 84- 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.
 85For more details on Elastic Defend refer to the [helper guide](https://www.elastic.co/guide/en/security/current/install-endpoint.html).
 86"""
 87severity = "low"
 88tags = [
 89    "Domain: Endpoint",
 90    "OS: Linux",
 91    "Use Case: Threat Detection",
 92    "Tactic: Persistence",
 93    "Data Source: Elastic Endgame",
 94    "Data Source: Elastic Defend",
 95    "Data Source: SentinelOne",
 96    "Resources: Investigation Guide",
 97]
 98timestamp_override = "event.ingested"
 99type = "eql"
100
101query = '''
102process where host.os.type == "linux" and event.type == "start" and event.action in ("exec", "exec_event", "start") and
103process.args : (
104  // Misc.
105  "/etc/rc.local", "/etc/rc.common", "/etc/rc.d/rc.local", "/etc/init.d/*", "/etc/update-motd.d/*",
106  "/etc/apt/apt.conf.d/*", "/etc/cron*", "/etc/init/*", "/etc/NetworkManager/dispatcher.d/*",
107  "/lib/dracut/modules.d/*", "/usr/lib/dracut/modules.d/*",
108
109  // XDG
110  "/etc/xdg/autostart/*", "/home/*/.config/autostart/*", "/root/.config/autostart/*",
111  "/home/*/.local/share/autostart/*", "/root/.local/share/autostart/*", "/home/*/.config/autostart-scripts/*",
112  "/root/.config/autostart-scripts/*", "/etc/xdg/autostart/*", "/usr/share/autostart/*",
113
114  // udev
115  "/lib/udev/*", "/etc/udev/rules.d/*", "/usr/lib/udev/rules.d/*", "/run/udev/rules.d/*"
116
117) and (
118  (process.name == "chmod" and process.args : ("+x*", "1*", "3*", "5*", "7*")) or
119  (process.name == "install" and process.args : "-m*" and process.args : ("7*", "5*", "3*", "1*"))
120) and not (
121  process.parent.executable : "/var/lib/dpkg/*" or
122  process.command_line in ("chmod 777 /etc/update-motd.d/", "chmod 755 /etc/update-motd.d/")
123)
124'''
125
126
127[[rule.threat]]
128framework = "MITRE ATT&CK"
129[[rule.threat.technique]]
130id = "T1037"
131name = "Boot or Logon Initialization Scripts"
132reference = "https://attack.mitre.org/techniques/T1037/"
133[[rule.threat.technique.subtechnique]]
134id = "T1037.004"
135name = "RC Scripts"
136reference = "https://attack.mitre.org/techniques/T1037/004/"
137
138
139[[rule.threat.technique]]
140id = "T1053"
141name = "Scheduled Task/Job"
142reference = "https://attack.mitre.org/techniques/T1053/"
143[[rule.threat.technique.subtechnique]]
144id = "T1053.003"
145name = "Cron"
146reference = "https://attack.mitre.org/techniques/T1053/003/"
147
148
149[[rule.threat.technique]]
150id = "T1547"
151name = "Boot or Logon Autostart Execution"
152reference = "https://attack.mitre.org/techniques/T1547/"
153[[rule.threat.technique.subtechnique]]
154id = "T1547.013"
155name = "XDG Autostart Entries"
156reference = "https://attack.mitre.org/techniques/T1547/013/"
157
158
159
160[rule.threat.tactic]
161id = "TA0003"
162name = "Persistence"
163reference = "https://attack.mitre.org/tactics/TA0003/"
...
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.

In Linux environments, scripts with executable permissions can be used to automate tasks, including system start-up processes. Adversaries exploit this by setting executable bits on scripts in directories typically used for persistence, allowing malicious code to run automatically. The detection rule identifies such activities by monitoring for changes in executable permissions in these directories, signaling potential unauthorized persistence attempts.

  • Review the process details to identify the specific script or file that had its executable bit set, focusing on the process.args field to determine the exact file path.
  • Examine the process.parent.executable field to understand the parent process that initiated the permission change, which can provide context on whether the action was part of a legitimate process or potentially malicious activity.
  • Check the user account associated with the process to determine if the action was performed by a legitimate user or a compromised account.
  • Investigate the history of the file in question, including recent modifications and the creation date, to assess if it aligns with known system changes or updates.
  • Analyze the contents of the script or file to identify any suspicious or unauthorized code that could indicate malicious intent.
  • Correlate this event with other recent alerts or logs from the same host to identify patterns or additional indicators of compromise that may suggest a broader persistence mechanism.
  • System administrators or automated scripts may legitimately change executable permissions in directories like /etc/init.d or /etc/cron* for maintenance or updates. To handle these, create exceptions for known administrative scripts or processes that regularly perform these actions.
  • Software installations or updates might trigger this rule when they modify startup scripts or configuration files. Users can mitigate this by excluding processes originating from trusted package managers or installation paths, such as /var/lib/dpkg.
  • Custom user scripts in home directories, especially in /home/*/.config/autostart, may be flagged if users set them to run at startup. To reduce false positives, maintain a whitelist of user scripts that are known and approved for startup execution.
  • Security tools or monitoring solutions might adjust permissions as part of their operations. Identify these tools and exclude their processes from triggering the rule to prevent unnecessary alerts.
  • Immediately isolate the affected system from the network to prevent potential lateral movement by the adversary.
  • Terminate any suspicious processes identified in the alert that are associated with unauthorized script execution.
  • Remove or disable the executable permissions on the identified scripts to prevent further unauthorized execution.
  • Conduct a thorough review of the affected directories to identify and remove any additional unauthorized scripts or files.
  • Restore any modified system files or configurations from a known good backup to ensure system integrity.
  • Monitor the system for any signs of re-infection or further unauthorized changes, focusing on the directories and processes highlighted in the alert.
  • Escalate the incident to the security operations team for further investigation and to determine if additional systems are affected.

References

Related rules

to-top