7.-Special-permissions
Last updated
Last updated
Setuid/Setgid Enumeration
Check (Manual - Check each binary against GTFObins)
Example: If /usr/bin/vim
has the setuid bit:
Check GTFObins for "vim"
setuid (Set User ID):
When a file has the setuid
bit set, it executes with the effective user ID of the file's owner, not the user who runs it.
If the owner is root, the program runs with root privileges.
Represented by an "s" in the owner's execute permissions (e.g., -rwsr-xr-x
).
Command to find setuid files owned by root:
setgid (Set Group ID):
Similar to setuid
, but it sets the effective group ID to the file's group owner.
Useful for giving users temporary access to group-owned resources.
Represented by an "s" in the group's execute permissions (e.g. -rwxr-sr-x
).
Command to find setgid files owned by root:
If a setuid
binary owned by root has a vulnerability, a regular user can exploit it to gain root privileges.
Common vulnerabilities include:
Buffer overflows.
Format string vulnerabilities.
Unsafe use of system calls.
Path abuse.
setgid
can be used to gain the groups privileges.
GTFOBins (gtfobins.github.io) is a curated list of Unix binaries that can be used to bypass security restrictions in misconfigured systems.
It provides examples of how to:
Escape restricted shells.
Escalate privileges.
Spawn shells.
Transfer files.
The example given, using apt-get, is a very strong example of how GTFObins can be used.
The key to using GTFObins is to enumerate the binaries that are on a target system, and then to check if those binaries have any exploits within GTFObins.
Important Considerations
Security Risk: setuid
and setgid
can be significant security risks if not configured carefully.
Minimal Privileges: Always follow the principle of least privilege. Only grant the necessary permissions.
Regular Audits: Regularly audit setuid
and setgid
files to identify and mitigate potential risks.
Code Review: If custom setuid
or setgid
programs are developed, conduct thorough code reviews to ensure they are secure.
When finding a setuid or setgid binary, always check if it is within GTFObins.
In essence, setuid
and setgid
are powerful tools that must be used with caution. GTFObins is an essential resource for penetration testers and security professionals to identify and exploit misconfigurations related to these permissions.