Sudo
Suppose for the below examples, the low-privileged user is allowed to run the find
command with sudo privileges
LD_PRELOAD env variable
LD_PRELOAD is an environment variable in Linux that allows you to force the system to load specific shared libraries before any other libraries when running a program.
Example
To exploit the LD_PRELOAD environment variable, look for env_keep+=LD_PRELOAD
from the results of the sudo -l
command.
C code which simply spawns a root shell
shell.c
Using gcc
to compile the C code into a shared object file:
-fPIC
If supported for the target machine, emit position-independent code, suitable for dynamic linking and avoiding any limit on the size of the global offset table.
-shared
Produce a shared object which can then be linked with other objects to form an executable
-nostartfiles
Do not use the standard system startup files when linking
Run the find
command with LD_PRELOAD
set as the previously created shared object file. This essentially executes the C code to spawn the root shell.
Binaries with sudo privileges
Suppose the binary with sudo privilege is /usr/bin/find
Adapted from: https://gtfobins.github.io/gtfobins/find/#sudo
Last updated