SUID and SGID exploits¶
Become root on Linux via SUID:
List files that have SUID or SGID bits set
Exploit
Example: nano¶
Crack passwords file¶
List files that have
SUIDorSGIDbits set:
find / -type f -perm -04000 -ls 2>/dev/null
Compare these executables with GTFOBins SUID. The nano text editor has the SUID bit set
Read
/etc/passwdand/etc/shadowusing nano.Copy contant to local
passwd.txtrespshadow.txtfiles.Use the
unshadowtool to create a file crackable by John the Ripper
unshadow passwd.txt shadow.txt > passwords.txt
Add a user¶
The other option would be to add a new user that has root privileges.
Using the
openssltool, create a password hash for a new user:
openssl passwd -1 -salt <password>
Add this password with a username to the
/etc/passwdfile. Useroot:/bin/bashto give this user a root shell.Switch to this user.
Notes¶
SUID (Set-user Identification) and SGID (Set-group Identification) allow files to be executed with the permission level of the file owner or the group owner, respectively.
Such files have an s bit set showing their special permission level. To find binaries known to be exploitable when the SUID bit is set see GTFObins SUID.