@amasad/

monkey-patching

bash

demos monkey patching libc read

fork
loading
Files
  • main.sh
  • inject.c
  • inject.so
  • main.c
  • out

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.5841057265509393","path":"main.sh","file":{"path":"main.sh","content":{"asEncoding":{"base64":"Z2NjIC1zaGFyZWQgLWZQSUMgLW8gaW5qZWN0LnNvIGluamVjdC5jCmdjYyBtYWluLmMgLW8gb3V0CmVjaG8gIndpdGhvdXQgTERfUFJFTE9BRCIKLi9vdXQKZWNobyAid2l0aCBMRF9QUkVMT0FEIgpMRF9QUkVMT0FEPSRQV0QvaW5qZWN0LnNvIC4vb3V0CgojIHNlZSBodHRwOi8vd3d3LmdvbGRzYm9yb3VnaC5tZS9jL2xvdy1sZXZlbC9rZXJuZWwvMjAxNi8wOC8yOS8xNi00OC01My10aGVfLWxkX3ByZWxvYWQtX3RyaWNrLw=="},"asBuffer":null},"loaded":true}}
1
2
3
4
5
6
7
8
gcc -shared -fPIC -o inject.so inject.c
gcc main.c -o out
echo "without LD_PRELOAD"
./out
echo "with LD_PRELOAD"
LD_PRELOAD=$PWD/inject.so ./out

# see http://www.goldsborough.me/c/low-level/kernel/2016/08/29/16-48-53-the_-ld_preload-_trick/