New Systemd Service Created by Previously Unknown Process

Systemd service files are configuration files in Linux systems used to define and manage system services. Malicious actors can leverage systemd service files to achieve persistence by creating or modifying service files to execute malicious commands or payloads during system startup. This allows them to maintain unauthorized access, execute additional malicious activities, or evade detection.

Elastic rule (View on GitHub)

  1[metadata]
  2creation_date = "2023/06/09"
  3integration = ["endpoint"]
  4maturity = "production"
  5min_stack_comments = "New fields added: required_fields, related_integrations, setup, New Term"
  6min_stack_version = "8.6.0"
  7updated_date = "2023/11/02"
  8
  9[rule]
 10author = ["Elastic"]
 11description = """
 12Systemd service files are configuration files in Linux systems used to define and manage system services. Malicious 
 13actors can leverage systemd service files to achieve persistence by creating or modifying service files to execute 
 14malicious commands or payloads during system startup. This allows them to maintain unauthorized access, execute 
 15additional malicious activities, or evade detection.
 16"""
 17from = "now-9m"
 18index = ["logs-endpoint.events.*", "endgame-*"]
 19language = "kuery"
 20license = "Elastic License v2"
 21name = "New Systemd Service Created by Previously Unknown Process"
 22references = [
 23    "https://opensource.com/article/20/7/systemd-timers",
 24    "https://pberba.github.io/security/2022/01/30/linux-threat-hunting-for-persistence-systemd-timers-cron/"
 25]
 26risk_score = 47
 27rule_id = "17b0a495-4d9f-414c-8ad0-92f018b8e001"
 28setup = """
 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
 53"""
 54severity = "medium"
 55tags = [
 56        "Domain: Endpoint",
 57        "OS: Linux",
 58        "Use Case: Threat Detection",
 59        "Tactic: Persistence",
 60        "Tactic: Privilege Escalation",
 61        "Data Source: Elastic Endgame",
 62        "Data Source: Elastic Defend"
 63        ]
 64timestamp_override = "event.ingested"
 65type = "new_terms"
 66
 67query = '''
 68host.os.type:linux and event.category:file and event.action:("creation" or "file_create_event") and file.path:(
 69  /etc/systemd/system/* or 
 70  /usr/local/lib/systemd/system/* or 
 71  /lib/systemd/system/* or 
 72  /usr/lib/systemd/system/* or 
 73  /home/*/.config/systemd/user/*
 74) and 
 75not (
 76  process.name:(
 77    "dpkg" or "dockerd" or "rpm" or "snapd" or "yum" or "exe" or "dnf" or "dnf-automatic" or python* or "puppetd" or
 78    "elastic-agent" or "cinc-client" or "chef-client" or "pacman" or "puppet" or "cloudflared"
 79  ) or 
 80  file.extension:("swp" or "swpx")
 81)
 82'''
 83
 84[[rule.threat]]
 85framework = "MITRE ATT&CK"
 86
 87[[rule.threat.technique]]
 88id = "T1543"
 89name = "Create or Modify System Process"
 90reference = "https://attack.mitre.org/techniques/T1543/"
 91
 92[[rule.threat.technique.subtechnique]]
 93id = "T1543.002"
 94name = "Systemd Service"
 95reference = "https://attack.mitre.org/techniques/T1543/002/"
 96
 97[rule.threat.tactic]
 98id = "TA0003"
 99name = "Persistence"
100reference = "https://attack.mitre.org/tactics/TA0003/"
101
102[[rule.threat]]
103framework = "MITRE ATT&CK"
104
105[[rule.threat.technique]]
106id = "T1543"
107name = "Create or Modify System Process"
108reference = "https://attack.mitre.org/techniques/T1543/"
109
110[[rule.threat.technique.subtechnique]]
111id = "T1543.002"
112name = "Systemd Service"
113reference = "https://attack.mitre.org/techniques/T1543/002/"
114
115[rule.threat.tactic]
116id = "TA0004"
117name = "Privilege Escalation"
118reference = "https://attack.mitre.org/tactics/TA0004/"
119
120[rule.new_terms]
121field = "new_terms_fields"
122value = ["host.id", "file.path", "process.executable"]
123
124[[rule.new_terms.history_window_start]]
125field = "history_window_start"
126value = "now-10d"

References

Related rules

to-top