Dangerous SUID or SGID Binaries
Executables that can run commands or write files have the SUID or SGID bit set, so any local user can use them to act as root or another privileged account.
| 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-250: Execution with Unnecessary Privileges |
| MITRE ATT&CK | T1548.001 Setuid and Setgid |
| Category | Broken Access Control |
Description
On Linux and other Unix-like systems, an executable with the set-user-ID (SUID) bit runs with the privileges of the file's owner rather than those of the user who starts it, and one with the set-group-ID (SGID) bit runs with the privileges of its group. A small number of system utilities, such as passwd, need this to carry out one narrow task safely. When the bit is set on a root-owned executable that can do more than that, such as a shell, an interpreter, an editor, a file utility such as find or cp, or a debugging tool, any local user can use it to run commands, read files or overwrite files as root.
Any user who can log in to the host or run code on it, including through a compromised service account or web application, can do this and so gain the privileges of the file's owner, usually root, and with them full control of the host: reading and changing all data, harvesting credentials and keys, installing persistence and hiding activity. An SGID executable gives the privileges of its group, which can be enough to read sensitive files or to reach root by another route. No user interaction or special conditions are needed, and public references describe the technique for most common utilities.
The same weakness arises from custom or third-party SUID executables that call other commands without full paths, load libraries from writable locations or trust environment variables or user input, and from SUID utilities with known vulnerabilities. File capabilities such as cap_setuid on an interpreter have the same effect. The weakness is identified by listing SUID and SGID files, for example with find / -perm -4000 -type f and find / -perm -2000 -type f, and capabilities with getcap -r /, then comparing the results with what the distribution installs and checking unusual entries against references such as GTFOBins.
Remediation
Keep the SUID and SGID bits only on executables that need them and are designed for it:
- List every SUID and SGID file on the host and compare the list with what the distribution installs. Remove the bit from anything that does not need elevated privileges (
chmod u-sorchmod g-s), and never set it on shells, interpreters, editors or general utilities as a convenience. Remove unneeded file capabilities withsetcap -r. - Where users need to perform a specific privileged action, grant it through a narrowly scoped
sudorule or a dedicated service rather than a SUID copy of a general-purpose tool. - For custom SUID executables that must remain, review the code: call other commands by full path, set a safe environment, drop privileges as soon as they are no longer needed and validate all input. Keep the file and its directory owned by root and not writable by others.
- Mount file systems that hold user data, temporary files and removable or network media, such as
/tmp,/var/tmp,/homeand NFS mounts, with thenosuidoption so that SUID files placed there are ignored. - Monitor for new SUID and SGID files with file integrity monitoring or a scheduled comparison against a known list, and keep packages that include SUID utilities up to date.
Confirm the fix by repeating the search and checking that every remaining SUID or SGID file is expected and cannot be used to run commands or write files as its owner.
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.