# LD_PRELOAD hooking


# grep -m 1 localtime /usr/include/time.h
extern struct tm *localtime (__const time_t *__timer) __THROW;
# cat newdate.c
#define _GNU_SOURCE
#include <stdio.h>
#include <time.h>
#include <dlfcn.h>

struct tm *(*orig_localtime)(const time_t *timep);

struct tm *localtime(const time_t *timep){
        time_t t=946684860;
        return orig_localtime(&t);
}

void _init(void){
        orig_localtime=dlsym(RTLD_NEXT,"localtime");
}
# gcc -Wall -fPIC -o newdate.o -c newdate.c
# ld -shared -o newdate.so newdate.o -ldl
# date
Thu Jan 10 13:35:30 CET 2013
# LD_PRELOAD=./newdate.so date
Sat Jan  1 01:01:00 CET 2000

No comments: