/***************************************************************************** corruotingData.c: Interposition library to capture function calls from the libc and attack the system by corrupting data thta is stored or taked from a file using the fwrite and fread functions, and corrupoting data in when the malloc operation is called By: Miguel Torres Computer Science, Mississippi State University July 2002 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 #define TRUE 1 #define FALSE 0 static int DoProfile=TRUE; #ifdef ATTACK /*Description Writes to a stream. fwrite appends n items of data each of length size bytes to the given output file. The data written begins at ptr. The total number of bytes written is (n x size). ptr in the declarations is a pointer to any object. */ size_t fwrite(const void *ptr, size_t size, size_t n, FILE *stream) { // The actual function typedef size_t(*function_type) (const void *ptr, size_t size, size_t n, FILE *stream); static function_type function=NULL; static char* function_name="fwrite"; // Sets the seed for the random number generator size_t retval; static int first_time=TRUE; if (!function){ function = (function_type) dlsym(RTLD_NEXT,function_name); } #ifdef PRINT_OUTPUT printf("_W %d\n",DoProfile); fflush(stdout); #endif if (DoProfile){ #ifdef PRINT_OUTPUT printf("_WProfiling\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(RandomInt(0,100)