PrivEsc with LD_PRELOAD

fx2301

fx2301

Posted on October 15, 2022

PrivEsc with LD_PRELOAD

Why?

You need root access on a Linux host.

When?

You have write access to the file-system, can set environment variables for root, and root runs processes.

How?

  1. Craft a C program with an init function registered with .init_array.
  2. Compile the C program as an .so binary for the matching architecture.
  3. Write the binary to the target host's filesystem.
  4. Set the LD_PRELOAD environment variable.
  5. Wait for or trigger the root process execution.

Example

#include <unistd.h>

void init(int argc, char **argv, char **envp) {
    // PrivEsc hook
}

__attribute__((section(".init_array"))) typeof(init) *__init = init;
Enter fullscreen mode Exit fullscreen mode
💖 💪 🙅 🚩
fx2301
fx2301

Posted on October 15, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

PrivEsc with LD_PRELOAD
ethicalhacking PrivEsc with LD_PRELOAD

October 15, 2022