/***************************************************************************** FunctionFault.c: Interposition library to capture function calls from the libc and attack the system by returning invalid values By: Miguel Torres Computer Science, Mississippi State University September 2003 Based on: Profiling and tracind gynamic library usage via interposition (Timothy Curry) Generation of application level audit data via library interposition (Kuperman and Spafford, 1999) The Thesis work by German Florez at the CCSR at Mississippi State University ******************************************************************************/ #include #include #include #include #include #include #include #include #include #include #include "signal.h" #include // For Random Generation #include "randomlib.h" // Sets the Seeds for the random generator #define RANDOM (double)random()/RAND_MAX //#define RANDOM (double)random((time(NULL))%31328)/RAND_MAX #define INIT_RANDS \ srand(time(NULL)); \ RandomInitialise((int)(time(NULL)*RANDOM)%31328,(int)(time(NULL)*RANDOM)%30081); // Frecuency to attack #define PERCENTAJE 2.0 #define TRUE 1 #define FALSE 0 static int DoProfile=TRUE; #ifdef ATTACK // Attacks the fopen function FILE *fopen(const char *filename, const char *mode) { // data referent to the real function typedef FILE*(*function_type) (const char *filename, const char *mode); static function_type function=NULL; static char* function_name="fopen"; static int first_time=TRUE; FILE *retval; // Search for the next function that fits the especification of function_name if (!function){ function = (function_type) dlsym(RTLD_NEXT,function_name); } // If the profiling is active if (DoProfile){ #ifdef PRINT_OUTPUT printf("_FopenProfiling\n"); fflush(stdout); #endif /* ** Seed the random number generator with the current time ** of day if we haven't done so yet. */ if( first_time ){ first_time = FALSE; // Random Generation INIT_RANDS } if(RandomDouble(0.0,100.0)