How can a legitimate-looking image hide a backdoor using LD_PRELOAD, and what is the defence?
A Dockerfile sets ENV LD_PRELOAD=/path/reverse_shell.so, so the malicious shared library is loaded into every program the container runs, opening a reverse shell. Defend by only running images from trusted, verified publishers.
LD_PRELOAD is a Linux environment variable that forces the dynamic linker to load a given shared library before all others, letting it hook or run code in any dynamically-linked program that starts. An attacker rebuilds a normal image (say Ubuntu), adds their own .so and an ENV LD_PRELOAD=… line, and re-tags it with the original name. The image behaves normally, but every command also triggers the preloaded library — here, a reverse shell back to the attacker's listener.
The point of the exercise is the supply-chain trust problem: the victim finds this "special version" on a registry, pulls it, runs it, and is compromised — no perimeter was breached, the malicious code was invited in.
Defences:
- Pull only Docker Official Images, Verified Publisher images, or your own builds.
- Inspect the Dockerfile and
docker image historybefore trusting an image. - Verify signatures / use hardened images, and scan images for anomalies.
- Run containers non-root with dropped capabilities so a backdoor that does fire is contained.
Go deeper:
Wikipedia: Dynamic linker (LD_PRELOAD) — how LD_PRELOAD forces a library into every dynamically-linked program.
Docker Docs: Trusted content — the Official/Verified labels that counter blind image trust.