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"]
  4maturity = "production"
  5updated_date = "2024/09/23"
  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-*"]
 17language = "eql"
 18license = "Elastic License v2"
 19name = "Executable Bit Set for Potential Persistence Script"
 20references = [
 21    "https://www.intezer.com/blog/malware-analysis/hiddenwasp-malware-targeting-linux-systems/",
 22    "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",
 23    "https://www.cyberciti.biz/faq/how-to-enable-rc-local-shell-script-on-systemd-while-booting-linux-system/",
 24    "https://www.elastic.co/security-labs/sequel-on-persistence-mechanisms",
 25]
 26risk_score = 21
 27rule_id = "94418745-529f-4259-8d25-a713a6feb6ae"
 28setup = """## Setup
 29
 30This rule requires data coming in from Elastic Defend.
 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"""
 53severity = "low"
 54tags = [
 55    "Domain: Endpoint",
 56    "OS: Linux",
 57    "Use Case: Threat Detection",
 58    "Tactic: Persistence",
 59    "Data Source: Elastic Endgame",
 60    "Data Source: Elastic Defend",
 61]
 62timestamp_override = "event.ingested"
 63type = "eql"
 64
 65query = '''
 66process where host.os.type == "linux" and event.type == "start" and event.action in ("exec", "exec_event") and
 67process.args : (
 68  // Misc.
 69  "/etc/rc.local", "/etc/rc.common", "/etc/rc.d/rc.local", "/etc/init.d/*", "/etc/update-motd.d/*",
 70  "/etc/apt/apt.conf.d/*", "/etc/cron*", "/etc/init/*",
 71
 72  // XDG
 73  "/etc/xdg/autostart/*", "/home/*/.config/autostart/*", "/root/.config/autostart/*",
 74  "/home/*/.local/share/autostart/*", "/root/.local/share/autostart/*", "/home/*/.config/autostart-scripts/*",
 75  "/root/.config/autostart-scripts/*", "/etc/xdg/autostart/*", "/usr/share/autostart/*",
 76  
 77  // udev
 78  "/lib/udev/*", "/etc/udev/rules.d/*", "/usr/lib/udev/rules.d/*", "/run/udev/rules.d/*"
 79
 80) and (
 81  (process.name == "chmod" and process.args : ("+x*", "1*", "3*", "5*", "7*")) or
 82  (process.name == "install" and process.args : "-m*" and process.args : ("7*", "5*", "3*", "1*"))
 83) and not process.parent.executable : "/var/lib/dpkg/*"
 84'''
 85
 86
 87[[rule.threat]]
 88framework = "MITRE ATT&CK"
 89[[rule.threat.technique]]
 90id = "T1037"
 91name = "Boot or Logon Initialization Scripts"
 92reference = "https://attack.mitre.org/techniques/T1037/"
 93[[rule.threat.technique.subtechnique]]
 94id = "T1037.004"
 95name = "RC Scripts"
 96reference = "https://attack.mitre.org/techniques/T1037/004/"
 97
 98
 99[[rule.threat.technique]]
100id = "T1053"
101name = "Scheduled Task/Job"
102reference = "https://attack.mitre.org/techniques/T1053/"
103[[rule.threat.technique.subtechnique]]
104id = "T1053.003"
105name = "Cron"
106reference = "https://attack.mitre.org/techniques/T1053/003/"
107
108
109[[rule.threat.technique]]
110id = "T1547"
111name = "Boot or Logon Autostart Execution"
112reference = "https://attack.mitre.org/techniques/T1547/"
113[[rule.threat.technique.subtechnique]]
114id = "T1547.013"
115name = "XDG Autostart Entries"
116reference = "https://attack.mitre.org/techniques/T1547/013/"
117
118
119
120[rule.threat.tactic]
121id = "TA0003"
122name = "Persistence"
123reference = "https://attack.mitre.org/tactics/TA0003/"

References

Related rules

to-top