Understanding SUID
In this step, you will understand the concept of SUID permission and its implications.
Typically, when a program is executed on Linux, it runs with the permissions of the current user. However, some programs, like cp
, require elevated privileges to perform certain operations, such as copying files to restricted directories. To allow regular users to execute such programs with elevated privileges, the SUID permission can be set on the executable file.
SUID stands for "Set user ID upon execution." When a file has the SUID permission set, it executes with the permissions of its owner, regardless of the user executing it. For example, the cp
command is owned by the root user and has the SUID bit set, allowing any user to execute it with root privileges.
To check the SUID permission on the cp
command and save the output to a file, run the following command:
ls -l /usr/bin/cp > /home/labex/project/suid_cp.txt
View the contents of the suid_cp.txt
file using the following command:
cat /home/labex/project/suid_cp.txt
Expected output:
-rwsr-xr-x 1 root root 141832 Feb 8 2024 /usr/bin/cp
You should see an s
in the permission bits, indicating the SUID permission.
While SUID can be useful for allowing regular users to run specific privileged commands, it can also be exploited if the SUID binary provides functionality for executing system commands or modifying files.