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.

SeverityHigh
CVSS 3.17.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.08.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
CWECWE-266: Incorrect Privilege Assignment
OWASP Top 10A06:2025 Insecure Design
MITRE ATT&CKT1548.003 Sudo and Sudo Caching
CategoryBroken 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/sudoers and /etc/sudoers.d, editing only with visudo, and remove rules that are no longer needed or that grant ALL to 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 sudoedit for 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_reset enabled (the default), do not add variables such as LD_PRELOAD, LD_LIBRARY_PATH or PYTHONPATH to env_keep, and do not use the SETENV tag.
  • Require the user's password for rules that grant significant privilege, and consider the NOEXEC tag to stop permitted commands starting further commands, bearing in mind that it does not stop them reading or writing files.
  • Keep the sudo package 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 trial  ·  No card required

Only need the reporting? Our reporting tool is free and open source, with the same library.


More Windows and Linux Hosts Findings

Every Windows and Linux Hosts finding