πShared Libraries
π― Overview
LD_PRELOAD environment variable allows loading custom shared libraries before program execution, enabling privilege escalation when combined with sudo configurations that preserve environment variables.
π Prerequisites
Check for LD_PRELOAD in Sudo
# Check sudo configuration
sudo -l
# Look for env_keep+=LD_PRELOAD in output:
# env_keep+=LD_PRELOAD
# Example vulnerable entry:
# (root) NOPASSWD: /usr/sbin/apache2 restartLibrary Dependencies Analysis
# View shared library dependencies
ldd /bin/ls
ldd /usr/sbin/apache2
# Check LD_PRELOAD current value
echo $LD_PRELOADπ LD_PRELOAD Exploitation
Create Malicious Library
Compile Shared Library
Execute Privilege Escalation
π§ Alternative Payloads
Reverse Shell Library
SUID Binary Creation
π Detection & Enumeration
LD_PRELOAD Vulnerability Check
Environment Variable Analysis
π Quick Reference
Immediate Checks
Emergency Exploitation
HTB Academy Example
β οΈ Exploitation Requirements
Must Have
Sudo access to any command (even non-GTFOBin)
env_keep+=LD_PRELOAD in sudoers configuration
GCC compiler available on target system
Write permissions in accessible directory
Common Scenarios
Non-exploitable sudo commands with LD_PRELOAD kept
Service restart permissions (apache, nginx, etc.)
Safe commands made dangerous by LD_PRELOAD
Custom applications with sudo permissions
LD_PRELOAD exploitation transforms safe sudo commands into privilege escalation vectors - environment variable preservation combined with shared library injection bypasses command restrictions for immediate root access.
Last updated