Currently viewing ATT&CK v7.2 which was live between July 8, 2020 and October 26, 2020. Learn more about the versioning system or see the live site.
Register to stream the next session of ATT&CKcon Power Hour November 12

Abuse Elevation Control Mechanism: Setuid and Setgid

An adversary may perform shell escapes or exploit vulnerabilities in an application with the setsuid or setgid bits to get code running in a different user’s context. On Linux or macOS, when the setuid or setgid bits are set for an application, the application will run with the privileges of the owning user or group respectively. [1]. 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 doesn’t need the elevated 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. These bits are indicated with an "s" instead of an "x" when viewing a file's attributes via ls -l. The chmod program can set these bits with via bitmasking, chmod 4777 [file] or via shorthand naming, chmod u+s [file].

Adversaries can use this mechanism on their own malware to make sure they're able to execute in elevated contexts in the future.[2].

ID: T1548.001
Sub-technique of:  T1548
Tactics: Privilege Escalation, Defense Evasion
Platforms: Linux, macOS
Permissions Required: User
Data Sources: File monitoring, Process command-line parameters, Process monitoring
Version: 1.0
Created: 30 January 2020
Last Modified: 27 March 2020

Procedure Examples

Name Description
Keydnap

Keydnap adds the setuid flag to a binary so it can easily elevate in the future.[2]

Mitigations

Mitigation Description
Operating System Configuration

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.

Detection

Monitor the file system for files that have the setuid or setgid bits set. Monitor for execution of utilities, like chmod, and their command-line arguments to look for setuid or setguid bits being set.

References