Skip to content

Latest commit

 

History

History
124 lines (69 loc) · 3.54 KB

T1166.md

File metadata and controls

124 lines (69 loc) · 3.54 KB

T1166 - Setuid and Setgid

When the setuid or setgid bits are set on Linux or macOS for an application, this means that the application will run with the privileges of the owning user or group respectively (Citation: setuid man page). Normally an application is run in the current user’s context, regardless of which user or group owns the application. 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].

An adversary can take advantage of this to either do a shell escape or exploit a vulnerability in an application with the setsuid or setgid bits to get code running in a different user’s context. Additionally, adversaries can use this mechanism on their own malware to make sure they're able to execute in elevated contexts in the future (Citation: OSX Keydnap malware).

Atomic Tests


Atomic Test #1 - Make and modify binary from C source

Make, change owner, and change file attributes on a C source code file

Supported Platforms: macOS, Linux

Inputs:

Name Description Type Default Value
payload hello.c payload path PathToAtomicsFolder/T1166/src/hello.c

Attack Commands: Run with sh! Elevation Required (e.g. root or admin)

cp #{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

Cleanup Commands:

sudo rm /tmp/hello
sudo rm /tmp/hello.c


Atomic Test #2 - Set a SetUID flag on file

This test sets the SetUID flag on a file in Linux and macOS.

Supported Platforms: macOS, Linux

Inputs:

Name Description Type Default Value
file_to_setuid Path of file to set SetUID flag path /tmp/evilBinary

Attack Commands: Run with sh! Elevation Required (e.g. root or admin)

sudo touch #{file_to_setuid}
sudo chown root #{file_to_setuid}
sudo chmod u+s #{file_to_setuid}

Cleanup Commands:

sudo rm #{file_to_setuid}


Atomic Test #3 - Set a SetGID flag on file

This test sets the SetGID flag on a file in Linux and macOS.

Supported Platforms: macOS, Linux

Inputs:

Name Description Type Default Value
file_to_setuid Path of file to set SetGID flag path /tmp/evilBinary

Attack Commands: Run with sh! Elevation Required (e.g. root or admin)

sudo touch #{file_to_setuid}
sudo chown root #{file_to_setuid}
sudo chmod g+s #{file_to_setuid}

Cleanup Commands:

sudo rm #{file_to_setuid}