Note
web
php
ld-preload
mail
shared-object
rce
putenv
Spawn an external binary via mail() with attacker-controlled LD_PRELOAD to load a malicious shared object even when PHP functions are restricted.
LD_PRELOAD + mail() + symlink to a .so
Even if PHP's dangerous functions are mostly restricted, spawning an external binary through mail()
can still inherit attacker-controlled environment variables. LD_PRELOAD then loads an attacker .so
before the target binary starts. The write primitive only needs to land a shared object somewhere
readable by the process; a symlink can make path placement easier.
Why It Works
mail()invokessendmail, which inherits the PHP process environment — including aputenv-setLD_PRELOAD.
Vulnerable Pattern
- PHP with
putenv,symlink, andmail()still available, plus a writable path where a.socan be uploaded or smuggled.
Exploit Flow
- Confirm
mail()truly reaches a system binary such assendmail. - Place the shared object in a stable path, or symlink from a predictable runtime directory to the upload location.
- Set
LD_PRELOAD, triggermail(), and make the library perform a simple side effect (write a file).
Variations
- If
mail()is unavailable, test other binary-launching functions or extension-loading paths.
Common Blockers
- Hardened runtimes stripping environment variables, PIE / loader mismatches, or no writable place for
the
.so.
PoC Sketch
symlink('/var/www/html/public/shared_notes/hook.so','/run/apache2/socks/hook.so');
putenv('LD_PRELOAD=/run/apache2/socks/hook.so');
mail('a@b.c','x','y');
Good Situations To Use It
putenv,symlink, andmail()are still enabled.- You can write a
.soto a readable path. - Classic PHP RCE functions are disabled.
Sources
fcsc2026/web/secure_mood_notes_2