Systemd Generator Created
This rule detects the creation of a systemd generator file. Generators are small executables executed by systemd at bootup and during configuration reloads. Their main role is to convert non-native configuration and execution parameters into dynamically generated unit files, symlinks, or drop-ins, extending the unit file hierarchy for the service manager. Systemd generators can be used to execute arbitrary code at boot time, which can be leveraged by attackers to maintain persistence on a Linux system.
Elastic rule (View on GitHub)
1[metadata]
2creation_date = "2024/06/19"
3integration = ["endpoint"]
4maturity = "production"
5updated_date = "2024/10/17"
6
7[rule]
8author = ["Elastic"]
9description = """
10This rule detects the creation of a systemd generator file. Generators are small executables executed by systemd at
11bootup and during configuration reloads. Their main role is to convert non-native configuration and execution parameters
12into dynamically generated unit files, symlinks, or drop-ins, extending the unit file hierarchy for the service manager.
13Systemd generators can be used to execute arbitrary code at boot time, which can be leveraged by attackers to maintain
14persistence on a Linux system.
15"""
16from = "now-9m"
17index = ["logs-endpoint.events.file*"]
18language = "eql"
19license = "Elastic License v2"
20name = "Systemd Generator Created"
21references = [
22 "https://pberba.github.io/security/2022/02/07/linux-threat-hunting-for-persistence-systemd-generators/",
23 "https://www.elastic.co/security-labs/primer-on-persistence-mechanisms",
24]
25risk_score = 47
26rule_id = "39c06367-b700-4380-848a-cab06e7afede"
27setup = """## Setup
28
29This rule requires data coming in from Elastic Defend.
30
31### Elastic Defend Integration Setup
32Elastic 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.
33
34#### Prerequisite Requirements:
35- Fleet is required for Elastic Defend.
36- To configure Fleet Server refer to the [documentation](https://www.elastic.co/guide/en/fleet/current/fleet-server.html).
37
38#### The following steps should be executed in order to add the Elastic Defend integration on a Linux System:
39- Go to the Kibana home page and click "Add integrations".
40- In the query bar, search for "Elastic Defend" and select the integration to see more details about it.
41- Click "Add Elastic Defend".
42- Configure the integration name and optionally add a description.
43- Select the type of environment you want to protect, either "Traditional Endpoints" or "Cloud Workloads".
44- 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).
45- We suggest selecting "Complete EDR (Endpoint Detection and Response)" as a configuration setting, that provides "All events; all preventions"
46- 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.
47For more details on Elastic Agent configuration settings, refer to the [helper guide](https://www.elastic.co/guide/en/fleet/8.10/agent-policy.html).
48- Click "Save and Continue".
49- 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.
50For more details on Elastic Defend refer to the [helper guide](https://www.elastic.co/guide/en/security/current/install-endpoint.html).
51"""
52severity = "medium"
53tags = [
54 "Domain: Endpoint",
55 "OS: Linux",
56 "Use Case: Threat Detection",
57 "Tactic: Persistence",
58 "Tactic: Privilege Escalation",
59 "Data Source: Elastic Defend",
60]
61timestamp_override = "event.ingested"
62type = "eql"
63query = '''
64file where host.os.type == "linux" and event.action in ("rename", "creation") and file.path : (
65"/run/systemd/system-generators/*", "/etc/systemd/system-generators/*",
66"/usr/local/lib/systemd/system-generators/*", "/lib/systemd/system-generators/*",
67"/usr/lib/systemd/system-generators/*", "/etc/systemd/user-generators/*",
68"/usr/local/lib/systemd/user-generators/*", "/usr/lib/systemd/user-generators/*",
69"/lib/systemd/user-generators/*"
70) and not (
71 process.executable in (
72 "/bin/dpkg", "/usr/bin/dpkg", "/bin/dockerd", "/usr/bin/dockerd", "/usr/sbin/dockerd", "/bin/microdnf",
73 "/usr/bin/microdnf", "/bin/rpm", "/usr/bin/rpm", "/bin/snapd", "/usr/bin/snapd", "/bin/yum", "/usr/bin/yum",
74 "/bin/dnf", "/usr/bin/dnf", "/bin/podman", "/usr/bin/podman", "/bin/dnf-automatic", "/usr/bin/dnf-automatic",
75 "/bin/pacman", "/usr/bin/pacman", "/usr/bin/dpkg-divert", "/bin/dpkg-divert", "/sbin/apk", "/usr/sbin/apk",
76 "/usr/local/sbin/apk", "/usr/bin/apt", "/usr/sbin/pacman", "/bin/podman", "/usr/bin/podman", "/usr/bin/puppet",
77 "/bin/puppet", "/opt/puppetlabs/puppet/bin/puppet", "/usr/bin/chef-client", "/bin/chef-client", "/usr/sbin/sshd",
78 "/bin/autossl_check", "/usr/bin/autossl_check", "/proc/self/exe", "/dev/fd/*", "/usr/bin/pamac-daemon",
79 "/bin/pamac-daemon", "/usr/lib/snapd/snapd", "/usr/local/bin/dockerd", "/usr/libexec/platform-python"
80 ) or
81 file.extension in ("swp", "swpx", "swx", "dpkg-remove") or
82 file.Ext.original.extension == "dpkg-new" or
83 process.executable == null
84)
85'''
86
87[[rule.threat]]
88framework = "MITRE ATT&CK"
89
90[[rule.threat.technique]]
91id = "T1543"
92name = "Create or Modify System Process"
93reference = "https://attack.mitre.org/techniques/T1543/"
94
95[[rule.threat.technique.subtechnique]]
96id = "T1543.002"
97name = "Systemd Service"
98reference = "https://attack.mitre.org/techniques/T1543/002/"
99
100[rule.threat.tactic]
101id = "TA0003"
102name = "Persistence"
103reference = "https://attack.mitre.org/tactics/TA0003/"
104
105[[rule.threat]]
106framework = "MITRE ATT&CK"
107
108[[rule.threat.technique]]
109id = "T1543"
110name = "Create or Modify System Process"
111reference = "https://attack.mitre.org/techniques/T1543/"
112
113[[rule.threat.technique.subtechnique]]
114id = "T1543.002"
115name = "Systemd Service"
116reference = "https://attack.mitre.org/techniques/T1543/002/"
117
118[rule.threat.tactic]
119id = "TA0004"
120name = "Privilege Escalation"
121reference = "https://attack.mitre.org/tactics/TA0004/"
References
Related rules
- Shadow File Modification
- Systemd Service Created
- Kernel Load or Unload via Kexec Detected
- At Job Created or Modified
- Potential Sudo Hijacking