Insecure sudo Configuration
sudo rules let a user run commands as root that can be turned into a full root shell, such as editors, interpreters, writable scripts or wildcard arguments.
| Severity | High |
| CVSS 3.1 | 7.8 CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H Open in the calculator |
| CVSS 4.0 | 8.5 CVSS:4.0/AV:L/AC:L/AT:N/PR:L/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N Open in the calculator |
| CWE | CWE-266: Incorrect Privilege Assignment |
| OWASP Top 10 | A06:2025 Insecure Design |
| MITRE ATT&CK | T1548.003 Sudo and Sudo Caching |
| Category | Broken Access Control |
Description
The sudo policy on the host, in /etc/sudoers and the files under /etc/sudoers.d, lets a user or group run commands as root, or as another privileged account, in a way that grants more than was intended. Many seemingly harmless tools can start a shell, run other commands, or read and write any file: editors such as vi and nano, pagers such as less, interpreters such as python and perl, and utilities such as find, tar, awk, git and package managers. Allowing any of these to run as root is, in effect, allowing a root shell: a user permitted to run such a command can become root and take full control of the host, reading and changing all data on it, including /etc/shadow and other users' SSH keys, installing persistence, disabling logging and security tools, and using the host's trust relationships to reach other systems.
Other common forms are rules that allow ALL commands to accounts that do not need full administration, wildcards in permitted command arguments or paths, rules that run scripts or binaries the user can modify, NOPASSWD on broad rules, and settings that pass environment variables such as LD_PRELOAD through to the command (env_keep or the SETENV tag). Where a rule applies to a service account or to a group with many members, compromise of any of those accounts, for example through a vulnerable web application running as the service account, becomes a root compromise. A rule that requires the user's password protects only as long as that password is not known to the attacker.
The weakness is identified by running sudo -l as each test account, reviewing the sudoers files, and checking the permitted commands against references such as GTFOBins; enumeration scripts such as linPEAS flag likely misconfigurations.
Remediation
Grant each user only the specific commands they need, in a form that cannot be used to escape to a shell:
- Review every rule in
/etc/sudoersand/etc/sudoers.d, editing only withvisudo, and remove rules that are no longer needed or that grantALLto accounts that do not need full administration. - Do not permit editors, pagers, interpreters, general file utilities or package managers to run as root. To let a user edit a root-owned file, grant
sudoeditfor that file rather than an editor. - Specify commands by full path with fixed arguments, avoid wildcards, and permit only scripts and binaries that are owned by root and not writable by anyone else, in directories that others cannot write to.
- Keep
env_resetenabled (the default), do not add variables such asLD_PRELOAD,LD_LIBRARY_PATHorPYTHONPATHtoenv_keep, and do not use theSETENVtag. - Require the user's password for rules that grant significant privilege, and consider the
NOEXECtag to stop permitted commands starting further commands, bearing in mind that it does not stop them reading or writing files. - Keep the
sudopackage up to date and send its logs to central logging.
Confirm the fix by running sudo -l as each affected user and checking that none of the permitted commands can be used to obtain a shell or write arbitrary files.
References
Add This Finding to Your Library
In Pental this write-up is in Settings, Library. Add to my library copies it into your own, rated in your firm's CVSS version, ready to put in your own words.
Free trialYour trial starts when your portal goes live, not when you sign up, so the time you spend setting up does not count. · No card required
Only need the reporting? Our reporting tool is free and open source, with the same library.