5.2.2 SUID Exploitation
SUID Exploitation
r=read, w=write, x=execute
rwx rwx rwx
user group others
421 421 421
4+2+1=7 4+2+1=7 4+2+1=7
chmod 777 #Maximum privilegesSuid Exploits (PoC)
CP Command
Infact, if I try to use: find / -perm -u=s -type f 2>/dev/null there's not cp path (or in alternative see permissions of ls -al command_path_name). If we want to assign SUID permission at cp command, we need to use chmod u+s (path of cp command):
Now, every users can execute cp command with root permissions!
Then, we can execute the same sequence of commands regarding cp of /etc/passwd using new_user account user:
The idea is to add a new user with root permissions and not only for cp command.
Using openssl passwd we generate a password with MD5 algorithm (option -1) and custom salt
Then, construct our costum account string to append in /etc/passwd file based on this format:
<username>:<hash>:0:0:0:root:/root:/bin/bash
Add it in our local copy of /etc/passw using vim or nano or copy it in original file:
Finally we can log into new_root_user and have root privileges.
GTFOBins
In alternative we can do privilege escalation using commands present on GTFOBins site regarding cp command in the section of SUID:
FIND Command
In the wake of the previous example, we proceed with the find command, using the same normal user (new_user).
To do privilege escalation we only need to file an existing file using find command:
GTFOBins
in alternative we can do privilege escalation using commands present on GTFOBins site regarding find command in the section of SUID:
NANO Command
As the last case, we do this sequence of command to do NANO SUID exploitation:
Now, we can open file with root permissions like as /etc/passwd with a normal user using nano:
As the example of Copy SUID, the idea is to add a new user with root permissions and not only for nano command.
Using openssl passwd we generate a password with MD5 algorithm (option -1) and custom salt
Then, construct our costum account string to append in /etc/passwd file based on this format:
<username>:<hash>:0:0:0:root:/root:/bin/bash
Add it in our local copy of /etc/passw using vim or nano or copy it in original file:
Finally we can log into new_root_user and have root privileges.
GTFOBins
in alternative we can do privilege escalation using commands present on GTFOBins site regarding nano command in the section of SUID:
RIGHT Command
Sudoers file can cantoins users with a specific root permission called SUDO Rights, e.g. new_user ca execute find command as root:
To do privilege escalation we only need to file an existing file using find command:
Can we do the same for others command, e.g. vi command:
It's possible to do the same for more command such as: man, python, nano, vim, etc.




