Install any skill in seconds. Free to start, no credit card required.
Get Started Free →An adversary may abuse configurations where an application has the setuid or setgid bits set in order to get code running in a different (and possibly more privileged) user’s context.
| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-01 | ✗→✓ | ▲ Improved | 21% | 0% |
| case-08 | ✗→✓ | ▲ Improved | 123% | 0% |
| case-09 | ✗→✓ | ▲ Improved | 254% | 0% |
| case-10 | ✗→✓ | ▲ Improved | 71% | 0% |
| case-11 | ✗→✓ | ▲ Improved | 128% | 0% |
> Sub-technique of: T1548
An adversary may abuse configurations where an application has the setuid or setgid bits set in order to get code running in a different (and possibly more privileged) user’s context. On Linux or macOS, when the setuid or setgid bits are set for an application binary, the application will run with the privileges of the owning user or group respectively. Normally an application is run in the current user’s context, regardless of which user or group owns the application. However, there are instances where programs need to be executed in an elevated context to function properly, but the user running them may not have the specific required privileges.
Instead of creating an entry in the sudoers file, which must be done by root, any user can specify the setuid or setgid flag to be set for their own applications (i.e. Linux and Mac File and Directory Permissions Modification). The <code>chmod</code> command can set these bits with bitmasking, <code>chmod 4777 file]</code> or via shorthand naming, <code>chmod u+s file]</code>. This will enable the setuid bit. To enable the setgid bit, <code>chmod 2775</code> and <code>chmod g+s</code> can be used.
Adversaries can use this mechanism on their own malware to make sure they're able to execute in elevated contexts in the future. This abuse is often part of a "shell escape" or other actions to bypass an execution environment with restricted permissions.
Alternatively, adversaries may choose to find and target vulnerable binaries with the setuid or setgid bits already enabled (i.e. File and Directory Discovery). The setuid and setguid bits are indicated with an "s" instead of an "x" when viewing a file's attributes via <code>ls -l</code>. The <code>find</code> command can also be used to search for such files. For example, <code>find / -perm +4000 2>/dev/null</code> can be used to find files with setuid set and <code>find / -perm +2000 2>/dev/null</code> may be used for setgid. Binaries that have these bits set may then be abused by adversaries.
Platforms: Linux, macOS
The following tests are from Atomic Red Team and provide actionable ways to test this technique:
Make, change owner, and change file attributes on a C source code file
Supported Platforms: macos, linux Elevation Required: Yes
bashcp #{payload} /tmp/hello.c sudo chown root /tmp/hello.c sudo make /tmp/hello sudo chown root /tmp/hello sudo chmod u+s /tmp/hello /tmp/hello
Make, change owner, and change file attributes on a C source code file
Supported Platforms: linux Elevation Required: Yes
bashcp #{payload} /tmp/hello.c chown root /tmp/hello.c make /tmp/hello chown root /tmp/hello chmod u+s /tmp/hello /tmp/hello
This test sets the SetUID flag on a file in FreeBSD.
Supported Platforms: macos, linux Elevation Required: Yes
bashsudo touch #{file_to_setuid} sudo chown root #{file_to_setuid} sudo chmod u+xs #{file_to_setuid}
This test sets the SetUID flag on a file in FreeBSD.
Supported Platforms: linux Elevation Required: Yes
bashtouch #{file_to_setuid} chown root #{file_to_setuid} chmod u+xs #{file_to_setuid}
This test sets the SetGID flag on a file in Linux and macOS.
Supported Platforms: macos, linux Elevation Required: Yes
bashsudo touch #{file_to_setuid} sudo chown root #{file_to_setuid} sudo chmod g+xs #{file_to_setuid}
If Atomic Red Team tests are not applicable, manually verify the technique by:
Applications with known vulnerabilities or known shell escapes should not have the setuid or setgid bits set to reduce potential damage if an application is compromised. Additionally, the number of programs with setuid or setgid bits set should be minimized across a system.
| Finding | Severity | Impact | | -------------------------------------- | -------- | -------------------- | | Setuid and Setgid technique applicable | High | Privilege Escalation |
| CWE ID | Title | | ------- | ----------------------------- | | CWE-269 | Improper Privilege Management |
Other measured skills in the registry, with their headline benchmark lift.