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/06/19"
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 = ["https://pberba.github.io/security/2022/02/07/linux-threat-hunting-for-persistence-systemd-generators/"]
22risk_score = 47
23rule_id = "39c06367-b700-4380-848a-cab06e7afede"
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 "Tactic: Privilege Escalation",
56 "Data Source: Elastic Defend"
57]
58timestamp_override = "event.ingested"
59type = "eql"
60query = '''
61file where host.os.type == "linux" and event.action in ("rename", "creation") and file.path : (
62"/run/systemd/system-generators/*", "/etc/systemd/system-generators/*",
63"/usr/local/lib/systemd/system-generators/*", "/lib/systemd/system-generators/*",
64"/usr/lib/systemd/system-generators/*", "/etc/systemd/user-generators/*",
65"/usr/local/lib/systemd/user-generators/*", "/usr/lib/systemd/user-generators/*",
66"/lib/systemd/user-generators/*"
67) and not (
68 process.executable in (
69 "/bin/dpkg", "/usr/bin/dpkg", "/bin/dockerd", "/usr/bin/dockerd", "/usr/sbin/dockerd", "/bin/microdnf",
70 "/usr/bin/microdnf", "/bin/rpm", "/usr/bin/rpm", "/bin/snapd", "/usr/bin/snapd", "/bin/yum", "/usr/bin/yum",
71 "/bin/dnf", "/usr/bin/dnf", "/bin/podman", "/usr/bin/podman", "/bin/dnf-automatic", "/usr/bin/dnf-automatic",
72 "/bin/pacman", "/usr/bin/pacman", "/usr/bin/dpkg-divert", "/bin/dpkg-divert", "/sbin/apk", "/usr/sbin/apk",
73 "/usr/local/sbin/apk", "/usr/bin/apt", "/usr/sbin/pacman", "/bin/podman", "/usr/bin/podman", "/usr/bin/puppet",
74 "/bin/puppet", "/opt/puppetlabs/puppet/bin/puppet", "/usr/bin/chef-client", "/bin/chef-client",
75 "/bin/autossl_check", "/usr/bin/autossl_check", "/proc/self/exe", "/dev/fd/*", "/usr/bin/pamac-daemon",
76 "/bin/pamac-daemon", "/usr/lib/snapd/snapd", "/usr/local/bin/dockerd"
77 ) or
78 file.extension in ("swp", "swpx", "swx", "dpkg-remove") or
79 file.Ext.original.extension == "dpkg-new" or
80 process.executable == null
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/"
References
Related rules
- Privilege Escalation via SUID/SGID
- Process Capability Set via setcap Utility
- Potential Sudo Hijacking
- At Job Created or Modified
- Kernel Load or Unload via Kexec Detected