Linux MOTD Script Persistence Technique
Attackers can achieve persistence or privilege escalation by creating or modifying scripts in the '/etc/update-motd.d/' directory, which execute automatically upon user login.
The '/etc/update-motd.d/' directory on Linux systems allows administrators to define scripts that generate the Message of the Day (MOTD), a text banner displayed to users upon successful remote login via SSH. Because these scripts are executed with the privileges of the system or the logging-in user, they represent a significant persistence vector. Attackers who gain sufficient privileges to modify files in this directory can insert malicious code that triggers during subsequent logins. This technique is particularly effective as it allows for the execution of payloads, lateral movement tools, or backdoors without requiring specialized rootkit software, making it a common choice for post-exploitation persistence. Defenders should treat any unauthorized file creation or modification in this directory as a high-fidelity indicator of a potential compromise.
Attack Chain
- Attacker gains initial access or a foothold on the target Linux system through an exploit or credential theft.
- Attacker performs local enumeration to identify the user's current shell and existing system configurations.
- Attacker identifies the '/etc/update-motd.d/' directory as a target for persistence.
- Attacker checks write permissions on the directory or existing scripts using standard tools like 'ls -l'.
- Attacker creates a new script or modifies an existing script within '/etc/update-motd.d/' containing malicious commands (e.g., a reverse shell).
- Attacker ensures the malicious file has the necessary execute permissions (e.g., 'chmod +x').
- A legitimate user (often a system administrator) logs into the server via SSH.
- The PAM (Pluggable Authentication Modules) framework executes the scripts in '/etc/update-motd.d/', triggering the attacker's payload.
Impact
Successful exploitation of this technique leads to persistent unauthorized access to the affected Linux system. This can be used to exfiltrate sensitive data, maintain long-term access for data theft, or provide a staging point for further lateral movement within the network. In scenarios where a root user logs in, the attacker can achieve persistent root-level execution.
Recommendation
- Deploy the provided Sigma rule to detect file modifications within '/etc/update-motd.d/'.
- Audit all current files within '/etc/update-motd.d/' to ensure they match approved system configuration and are signed or monitored for changes.
- Enable Sysmon for Linux or equivalent EDR telemetry (Event ID 11) to monitor file system activity in system directories.
- Implement file integrity monitoring (FIM) on '/etc/update-motd.d/' to alert on any unauthorized modifications.
Immediate actions
Deploy the Sigma rule provided in this brief.
Mitigations
Restrict write access to /etc/update-motd.d/ to authorized accounts only.
T1547
Detection coverage 1
Detect Linux MOTD Script Addition or Modification
mediumDetects the creation or modification of files within /etc/update-motd.d/, a common persistence technique on Linux systems.
Detection queries are available on the platform. Get full rules →