Skip to content

Latest commit

 

History

History
55 lines (34 loc) · 1.37 KB

File metadata and controls

55 lines (34 loc) · 1.37 KB
description cover coverY
10/30/2023
59

🔃 LD_PRELOAD

"As if this stuff can't get any cooler..."

In Linux, LD_PRELOAD is an environment variable that allows us to be able to manipulate which library is used at runtime for a binary.

  • In other words, force a binary to use a specific library

This allows us to be able to change program behavior, how certain functions work, and logic.

Preeny, pre-existing pwn libraries for LD_PRELOAD

{% embed url="https://github.com/zardus/preeny" %}

How-to: LD_PRELOAD

  1. Write your own library:

library.h:

#include <stdio.h>

foo bar(arg1, arg2)

{
    return 0;
}
  1. Compile and set LD_LIBRARY_PATH variable to current directory:
cc -o <library.hso> -shared library.c -ldl

LD_LIBRARY_PATH=./$LD_LIBRARY_PATH

a library.so file will be created, this is our shared library that we want our binary to use.

  1. Set the LD_PRELOAD environment variable to the compiled shared library and execute the program with our LD_PRELOAD:
LD_PRELOAD=library.so ./<target_binary>

This will force our target binary to use our newly created shared library.

Ultimately, changing the binary's behavior.