Run Program with Preloading Libraries without Using LD_PRELOAD Nov 1st 2021 Words: 133

Background

Setting LD_PRELOAD variable can define custom libraries to load before running a program. This variable is used by utilities such as proxychains to hook up network related functions. However, some applications may refuses to run if LD_PRELOAD variable is presented, as an anti-hacking trick maybe.

Solution

Use ld-linux to load the program with preloading libraries without setting the environment variable. man page

1
LD_PRELOAD="" /lib64/ld-linux-x86-64.so.2 --preload /usr/lib/x86_64-linux-gnu/libproxychains.so.4 /usr/bin/curl https://www.google.com

Note that the process must be passed as a path.

proxychains example:

1
sudo proxychains bash -c 'LD_PRELOAD="" /lib64/ld-linux-x86-64.so.2 --preload /usr/lib/x86_64-linux-gnu/libproxychains.so.4 /usr/bin/curl https://www.google.com'