Skip to main content

Overview

Linux binaries load shared libraries (.so) at runtime. If you can control where libraries are loaded from, you can inject malicious code that runs with the binary’s privileges.

Library Search Order


Writable /etc/ld.so.conf.d/

If writable, add custom library path:
Create malicious library in /tmp/evil/ matching a library name used by a root process.

Writable Library Directories

Check if any configured library path is writable:
If writable → replace existing library or add new one.

RPATH / RUNPATH Injection

Check Binary for RPATH/RUNPATH

Example Output

If /home/user/lib is writable:

Find Libraries the Binary Loads

Create Malicious Library

Compile:
Run SUID binary or wait for root service to execute it.

Missing Shared Library

If a SUID binary or root service tries to load a library that doesn’t exist:

Find Missing Libraries

Example

Find writable directory in search path and create the library:

ld.so.preload

/etc/ld.so.preload is loaded before all other libraries for every binary.

Check Permissions

If writable:
Create evil.so:
Next time any root process runs → payload executes.

ldconfig Abuse

If you can run ldconfig (directly or via sudo):
After adding malicious path to /etc/ld.so.conf.d/ or placing library in existing path, ldconfig rebuilds the cache:

Quick Reference