rendered paste body#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
static void init (void) __attribute__ ((constructor));
int stat(const char *path, struct stat *buf);
int fstat(int filedes, struct stat *buf);
int lstat(const char *path, struct stat *buf);
static void init (void)
{
fprintf(stderr,"lib loaded\n");
}
int lstat(const char *path, struct stat *buf)
{
fprintf(stderr,"LSTAT\n");
return 0;
}
int stat(const char *path, struct stat *buf)
{
fprintf(stderr,"STAT\n");
return 0;
}
int fstat(int filedes, struct stat *buf)
{
fprintf(stderr, "FSTAT\n");
return 0;
}
######################################################################
#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
int main ()
{
struct stat buffer;
int status;
printf("lstat: %d\n", stat("./dontexitsts", &buffer));
}
#####################################################################
willem[preload]$ gcc -fPIC -shared -o lib.so lib.c
willem[preload]$ LD_PRELOAD="./lib.so" ./a.out
lib loaded
lstat: -1
lstat should return 0 as it got hijacked, but doesnt seems so ...