Detection of Privilege Escalation via Unauthorized Sudoers Modification
Adversaries may attempt to gain elevated privileges on Unix-like systems by using the echo command to inject NOPASSWD directives into the sudoers file, allowing passwordless execution of commands as root.
What's new
- 1. OS linux; OS macos Sep 19, 13:18 via elastic
Adversaries targeting Linux and macOS environments frequently attempt to achieve persistent privilege escalation by manipulating system configuration files. A common technique involves modifying the /etc/sudoers file to grant specific users or groups passwordless sudo access. By leveraging the echo command, an attacker can append a line containing the NOPASSWD: ALL directive to the sudoers file or a file within the sudoers.d directory. This configuration change effectively bypasses authentication requirements for elevated operations, granting the attacker persistent root-level command execution capabilities. Defenders should monitor for suspicious execution patterns involving the echo utility directed toward sensitive system configuration files.
Attack Chain
- Attacker gains initial user-level access on a Linux or macOS system.
- Attacker identifies a target user account or group for privilege escalation.
- Attacker uses the echo command to craft a line containing the NOPASSWD: ALL configuration directive.
- Attacker redirects or appends the output of the echo command into the /etc/sudoers file or a file located in /etc/sudoers.d/.
- The system configuration is updated, granting the specified user unrestricted, passwordless sudo privileges.
- Attacker executes a command via sudo to confirm the bypass of authentication prompts.
- Attacker proceeds to perform further post-exploitation activities, such as exfiltration or lateral movement, with elevated permissions.
Impact
Successful exploitation allows unauthorized users to execute commands with root privileges without providing a password. This enables complete system compromise, persistent backdoor creation, and potential lateral movement across the internal network.
Recommendation
Deploy the Sigma rule provided in this brief to detect suspicious sudoers modifications. Audit current /etc/sudoers and /etc/sudoers.d/ configurations to ensure only authorized users have elevated access. Implement rigorous logging of modifications to critical system files using tools like auditd or file integrity monitoring (FIM) solutions.
Immediate actions
Deploy the Sigma rule to monitor for echo-based modifications of sudoers files.
Threat Hunt
Search command history for echo commands redirecting to /etc/sudoers or /etc/sudoers.d/
Data: Process command line arguments
Mitigations
Restrict write access to /etc/sudoers and /etc/sudoers.d/ to root only.
T1548.003
Detection coverage 1
Detect Potential Privilege Escalation via Sudoers Modification
highDetects the use of echo to append NOPASSWD directives to sudoers configuration files, a common technique for privilege escalation.
Detection queries are available on the platform. Get full rules →