Carlos Aguni

Highly motivated self-taught IT analyst. Always learning and ready to explore new skills. An eternal apprentice.


C LD_PRELOAD

13 Jul 2021 »

https://stackoverflow.com/questions/25812181/is-it-possible-to-override-main-method-using-ld-preload

#include <stdio.h>

int main (void)
{
  puts("Hello, world!");
  return 0;
}
#include <stdio.h>

int puts (const char *s)
{
  return printf("Hijacked puts: %s\n", s);
}
gcc -o puts.so -shared -fPIC puts.c
gcc main.c -o main
LD_PRELOAD=./puts.so ./main
#Hijacked puts: Hello, world!