I am trying to inject a SO into a process that starts using systemd init system (using LD_PRELOAD), but it does not loaded into the new process.
I complied a basic SO (unrandom.c):
int rand(){
return 42; //the most random number in the universe
}
with the command line:
gcc -shared -fPIC unrandom.c -o unrandom.so
I changed the .service file to include:
Environment="LD_PRELOAD=/tmp/unrandom.so"
After starting the service the LD_PRELOAD environment variable is exist in the process, but the SO does not injected
cat /proc/<PID>/maps
Am I missing something?
My machine is RHEL7
Setuid processes restrict usage of LD_PRELOAD
(and some other env. variables) due to security reasons.
Loaded library must be specified via name only and be located in one of the directories listed in /etc/ld.so.conf
(see e.g. this link). For example on Debian-based systems
sudo cp library.so /usr/lib/x86_64-linux-gnu
LD_PRELOAD=library.so daemon
Another approach is to put full path to library to /etc/ld.so.preload
:
sudo echo path/to/library.so >> /etc/ld.so.preload
but then it'll be preloaded to all new processes (which has a high chance of breaking your system if you are not extremely careful).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With