LD_PRELOAD not loading on systemd

I am trying to inject SO into a process that starts using systemd init system (using LD_PRELOAD), but it does not load into the new process.

I have done basic SO (unrandom.c):

int rand(){ return 42; //the most random number in the universe } 

with command line:

 gcc -shared -fPIC unrandom.c -o unrandom.so 

I modified the .service file to include:

 Environment="LD_PRELOAD=/tmp/unrandom.so" 

After starting the service in the process, the LD_PRELOAD environment variable exists, but SO does not enter

 cat /proc/<PID>/maps 

Am I missing something?

My car is RHEL7

+6
source share
1 answer

Setuid processes limit the use of LD_PRELOAD (and some other variables) due to security concerns.

The loaded library should be specified only by name and be in one of the directories listed in /etc/ld.so.conf (see, for example, 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 the full library path to /etc/ld.so.preload :

 sudo echo path/to/library.so >> /etc/ld.so.preload 

but then it will be preloaded to all new processes (which has a high probability of hacking the system if you are not very careful).

+2
source

All Articles