Shell Configuration Modification

This rule monitors the creation/alteration of a shell configuration by a previously unknown process executable using the new terms rule type. Unix systems use shell configuration files to set environment variables, create aliases, and customize the user's environment. Adversaries may modify or add a shell configuration file to execute malicious code and gain persistence in the system. This behavior is consistent with the Kaiji malware family.

Elastic rule (View on GitHub)

  1[metadata]
  2creation_date = "2024/04/30"
  3integration = ["endpoint"]
  4maturity = "production"
  5updated_date = "2024/05/21"
  6
  7[rule]
  8author = ["Elastic"]
  9description = """
 10This rule monitors the creation/alteration of a shell configuration by a previously unknown process executable using the
 11new terms rule type. Unix systems use shell configuration files to set environment variables, create aliases, and
 12customize the user's environment. Adversaries may modify or add a shell configuration file to execute malicious code and
 13gain persistence in the system. This behavior is consistent with the Kaiji malware family.
 14"""
 15false_positives = ["Legitimate user shell modification activity."]
 16from = "now-9m"
 17index = ["logs-endpoint.events.*", "endgame-*"]
 18language = "kuery"
 19license = "Elastic License v2"
 20name = "Shell Configuration Modification"
 21references = ["https://intezer.com/blog/research/kaiji-new-chinese-linux-malware-turning-to-golang/"]
 22risk_score = 47
 23rule_id = "28f6f34b-8e16-487a-b5fd-9d22eb903db8"
 24setup = """## Setup
 25
 26This rule requires data coming in from Elastic Defend.
 27
 28### Elastic Defend Integration Setup
 29Elastic 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.
 30
 31#### Prerequisite Requirements:
 32- Fleet is required for Elastic Defend.
 33- To configure Fleet Server refer to the [documentation](https://www.elastic.co/guide/en/fleet/current/fleet-server.html).
 34
 35#### The following steps should be executed in order to add the Elastic Defend integration on a Linux System:
 36- Go to the Kibana home page and click "Add integrations".
 37- In the query bar, search for "Elastic Defend" and select the integration to see more details about it.
 38- Click "Add Elastic Defend".
 39- Configure the integration name and optionally add a description.
 40- Select the type of environment you want to protect, either "Traditional Endpoints" or "Cloud Workloads".
 41- 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).
 42- We suggest selecting "Complete EDR (Endpoint Detection and Response)" as a configuration setting, that provides "All events; all preventions"
 43- 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.
 44For more details on Elastic Agent configuration settings, refer to the [helper guide](https://www.elastic.co/guide/en/fleet/8.10/agent-policy.html).
 45- Click "Save and Continue".
 46- 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.
 47For more details on Elastic Defend refer to the [helper guide](https://www.elastic.co/guide/en/security/current/install-endpoint.html).
 48"""
 49severity = "medium"
 50tags = [
 51    "Domain: Endpoint",
 52    "OS: Linux",
 53    "Use Case: Threat Detection",
 54    "Tactic: Persistence",
 55    "Data Source: Elastic Endgame",
 56    "Data Source: Elastic Defend",
 57]
 58timestamp_override = "event.ingested"
 59type = "new_terms"
 60
 61query = '''
 62event.category:file and host.os.type:linux and
 63event.action:(creation or file_create_event or rename or file_rename_event) and file.path:(
 64  "/etc/profile" or "/etc/profile.local" or "/etc/bashrc" or "/etc/bash.bashrc" or "/etc/bash.bashrc.local" or
 65  "/etc/zshenv" or "/etc/zprofile" or "/etc/zlogin" or "/etc/zlogout" or "/root/.profile" or "/root/.bash_logout" or
 66  "/root/.bashrc" or "/root/.bash_login" or /etc/profile.d/* or /home/*/.profile or /home/*/.bash_logout or
 67  /home/*/.bashrc or /home/*/.bash_login
 68) and not (
 69  (process.executable: (
 70  "/bin/dpkg" or "/usr/bin/dpkg" or "/bin/useradd" or "/usr/sbin/useradd" or "/bin/adduser" or "/usr/sbin/adduser" or
 71  "/bin/dockerd" or "/usr/bin/dockerd" or "/bin/microdnf" or "/usr/bin/microdnf" or "/bin/rpm" or "/usr/bin/rpm" or
 72  "/bin/snapd" or "/usr/bin/snapd" or "/bin/yum" or "/usr/bin/yum" or "/bin/dnf" or "/usr/bin/dnf" or "/bin/podman" or
 73  "/usr/bin/podman" or "/bin/dnf-automatic" or "/usr/bin/dnf-automatic" or "/bin/pacman" or "/usr/bin/pacman"
 74  )
 75) or
 76  (file.extension:("swp" or "swpx")) or
 77  (process.executable:("/bin/sed" or "/usr/bin/sed") and file.name:sed*) or
 78  (process.executable:("/bin/perl" or "/usr/bin/perl") and file.name:e2scrub_all.tmp*)
 79)
 80'''
 81
 82
 83[[rule.threat]]
 84framework = "MITRE ATT&CK"
 85[[rule.threat.technique]]
 86id = "T1546"
 87name = "Event Triggered Execution"
 88reference = "https://attack.mitre.org/techniques/T1546/"
 89[[rule.threat.technique.subtechnique]]
 90id = "T1546.004"
 91name = "Unix Shell Configuration Modification"
 92reference = "https://attack.mitre.org/techniques/T1546/004/"
 93
 94
 95
 96[rule.threat.tactic]
 97id = "TA0003"
 98name = "Persistence"
 99reference = "https://attack.mitre.org/tactics/TA0003/"
100
101[rule.new_terms]
102field = "new_terms_fields"
103value = ["host.id", "user.id", "process.executable"]
104[[rule.new_terms.history_window_start]]
105field = "history_window_start"
106value = "now-10d"

References

Related rules

to-top