Linux Sudoers File Modification for Persistence and Privilege Escalation
Adversaries manipulate the /etc/sudoers file or /etc/sudoers.d/ directory to establish persistence and gain unauthorized elevated privileges on Linux systems.
Adversaries targeting Linux environments often seek to gain and maintain elevated privileges by modifying the sudoers configuration files. The sudoers file, located at /etc/sudoers, and the directory /etc/sudoers.d/ control user access to the sudo command. By injecting custom configuration lines, an attacker can grant their user account passwordless root execution, essentially providing a persistent backdoor with administrative access. This technique is observed in various malware kits, such as the TripleCross rootkit, which utilizes modification of these files to ensure persistence. Defenders must distinguish between authorized changes made by configuration management tools (like Ansible or Chef) or system package updates and unauthorized modifications that indicate malicious intent.
Attack Chain
- Attacker gains initial access to a Linux system via an exploit or stolen credentials.
- Attacker enumerates current user privileges and sudoers configuration files.
- Attacker identifies the target sudoers file or a sub-file within /etc/sudoers.d/ for modification.
- Attacker writes malicious configuration strings (e.g., "user ALL=(ALL) NOPASSWD: ALL") to the target file.
- Attacker leverages file integrity monitoring or system tools to persist changes.
- Attacker executes commands using sudo without needing to provide a password.
- Final objective is achieved, such as long-term persistence or data exfiltration as root.
Impact
Successful modification of sudoers files results in complete system compromise, allowing an attacker to maintain persistent, passwordless administrative access. This enables full control over the host, potential lateral movement, and unmonitored exfiltration of sensitive data.
Recommendation
- Deploy the provided Sigma rule to monitor file modifications to /etc/sudoers and the /etc/sudoers.d/ directory.
- Establish a baseline for authorized configuration management tools (e.g., SaltStack, Puppet, Ansible) that legitimately modify these files to reduce false positives.
- Audit existing sudoers configuration files for unauthorized "NOPASSWD" directives or unfamiliar user entries.
- Enable file integrity monitoring (FIM) on /etc/sudoers and /etc/sudoers.d/ to alert on any changes in real-time.
Immediate actions
Deploy Sigma rule to monitor sudoers file changes
Threat Hunt
Search for existing NOPASSWD entries in all /etc/sudoers.d/ files
Data: File content snapshots
Mitigations
Restrict write access to /etc/sudoers and /etc/sudoers.d/ to root only
T1548.003
Detection coverage 1
Detect Modification of Sudoers Configuration Files
mediumDetects the creation or modification of the main /etc/sudoers file or files within the /etc/sudoers.d/ directory.
Detection queries are available on the platform. Get full rules →