Systemd Shell Execution During Boot

This rule detects the execution of shell commands by systemd during the boot process on Linux systems. Systemd is a system and service manager for Linux operating systems. Attackers may execute shell commands during the boot process to maintain persistence on the system. This may be a sign of malicious systemd services, initramfs or GRUB bootloader manipulation, or other persistence mechanisms.

Elastic rule (View on GitHub)

  1[metadata]
  2creation_date = "2025/01/16"
  3integration = ["endpoint"]
  4maturity = "production"
  5updated_date = "2025/01/22"
  6
  7[rule]
  8author = ["Elastic"]
  9description = """
 10This rule detects the execution of shell commands by systemd during the boot process on Linux systems. Systemd
 11is a system and service manager for Linux operating systems. Attackers may execute shell commands during the
 12boot process to maintain persistence on the system. This may be a sign of malicious systemd services, initramfs
 13or GRUB bootloader manipulation, or other persistence mechanisms.
 14"""
 15from = "now-9m"
 16index = ["logs-endpoint.events.process*"]
 17language = "eql"
 18license = "Elastic License v2"
 19name = "Systemd Shell Execution During Boot"
 20risk_score = 47
 21rule_id = "0b76ad27-c3f3-4769-9e7e-3237137fdf06"
 22setup = """## Setup
 23
 24This rule requires data coming in from Elastic Defend.
 25
 26### Elastic Defend Integration Setup
 27Elastic 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.
 28
 29#### Prerequisite Requirements:
 30- Fleet is required for Elastic Defend.
 31- To configure Fleet Server refer to the [documentation](https://www.elastic.co/guide/en/fleet/current/fleet-server.html).
 32
 33#### The following steps should be executed in order to add the Elastic Defend integration on a Linux System:
 34- Go to the Kibana home page and click "Add integrations".
 35- In the query bar, search for "Elastic Defend" and select the integration to see more details about it.
 36- Click "Add Elastic Defend".
 37- Configure the integration name and optionally add a description.
 38- Select the type of environment you want to protect, either "Traditional Endpoints" or "Cloud Workloads".
 39- 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).
 40- We suggest selecting "Complete EDR (Endpoint Detection and Response)" as a configuration setting, that provides "All events; all preventions"
 41- 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.
 42For more details on Elastic Agent configuration settings, refer to the [helper guide](https://www.elastic.co/guide/en/fleet/8.10/agent-policy.html).
 43- Click "Save and Continue".
 44- 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.
 45For more details on Elastic Defend refer to the [helper guide](https://www.elastic.co/guide/en/security/current/install-endpoint.html).
 46"""
 47severity = "medium"
 48tags = [
 49    "Domain: Endpoint",
 50    "OS: Linux",
 51    "Use Case: Threat Detection",
 52    "Tactic: Persistence",
 53    "Tactic: Privilege Escalation",
 54    "Data Source: Elastic Defend",
 55    "Resources: Investigation Guide",
 56]
 57timestamp_override = "event.ingested"
 58type = "eql"
 59query = '''
 60process where host.os.type == "linux" and event.type == "info" and event.action == "already_running" and
 61process.parent.name == "systemd" and process.name in ("bash", "sh", "tcsh", "csh", "zsh", "ksh", "fish") and
 62process.parent.command_line == "/sbin/init" and process.args_count >= 2
 63'''
 64note = """## Triage and analysis
 65
 66> **Disclaimer**:
 67> 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.
 68
 69### Investigating Systemd Shell Execution During Boot
 70
 71Systemd is a critical component in Linux, managing system and service initialization during boot. Adversaries may exploit systemd to execute shell commands at startup, ensuring persistence and potential privilege escalation. The detection rule identifies suspicious shell executions by monitoring processes initiated by systemd, focusing on those with specific characteristics indicative of unauthorized activity.
 72
 73### Possible investigation steps
 74
 75- Review the process details to confirm the parent process is indeed systemd and the command line used is "/sbin/init" to ensure the alert is not a false positive.
 76- Examine the specific shell process name (e.g., bash, sh, etc.) and its arguments to identify any unusual or suspicious commands being executed.
 77- Investigate the history and configuration of the systemd service or unit file associated with the suspicious process to determine if it has been modified or created recently.
 78- Check for any recent changes or anomalies in the initramfs or GRUB bootloader configurations that could indicate tampering or unauthorized modifications.
 79- Correlate the alert with other security events or logs from the same host to identify any patterns or additional indicators of compromise that might suggest a broader attack or persistence mechanism.
 80
 81### False positive analysis
 82
 83- Legitimate system maintenance scripts may trigger this rule if they are executed by systemd during boot. Users can create exceptions for known maintenance scripts by identifying their specific command lines and excluding them from the detection rule.
 84- Custom user scripts that are intentionally set to run at boot for automation purposes might be flagged. To handle this, users should document these scripts and adjust the rule to exclude their specific process names or command lines.
 85- Some Linux distributions may use shell scripts for legitimate boot-time operations. Users should verify the distribution's default boot scripts and exclude them if they are known to be safe and necessary for system operation.
 86- System updates or package installations that modify boot processes could cause false positives. Users should monitor for these events and temporarily adjust the rule to prevent unnecessary alerts during known update windows.
 87
 88### Response and remediation
 89
 90- Immediately isolate the affected system from the network to prevent further unauthorized access or lateral movement.
 91- Terminate any suspicious shell processes identified as being executed by systemd during boot to halt potential malicious activity.
 92- Conduct a thorough review of systemd service files and configurations to identify and remove any unauthorized or malicious entries.
 93- Restore any modified system files or configurations from a known good backup to ensure system integrity.
 94- Escalate the incident to the security operations team for further investigation and to determine if additional systems are affected.
 95- Implement enhanced monitoring on the affected system and similar environments to detect any recurrence of the threat.
 96- Review and update access controls and permissions to limit the ability of unauthorized users to modify systemd configurations or execute shell commands during boot."""
 97
 98[[rule.threat]]
 99framework = "MITRE ATT&CK"
100
101[[rule.threat.technique]]
102id = "T1543"
103name = "Create or Modify System Process"
104reference = "https://attack.mitre.org/techniques/T1543/"
105
106[[rule.threat.technique.subtechnique]]
107id = "T1543.002"
108name = "Systemd Service"
109reference = "https://attack.mitre.org/techniques/T1543/002/"
110
111[rule.threat.tactic]
112id = "TA0003"
113name = "Persistence"
114reference = "https://attack.mitre.org/tactics/TA0003/"
115
116[[rule.threat]]
117framework = "MITRE ATT&CK"
118
119[[rule.threat.technique]]
120id = "T1543"
121name = "Create or Modify System Process"
122reference = "https://attack.mitre.org/techniques/T1543/"
123
124[[rule.threat.technique.subtechnique]]
125id = "T1543.002"
126name = "Systemd Service"
127reference = "https://attack.mitre.org/techniques/T1543/002/"
128
129[rule.threat.tactic]
130id = "TA0004"
131name = "Privilege Escalation"
132reference = "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 Shell Execution During Boot

Systemd is a critical component in Linux, managing system and service initialization during boot. Adversaries may exploit systemd to execute shell commands at startup, ensuring persistence and potential privilege escalation. The detection rule identifies suspicious shell executions by monitoring processes initiated by systemd, focusing on those with specific characteristics indicative of unauthorized activity.

Possible investigation steps

  • Review the process details to confirm the parent process is indeed systemd and the command line used is "/sbin/init" to ensure the alert is not a false positive.
  • Examine the specific shell process name (e.g., bash, sh, etc.) and its arguments to identify any unusual or suspicious commands being executed.
  • Investigate the history and configuration of the systemd service or unit file associated with the suspicious process to determine if it has been modified or created recently.
  • Check for any recent changes or anomalies in the initramfs or GRUB bootloader configurations that could indicate tampering or unauthorized modifications.
  • Correlate the alert with other security events or logs from the same host to identify any patterns or additional indicators of compromise that might suggest a broader attack or persistence mechanism.

False positive analysis

  • Legitimate system maintenance scripts may trigger this rule if they are executed by systemd during boot. Users can create exceptions for known maintenance scripts by identifying their specific command lines and excluding them from the detection rule.
  • Custom user scripts that are intentionally set to run at boot for automation purposes might be flagged. To handle this, users should document these scripts and adjust the rule to exclude their specific process names or command lines.
  • Some Linux distributions may use shell scripts for legitimate boot-time operations. Users should verify the distribution's default boot scripts and exclude them if they are known to be safe and necessary for system operation.
  • System updates or package installations that modify boot processes could cause false positives. Users should monitor for these events and temporarily adjust the rule to prevent unnecessary alerts during known update windows.

Response and remediation

  • Immediately isolate the affected system from the network to prevent further unauthorized access or lateral movement.
  • Terminate any suspicious shell processes identified as being executed by systemd during boot to halt potential malicious activity.
  • Conduct a thorough review of systemd service files and configurations to identify and remove any unauthorized or malicious entries.
  • Restore any modified system files or configurations from a known good backup to ensure system integrity.
  • Escalate the incident to the security operations team for further investigation and to determine if additional systems are affected.
  • Implement enhanced monitoring on the affected system and similar environments to detect any recurrence of the threat.
  • Review and update access controls and permissions to limit the ability of unauthorized users to modify systemd configurations or execute shell commands during boot.

Related rules

to-top