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 = "2025/01/24"
  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    "Resources: Investigation Guide",
 61]
 62timestamp_override = "event.ingested"
 63type = "eql"
 64query = '''
 65file where host.os.type == "linux" and event.action in ("rename", "creation") and file.path : (
 66"/run/systemd/system-generators/*", "/etc/systemd/system-generators/*",
 67"/usr/local/lib/systemd/system-generators/*", "/lib/systemd/system-generators/*",
 68"/usr/lib/systemd/system-generators/*", "/etc/systemd/user-generators/*",
 69"/usr/local/lib/systemd/user-generators/*", "/usr/lib/systemd/user-generators/*",
 70"/lib/systemd/user-generators/*"
 71) and not (
 72  process.executable in (
 73    "/bin/dpkg", "/usr/bin/dpkg", "/bin/dockerd", "/usr/bin/dockerd", "/usr/sbin/dockerd", "/bin/microdnf",
 74    "/usr/bin/microdnf", "/bin/rpm", "/usr/bin/rpm", "/bin/snapd", "/usr/bin/snapd", "/bin/yum", "/usr/bin/yum",
 75    "/bin/dnf", "/usr/bin/dnf", "/bin/podman", "/usr/bin/podman", "/bin/dnf-automatic", "/usr/bin/dnf-automatic",
 76    "/bin/pacman", "/usr/bin/pacman", "/usr/bin/dpkg-divert", "/bin/dpkg-divert", "/sbin/apk", "/usr/sbin/apk",
 77    "/usr/local/sbin/apk", "/usr/bin/apt", "/usr/sbin/pacman", "/bin/podman", "/usr/bin/podman", "/usr/bin/puppet",
 78    "/bin/puppet", "/opt/puppetlabs/puppet/bin/puppet", "/usr/bin/chef-client", "/bin/chef-client", "/usr/sbin/sshd",
 79    "/bin/autossl_check", "/usr/bin/autossl_check", "/proc/self/exe", "/dev/fd/*",  "/usr/bin/pamac-daemon",
 80    "/bin/pamac-daemon", "/usr/lib/snapd/snapd", "/usr/local/bin/dockerd", "/usr/libexec/platform-python"
 81  ) or
 82  process.name like~ ("ssm-agent-worker", "crio", "docker-init", "systemd", "pacman", "python*", "platform-python*") or
 83  file.extension in ("swp", "swpx", "swx", "dpkg-remove") or
 84  file.Ext.original.extension == "dpkg-new" or
 85  process.executable == null
 86)
 87'''
 88note = """## Triage and analysis
 89
 90> **Disclaimer**:
 91> This investigation guide was created using generative AI technology and has been reviewed to improve its accuracy and relevance. While every effort has been made to ensure its quality, we recommend validating the content and adapting it to suit your specific environment and operational needs.
 92
 93### Investigating Systemd Generator Created
 94
 95Systemd generators are scripts that systemd runs at boot or during configuration reloads to convert non-native configurations into unit files. Adversaries can exploit this by creating malicious generators to execute arbitrary code, ensuring persistence or escalating privileges. The detection rule identifies suspicious generator file creations or renames, excluding benign processes and file types, to flag potential abuse.
 96
 97### Possible investigation steps
 98
 99- Review the file path where the generator was created or renamed to determine if it is located in a standard systemd generator directory, such as /run/systemd/system-generators/ or /etc/systemd/user-generators/.
100- Identify the process that created or renamed the generator file by examining the process.executable field, and determine if it is a known benign process or potentially malicious.
101- Check the file extension and original extension fields to ensure the file is not a temporary or expected system file, such as those with extensions like "swp" or "dpkg-new".
102- Investigate the history and behavior of the process that created the generator file, including any associated network connections or file modifications, to assess if it exhibits signs of malicious activity.
103- Correlate the event with other security alerts or logs from the same host to identify any patterns or additional indicators of compromise that might suggest persistence or privilege escalation attempts.
104
105### False positive analysis
106
107- Package managers like dpkg, rpm, and yum can trigger false positives when they create or rename files in systemd generator directories during software installations or updates. To handle these, exclude processes associated with these package managers as specified in the rule.
108- Automated system management tools such as Puppet and Chef may also create or modify generator files as part of their configuration management tasks. Exclude these processes by adding them to the exception list if they are part of your environment.
109- Temporary files with extensions like swp, swpx, and swx, often created by text editors, can be mistakenly flagged. Ensure these extensions are included in the exclusion list to prevent unnecessary alerts.
110- System updates or maintenance scripts that run as part of regular operations might create or modify generator files. Identify these scripts and add their executables to the exclusion list to reduce false positives.
111- Custom scripts or tools that are part of legitimate administrative tasks may also trigger alerts. Review these scripts and consider excluding their executables if they are verified as non-malicious.
112
113### Response and remediation
114
115- Immediately isolate the affected system from the network to prevent further execution of potentially malicious code and lateral movement.
116- Terminate any suspicious processes associated with the creation or modification of systemd generator files to halt any ongoing malicious activity.
117- Conduct a thorough review of the systemd generator directories to identify and remove any unauthorized or suspicious generator files.
118- Restore any modified or deleted legitimate systemd generator files from a known good backup to ensure system integrity.
119- Implement file integrity monitoring on systemd generator directories to detect unauthorized changes in the future.
120- Escalate the incident to the security operations team for further investigation and to determine if additional systems are affected.
121- Review and update access controls and permissions for systemd generator directories to limit the ability to create or modify files to authorized users only."""
122
123[[rule.threat]]
124framework = "MITRE ATT&CK"
125
126[[rule.threat.technique]]
127id = "T1543"
128name = "Create or Modify System Process"
129reference = "https://attack.mitre.org/techniques/T1543/"
130
131[[rule.threat.technique.subtechnique]]
132id = "T1543.002"
133name = "Systemd Service"
134reference = "https://attack.mitre.org/techniques/T1543/002/"
135
136[rule.threat.tactic]
137id = "TA0003"
138name = "Persistence"
139reference = "https://attack.mitre.org/tactics/TA0003/"
140
141[[rule.threat]]
142framework = "MITRE ATT&CK"
143
144[[rule.threat.technique]]
145id = "T1543"
146name = "Create or Modify System Process"
147reference = "https://attack.mitre.org/techniques/T1543/"
148
149[[rule.threat.technique.subtechnique]]
150id = "T1543.002"
151name = "Systemd Service"
152reference = "https://attack.mitre.org/techniques/T1543/002/"
153
154[rule.threat.tactic]
155id = "TA0004"
156name = "Privilege Escalation"
157reference = "https://attack.mitre.org/tactics/TA0004/"

Triage and analysis

Disclaimer: This investigation guide was created using generative AI technology and has been reviewed to improve its accuracy and relevance. While every effort has been made to ensure its quality, we recommend validating the content and adapting it to suit your specific environment and operational needs.

Investigating Systemd Generator Created

Systemd generators are scripts that systemd runs at boot or during configuration reloads to convert non-native configurations into unit files. Adversaries can exploit this by creating malicious generators to execute arbitrary code, ensuring persistence or escalating privileges. The detection rule identifies suspicious generator file creations or renames, excluding benign processes and file types, to flag potential abuse.

Possible investigation steps

  • Review the file path where the generator was created or renamed to determine if it is located in a standard systemd generator directory, such as /run/systemd/system-generators/ or /etc/systemd/user-generators/.
  • Identify the process that created or renamed the generator file by examining the process.executable field, and determine if it is a known benign process or potentially malicious.
  • Check the file extension and original extension fields to ensure the file is not a temporary or expected system file, such as those with extensions like "swp" or "dpkg-new".
  • Investigate the history and behavior of the process that created the generator file, including any associated network connections or file modifications, to assess if it exhibits signs of malicious activity.
  • Correlate the event with other security alerts or logs from the same host to identify any patterns or additional indicators of compromise that might suggest persistence or privilege escalation attempts.

False positive analysis

  • Package managers like dpkg, rpm, and yum can trigger false positives when they create or rename files in systemd generator directories during software installations or updates. To handle these, exclude processes associated with these package managers as specified in the rule.
  • Automated system management tools such as Puppet and Chef may also create or modify generator files as part of their configuration management tasks. Exclude these processes by adding them to the exception list if they are part of your environment.
  • Temporary files with extensions like swp, swpx, and swx, often created by text editors, can be mistakenly flagged. Ensure these extensions are included in the exclusion list to prevent unnecessary alerts.
  • System updates or maintenance scripts that run as part of regular operations might create or modify generator files. Identify these scripts and add their executables to the exclusion list to reduce false positives.
  • Custom scripts or tools that are part of legitimate administrative tasks may also trigger alerts. Review these scripts and consider excluding their executables if they are verified as non-malicious.

Response and remediation

  • Immediately isolate the affected system from the network to prevent further execution of potentially malicious code and lateral movement.
  • Terminate any suspicious processes associated with the creation or modification of systemd generator files to halt any ongoing malicious activity.
  • Conduct a thorough review of the systemd generator directories to identify and remove any unauthorized or suspicious generator files.
  • Restore any modified or deleted legitimate systemd generator files from a known good backup to ensure system integrity.
  • Implement file integrity monitoring on systemd generator directories to detect unauthorized changes in the future.
  • Escalate the incident to the security operations team for further investigation and to determine if additional systems are affected.
  • Review and update access controls and permissions for systemd generator directories to limit the ability to create or modify files to authorized users only.

References

Related rules

to-top