Shared Libraries
Last updated
Last updated
The LD_PRELOAD environment variable is used to specify one or more shared libraries (.so files) to be loaded by the loader before all others, including the standard C library (libc.so
). This process is known as preloading a library.
However, to maintain system security and prevent this feature from being exploited, particularly with suid/sgid executables, the system enforces certain conditions:
The loader disregards LD_PRELOAD for executables where the real user ID (ruid) does not match the effective user ID (euid).
For executables with suid/sgid, only libraries in standard paths that are also suid/sgid are preloaded.
Privilege escalation can occur if you have the ability to execute commands with sudo
and the output of sudo -l
includes the statement env_keep+=LD_PRELOAD. This configuration allows the LD_PRELOAD environment variable to persist and be recognized even when commands are run with sudo
, potentially leading to the execution of arbitrary code with elevated privileges.
For example: This user has rights to use openssl as root, but since this is NOT
a and the /etc/sudoers
entry is written specifying the absolute path, this could not be used to escalate privileges under normal circumstances. However, we can exploit the LD_PRELOAD
issue to run a custom shared library file.