Page cover

Sudo Privilege Escalation by Overriding Shared Library

LD_PRELOAD and LD_LIBRARY_PATH might be vulnerable to privilege escalation (PrivEsc).

Check sudo commands.

sudo -l
Copied!

The below is the output example.

env_keep+=LD_PRELOAD

(ALL : ALL) NOPASSWD: somecmd
Copied!

If we find the sudo command keeps LD_PRELOAD environment, we can overwrite this variable to load our custome shared object and escalate the privileges.

Also, we can replace the LD_PRELOAD with LD_LIBRARY_PATH.

By the way, to list shared libraries required by the executable, use ldd command.

ldd somecmd
Copied!

First off, create exploit.c under /tmp .

  • The "constructor" attribute is a special type of function attribute in GCC. It tells the compiler to automatically call the function before the main function.

Now compile the c program to shared object.

We can execute command with setting the shared library to LD_PRELOAD variable then spawn the root shell.

Last updated