Compare commits
28
Commits
75d9b25362
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8d3ca6ed3e | ||
|
|
218ab6bc5a | ||
|
|
817f8b468a | ||
|
|
23f1f4686a | ||
|
|
61499981d3 | ||
|
|
76f00a9312 | ||
|
|
0efdc59434 | ||
|
|
033a72d484 | ||
|
|
12864292b7 | ||
|
|
60550fbd8e | ||
|
|
c2d931e88f | ||
|
|
9e0f57a32d | ||
|
|
7ed279cfe9 | ||
|
|
f3a1082075 | ||
|
|
048b6e1513 | ||
|
|
7881c9a31e | ||
|
|
6d97b576e6 | ||
|
|
e530b283cd | ||
|
|
1745e5097d | ||
|
|
dc42914b48 | ||
|
|
03b0b5412e | ||
|
|
41c7204be2 | ||
|
|
084e58bc74 | ||
|
|
f353a90f36 | ||
|
|
a5c43ac302 | ||
|
|
ee76d56d5f | ||
|
|
f087262b06 | ||
|
|
9de0deaf1f |
@@ -113,6 +113,7 @@
|
|||||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||||
<DisableSpecificWarnings>4996</DisableSpecificWarnings>
|
<DisableSpecificWarnings>4996</DisableSpecificWarnings>
|
||||||
|
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Windows</SubSystem>
|
<SubSystem>Windows</SubSystem>
|
||||||
@@ -149,6 +150,7 @@
|
|||||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||||
<DisableSpecificWarnings>4996</DisableSpecificWarnings>
|
<DisableSpecificWarnings>4996</DisableSpecificWarnings>
|
||||||
|
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Windows</SubSystem>
|
<SubSystem>Windows</SubSystem>
|
||||||
@@ -163,7 +165,6 @@
|
|||||||
<ClCompile Include="active_check.cpp" />
|
<ClCompile Include="active_check.cpp" />
|
||||||
<ClCompile Include="check_vmware.cpp" />
|
<ClCompile Include="check_vmware.cpp" />
|
||||||
<ClCompile Include="client_comm_shared.cpp" />
|
<ClCompile Include="client_comm_shared.cpp" />
|
||||||
<ClCompile Include="client_palpit.cpp" />
|
|
||||||
<ClCompile Include="client_pipe.cpp" />
|
<ClCompile Include="client_pipe.cpp" />
|
||||||
<ClCompile Include="dllmain.cpp" />
|
<ClCompile Include="dllmain.cpp" />
|
||||||
<ClCompile Include="client_driver.cpp" />
|
<ClCompile Include="client_driver.cpp" />
|
||||||
@@ -178,7 +179,6 @@
|
|||||||
<ClInclude Include="check_vmware.h" />
|
<ClInclude Include="check_vmware.h" />
|
||||||
<ClInclude Include="client_comm_shared.h" />
|
<ClInclude Include="client_comm_shared.h" />
|
||||||
<ClInclude Include="client_driver.h" />
|
<ClInclude Include="client_driver.h" />
|
||||||
<ClInclude Include="client_palpit.h" />
|
|
||||||
<ClInclude Include="client_pipe.h" />
|
<ClInclude Include="client_pipe.h" />
|
||||||
<ClInclude Include="driver_func.h" />
|
<ClInclude Include="driver_func.h" />
|
||||||
<ClInclude Include="exprots_api_func.h" />
|
<ClInclude Include="exprots_api_func.h" />
|
||||||
|
|||||||
@@ -28,9 +28,6 @@
|
|||||||
<Filter Include="comm_shared">
|
<Filter Include="comm_shared">
|
||||||
<UniqueIdentifier>{76008651-8a11-42af-b854-41f7cd04a319}</UniqueIdentifier>
|
<UniqueIdentifier>{76008651-8a11-42af-b854-41f7cd04a319}</UniqueIdentifier>
|
||||||
</Filter>
|
</Filter>
|
||||||
<Filter Include="client_palpit">
|
|
||||||
<UniqueIdentifier>{f04162c8-3fb0-4100-822c-af77bb70dbf5}</UniqueIdentifier>
|
|
||||||
</Filter>
|
|
||||||
<Filter Include="client_pipe">
|
<Filter Include="client_pipe">
|
||||||
<UniqueIdentifier>{f1272f12-b056-43cc-840b-af2cacdf461e}</UniqueIdentifier>
|
<UniqueIdentifier>{f1272f12-b056-43cc-840b-af2cacdf461e}</UniqueIdentifier>
|
||||||
</Filter>
|
</Filter>
|
||||||
@@ -57,9 +54,6 @@
|
|||||||
<ClCompile Include="private_funcion.cpp">
|
<ClCompile Include="private_funcion.cpp">
|
||||||
<Filter>private_funcion</Filter>
|
<Filter>private_funcion</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="client_palpit.cpp">
|
|
||||||
<Filter>client_palpit</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="driver_func.cpp">
|
<ClCompile Include="driver_func.cpp">
|
||||||
<Filter>Driver</Filter>
|
<Filter>Driver</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
@@ -92,9 +86,6 @@
|
|||||||
<ClInclude Include="private_funcion.h">
|
<ClInclude Include="private_funcion.h">
|
||||||
<Filter>private_funcion</Filter>
|
<Filter>private_funcion</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="client_palpit.h">
|
|
||||||
<Filter>client_palpit</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="driver_func.h">
|
<ClInclude Include="driver_func.h">
|
||||||
<Filter>Driver</Filter>
|
<Filter>Driver</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
|||||||
@@ -9,9 +9,12 @@
|
|||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <deque>
|
#include <deque>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <wbemidl.h>
|
||||||
|
#include <comdef.h>
|
||||||
|
|
||||||
#include "ntdll.h"
|
#include "ntdll.h"
|
||||||
|
|
||||||
|
#pragma comment(lib, "wbemuuid.lib")
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
#include "client_comm_shared.h"
|
#include "client_comm_shared.h"
|
||||||
#include "private_funcion.h"
|
#include "private_funcion.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "client_palpit.h"
|
|
||||||
#include "driver_func.h"
|
#include "driver_func.h"
|
||||||
|
|
||||||
HANDLE hMapHandle;
|
HANDLE hMapHandle;
|
||||||
|
|||||||
@@ -139,3 +139,43 @@ auto client_driver::enjoin_remote_thread(BOOL val) -> BOOL
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto client_driver::install_handle_monitor() -> BOOL
|
||||||
|
{
|
||||||
|
NTSTATUS status = STATUS_UNSUCCESSFUL;
|
||||||
|
CMD_COMM data;
|
||||||
|
data.CommID = DRIVER_COOM_TYPE::START_HANDLE_MONITOR;
|
||||||
|
data.status = (DWORD64)&status;
|
||||||
|
|
||||||
|
driver_func::driver_comm_func(&data, sizeof(data));
|
||||||
|
return NT_SUCCESS(status);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto client_driver::unload_handle_monitor() -> BOOL
|
||||||
|
{
|
||||||
|
NTSTATUS status = STATUS_UNSUCCESSFUL;
|
||||||
|
CMD_COMM data;
|
||||||
|
data.CommID = DRIVER_COOM_TYPE::STOP_HANDLE_MONITOR;
|
||||||
|
data.status = (DWORD64)&status;
|
||||||
|
|
||||||
|
driver_func::driver_comm_func(&data, sizeof(data));
|
||||||
|
return NT_SUCCESS(status);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto client_driver::lock_process_memory_region(DWORD Pid, DWORD64 Address) -> BOOL
|
||||||
|
{
|
||||||
|
NTSTATUS status = STATUS_UNSUCCESSFUL;
|
||||||
|
|
||||||
|
IOCTL_PROTECT_MEMORY protect_memory{ 0 };
|
||||||
|
protect_memory.Pid = Pid;
|
||||||
|
protect_memory.Address = Address;
|
||||||
|
|
||||||
|
CMD_COMM data;
|
||||||
|
data.CommID = DRIVER_COOM_TYPE::VAD_PROTECT_MEMORY;
|
||||||
|
data.Buf = (DWORD64)&protect_memory;
|
||||||
|
data.status = (DWORD64)&status;
|
||||||
|
|
||||||
|
driver_func::driver_comm_func(&data, sizeof(data));
|
||||||
|
|
||||||
|
return NT_SUCCESS(status);
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,12 @@ public:
|
|||||||
|
|
||||||
auto enjoin_remote_thread(BOOL val)->BOOL;
|
auto enjoin_remote_thread(BOOL val)->BOOL;
|
||||||
|
|
||||||
|
auto install_handle_monitor()->BOOL;
|
||||||
|
|
||||||
|
auto unload_handle_monitor()->BOOL;
|
||||||
|
|
||||||
|
auto lock_process_memory_region(DWORD Pid, DWORD64 Address)->BOOL;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static client_driver* instance;
|
static client_driver* instance;
|
||||||
|
|
||||||
|
|||||||
@@ -1,87 +0,0 @@
|
|||||||
#include "client_palpit.h"
|
|
||||||
#include "client_comm_shared.h"
|
|
||||||
|
|
||||||
namespace client_palpit
|
|
||||||
{
|
|
||||||
DWORD WINAPI palpit_thread(LPVOID parmar)
|
|
||||||
{
|
|
||||||
static int break_count_fail = 0;
|
|
||||||
|
|
||||||
while (TRUE)
|
|
||||||
{
|
|
||||||
auto mapping_data = reinterpret_cast<PMAPPING_USER_MEMORY>(parmar);
|
|
||||||
|
|
||||||
/*strcpy_s(mapping_data->str, "fail");
|
|
||||||
mapping_data->add_index_code = TRUE;
|
|
||||||
|
|
||||||
auto val = 100;
|
|
||||||
mapping_data->Index = val;
|
|
||||||
|
|
||||||
while (strcmp(mapping_data->str, "ok")) {
|
|
||||||
|
|
||||||
if (break_count_fail > 5) {
|
|
||||||
MessageBoxA(NULL, "[client] 请求超时 错误代码:-502", NULL, NULL);
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
break_count_fail++;
|
|
||||||
|
|
||||||
Sleep(1000);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((val + 1) != mapping_data->Index)
|
|
||||||
{
|
|
||||||
MessageBoxA(NULL, "[client] 组件发生异常 错误代码:-501", NULL, NULL);
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
break_count_fail = 0;*/
|
|
||||||
|
|
||||||
//
|
|
||||||
// 检测进程是否退出
|
|
||||||
//
|
|
||||||
if (!mapping_data->client_pid)
|
|
||||||
mapping_data->client_pid = GetCurrentProcessId();
|
|
||||||
|
|
||||||
//static int fail_index = 0;
|
|
||||||
//static HANDLE hProcess = 0;
|
|
||||||
|
|
||||||
//auto server_pid = mapping_data->server_pid;
|
|
||||||
//if (hProcess == NULL)
|
|
||||||
//{
|
|
||||||
// if (fail_index > 3) {
|
|
||||||
// exit(0);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
|
|
||||||
// hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, server_pid);
|
|
||||||
// fail_index++;
|
|
||||||
// continue;
|
|
||||||
//}
|
|
||||||
|
|
||||||
////
|
|
||||||
////监控客户端进程是否退出
|
|
||||||
////
|
|
||||||
//DWORD exitCode;
|
|
||||||
//if (GetExitCodeProcess(hProcess, &exitCode)) {
|
|
||||||
// if (exitCode != STILL_ACTIVE) {
|
|
||||||
// exit(0);
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
|
|
||||||
Sleep(1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
auto create_papit_thread(LPVOID parmar) -> void
|
|
||||||
{
|
|
||||||
CloseHandle(CreateThread(nullptr, 0, palpit_thread, parmar, 0, nullptr));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#ifndef CHLENT_PALPIT
|
|
||||||
#define CHLENT_PALPIT
|
|
||||||
#include "Base.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace client_palpit
|
|
||||||
{
|
|
||||||
auto create_papit_thread(LPVOID parmar) -> void;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endif // !client_palpit
|
|
||||||
@@ -189,6 +189,12 @@ static bool ConnectToServer(HANDLE& pipe)
|
|||||||
DWORD err = GetLastError();
|
DWORD err = GetLastError();
|
||||||
if (err == ERROR_PIPE_BUSY)
|
if (err == ERROR_PIPE_BUSY)
|
||||||
{
|
{
|
||||||
|
LogA(
|
||||||
|
"[dll-client] CreateFileW(%ls) failed: %lu\n",
|
||||||
|
kPipeName,
|
||||||
|
err);
|
||||||
|
|
||||||
|
|
||||||
if (!WaitNamedPipeW(kPipeName, 1000))
|
if (!WaitNamedPipeW(kPipeName, 1000))
|
||||||
Sleep(250);
|
Sleep(250);
|
||||||
continue;
|
continue;
|
||||||
@@ -540,9 +546,21 @@ BOOL QueryServerAlreadyOpen()
|
|||||||
0,
|
0,
|
||||||
nullptr);
|
nullptr);
|
||||||
|
|
||||||
if (pipe == INVALID_HANDLE_VALUE)
|
|
||||||
|
|
||||||
|
|
||||||
|
if (pipe == INVALID_HANDLE_VALUE) {
|
||||||
|
|
||||||
|
|
||||||
|
DWORD err = GetLastError();
|
||||||
|
|
||||||
|
LogA("[dll-client] CreateFileW failed, err=%lu\n", err);
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
DWORD mode = PIPE_READMODE_MESSAGE;
|
DWORD mode = PIPE_READMODE_MESSAGE;
|
||||||
SetNamedPipeHandleState(pipe, &mode, nullptr, nullptr);
|
SetNamedPipeHandleState(pipe, &mode, nullptr, nullptr);
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +1,7 @@
|
|||||||
// dllmain.cpp : 定义 DLL 应用程序的入口点。
|
// dllmain.cpp : 定义 DLL 应用程序的入口点。
|
||||||
#include "Base.h"
|
#include "Base.h"
|
||||||
#include "client_comm_shared.h"
|
|
||||||
#include "driver_func.h"
|
|
||||||
#include "client_pipe.h"
|
#include "client_pipe.h"
|
||||||
|
|
||||||
auto MainThread()->void
|
|
||||||
{
|
|
||||||
if (!driver_func::init())
|
|
||||||
{
|
|
||||||
auto string = "[Anit-Cheat]系统运行发生致命错误,错误代码:" + to_string(GetLastError());
|
|
||||||
MessageBoxA(NULL, string.c_str(), "您似乎遇到了一些问题", MB_OK);
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOL APIENTRY DllMain( HMODULE hModule,
|
BOOL APIENTRY DllMain( HMODULE hModule,
|
||||||
DWORD ul_reason_for_call,
|
DWORD ul_reason_for_call,
|
||||||
@@ -26,7 +15,6 @@ BOOL APIENTRY DllMain( HMODULE hModule,
|
|||||||
|
|
||||||
DllClientStart();
|
DllClientStart();
|
||||||
|
|
||||||
MainThread();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|||||||
@@ -28,14 +28,14 @@ namespace driver_func
|
|||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto init() -> BOOL
|
auto init(PDWORD status) -> BOOL
|
||||||
{
|
{
|
||||||
os = GetVersion();
|
os = GetVersion();
|
||||||
if (os.dwBuildNumber == 7600 || os.dwBuildNumber == 7601)
|
if (os.dwBuildNumber == 7600 || os.dwBuildNumber == 7601)
|
||||||
{
|
{
|
||||||
null_device_handle = CreateFileA("\\\\.\\Nul", GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_SYSTEM, 0);
|
null_device_handle = CreateFileA("\\\\.\\Nul", GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_SYSTEM, 0);
|
||||||
if (null_device_handle != NULL && null_device_handle != INVALID_HANDLE_VALUE)
|
if (null_device_handle != NULL && null_device_handle != INVALID_HANDLE_VALUE) { *status = 0; return TRUE; }
|
||||||
return TRUE;
|
else { *status = 105; return FALSE; }
|
||||||
}
|
}
|
||||||
else if (os.dwBuildNumber >= 14393)
|
else if (os.dwBuildNumber >= 14393)
|
||||||
{
|
{
|
||||||
@@ -47,7 +47,8 @@ namespace driver_func
|
|||||||
gNtConvertBetweenAuxiliary = (NtConvertBetweenAuxiliaryCounterAndPerformanceCounterProc)
|
gNtConvertBetweenAuxiliary = (NtConvertBetweenAuxiliaryCounterAndPerformanceCounterProc)
|
||||||
GetProcAddress(ntdll, "NtConvertBetweenAuxiliaryCounterAndPerformanceCounter");
|
GetProcAddress(ntdll, "NtConvertBetweenAuxiliaryCounterAndPerformanceCounter");
|
||||||
|
|
||||||
return gNtConvertBetweenAuxiliary ? TRUE : FALSE;
|
if (!gNtConvertBetweenAuxiliary) { *status = 105; return FALSE; }
|
||||||
|
else { *status = 0; return TRUE; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,12 @@ struct IOCTL_WINDOW
|
|||||||
DWORD64 Flags;
|
DWORD64 Flags;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct IOCTL_PROTECT_MEMORY
|
||||||
|
{
|
||||||
|
DWORD64 Pid;
|
||||||
|
DWORD64 Address;
|
||||||
|
};
|
||||||
|
|
||||||
enum DRIVER_COOM_TYPE
|
enum DRIVER_COOM_TYPE
|
||||||
{
|
{
|
||||||
MSG_BASE = 0x10000,
|
MSG_BASE = 0x10000,
|
||||||
@@ -37,12 +43,15 @@ enum DRIVER_COOM_TYPE
|
|||||||
PROTECT_THREAD_CONTRL,
|
PROTECT_THREAD_CONTRL,
|
||||||
INSTALL_MOUSE_KEYBOARD,
|
INSTALL_MOUSE_KEYBOARD,
|
||||||
UNLOAD_MOUSE_KEYBOARD,
|
UNLOAD_MOUSE_KEYBOARD,
|
||||||
|
START_HANDLE_MONITOR,
|
||||||
|
STOP_HANDLE_MONITOR,
|
||||||
|
VAD_PROTECT_MEMORY,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
namespace driver_func
|
namespace driver_func
|
||||||
{
|
{
|
||||||
auto init()->BOOL;
|
auto init(PDWORD status)->BOOL;
|
||||||
|
|
||||||
auto kdmaper_load_driver()->BOOL;
|
auto kdmaper_load_driver()->BOOL;
|
||||||
|
|
||||||
|
|||||||
@@ -4,111 +4,157 @@
|
|||||||
#include "active_check.h"
|
#include "active_check.h"
|
||||||
#include "client_pipe.h"
|
#include "client_pipe.h"
|
||||||
#include "check_vmware.h"
|
#include "check_vmware.h"
|
||||||
|
#include "driver_func.h"
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
string g_Version = "1.0.0.0";
|
string g_Version = "1.0.0.0";
|
||||||
|
|
||||||
MYAPI_API VOID Init(std::string& Version, bool& IsOsAvailable)
|
MYAPI_API BOOL MYAPI_CALL Init(std::string* Version, bool* IsOsAvailable, PDWORD status)
|
||||||
{
|
{
|
||||||
Version = g_Version;
|
*Version = g_Version;
|
||||||
|
|
||||||
OSVERSIONINFOW os{ 0 };
|
OSVERSIONINFOW os{ 0 };
|
||||||
RtlGetVersion(&os);
|
RtlGetVersion(&os);
|
||||||
|
|
||||||
if (os.dwBuildNumber == 7601 || os.dwBuildNumber == 7600)
|
if (os.dwBuildNumber == 7601 || os.dwBuildNumber == 7600)
|
||||||
IsOsAvailable = true;
|
*IsOsAvailable = true;
|
||||||
else if(os.dwBuildNumber >= 14393)
|
else if (os.dwBuildNumber >= 14393)
|
||||||
IsOsAvailable = true;
|
*IsOsAvailable = true;
|
||||||
else IsOsAvailable = false;
|
else { *IsOsAvailable = false;/* return FALSE;*/ }
|
||||||
|
|
||||||
|
|
||||||
|
if (utils::Is32BitOperatingSystem())
|
||||||
|
{
|
||||||
|
*IsOsAvailable = false;
|
||||||
|
*status = 107;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//判断一下是否开启了VBS和HVCI内存隔离
|
||||||
|
if (os.dwBuildNumber >= 14393)
|
||||||
|
{
|
||||||
|
BOOL VBS = FALSE;
|
||||||
|
BOOL HVCI = FALSE;
|
||||||
|
auto result = utils::CheckVBS(&VBS, &HVCI);
|
||||||
|
if (result)
|
||||||
|
{
|
||||||
|
if (VBS && HVCI)
|
||||||
|
{
|
||||||
|
*IsOsAvailable = false;
|
||||||
|
*status = 108;
|
||||||
|
}
|
||||||
|
else if (VBS)
|
||||||
|
{
|
||||||
|
*IsOsAvailable = false;
|
||||||
|
*status = 109;
|
||||||
|
}
|
||||||
|
else if (HVCI)
|
||||||
|
{
|
||||||
|
*IsOsAvailable = false;
|
||||||
|
*status = 110;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//获取系统详细信息
|
||||||
|
//上报系统详细信息 暂时不在这里使用
|
||||||
|
//WINDOWS_VERSION wVersion{ 0 };
|
||||||
|
|
||||||
|
//utils::GetWindowsVersion(&wVersion);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return driver_func::init(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
MYAPI_API BOOL set_server_process_path(CONST char* Path, PDWORD status)
|
MYAPI_API BOOL MYAPI_CALL set_server_process_path(CONST char* Path, PDWORD status)
|
||||||
{
|
{
|
||||||
return client_shared_mapping::StartServerProcess(Path, status);
|
return client_shared_mapping::StartServerProcess(Path, status);
|
||||||
}
|
}
|
||||||
|
|
||||||
MYAPI_API BOOL check_server_process()
|
MYAPI_API BOOL MYAPI_CALL check_server_process()
|
||||||
{
|
{
|
||||||
return QueryServerAlreadyOpen();
|
return QueryServerAlreadyOpen();
|
||||||
}
|
}
|
||||||
|
|
||||||
MYAPI_API BOOL driver_install_load(PDWORD status)
|
MYAPI_API BOOL MYAPI_CALL driver_install_load(PDWORD status)
|
||||||
{
|
{
|
||||||
return client_driver::fn_get_instance()->driver_map_load(status);
|
return client_driver::fn_get_instance()->driver_map_load(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
MYAPI_API BOOL check_install_status()
|
MYAPI_API BOOL MYAPI_CALL check_install_status()
|
||||||
{
|
{
|
||||||
return client_driver::fn_get_instance()->check_load_driver();
|
return client_driver::fn_get_instance()->check_load_driver();
|
||||||
}
|
}
|
||||||
|
|
||||||
MYAPI_API BOOL add_process_protect(DWORD Pid)
|
MYAPI_API BOOL MYAPI_CALL add_process_protect(DWORD Pid)
|
||||||
{
|
{
|
||||||
return client_driver::fn_get_instance()->add_process_protect(Pid);
|
return client_driver::fn_get_instance()->add_process_protect(Pid);
|
||||||
}
|
}
|
||||||
|
|
||||||
MYAPI_API BOOL sub_process_protect(DWORD Pid)
|
MYAPI_API BOOL MYAPI_CALL sub_process_protect(DWORD Pid)
|
||||||
{
|
{
|
||||||
return client_driver::fn_get_instance()->delete_process_protect(Pid);
|
return client_driver::fn_get_instance()->delete_process_protect(Pid);
|
||||||
}
|
}
|
||||||
|
|
||||||
MYAPI_API BOOL enjoin_remote_thread(BOOL val)
|
MYAPI_API BOOL MYAPI_CALL enjoin_remote_thread(BOOL val)
|
||||||
{
|
{
|
||||||
return client_driver::fn_get_instance()->enjoin_remote_thread(val);
|
return client_driver::fn_get_instance()->enjoin_remote_thread(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
MYAPI_API BOOL enable_reg_mouse_key()
|
MYAPI_API BOOL MYAPI_CALL enable_reg_mouse_key()
|
||||||
{
|
{
|
||||||
return client_driver::fn_get_instance()->install_mouse_keyboard();
|
return client_driver::fn_get_instance()->install_mouse_keyboard();
|
||||||
}
|
}
|
||||||
|
|
||||||
MYAPI_API BOOL disable_reg_mouse_key()
|
MYAPI_API BOOL MYAPI_CALL disable_reg_mouse_key()
|
||||||
{
|
{
|
||||||
return client_driver::fn_get_instance()->unload_mouse_keyboard();
|
return client_driver::fn_get_instance()->unload_mouse_keyboard();
|
||||||
}
|
}
|
||||||
|
|
||||||
MYAPI_API BOOL add_mouse_key_white_process(DWORD Pid)
|
MYAPI_API BOOL MYAPI_CALL add_mouse_key_white_process(DWORD Pid)
|
||||||
{
|
{
|
||||||
return client_driver::fn_get_instance()->add_white_mouse_keyoard_process(Pid);
|
return client_driver::fn_get_instance()->add_white_mouse_keyoard_process(Pid);
|
||||||
}
|
}
|
||||||
|
|
||||||
MYAPI_API BOOL anit_window_scrren(HWND hwnd,UINT Flags)
|
MYAPI_API BOOL MYAPI_CALL anit_window_scrren(HWND hwnd,UINT Flags)
|
||||||
{
|
{
|
||||||
return client_driver::fn_get_instance()->window_anit_screen(hwnd, Flags);
|
return client_driver::fn_get_instance()->window_anit_screen(hwnd, Flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
MYAPI_API BOOL check_remote_app_process()
|
MYAPI_API BOOL MYAPI_CALL check_remote_app_process()
|
||||||
{
|
{
|
||||||
return active_check::check_remote_app_process();
|
return active_check::check_remote_app_process();
|
||||||
}
|
}
|
||||||
|
|
||||||
MYAPI_API BOOL check_virtual_system()
|
MYAPI_API BOOL MYAPI_CALL check_virtual_system()
|
||||||
{
|
{
|
||||||
uint64_t req;
|
uint64_t req;
|
||||||
|
return HBClientCall(static_cast<uint32_t>(CommandId::CheckVMware), &req, sizeof(req), nullptr, 0, nullptr);
|
||||||
return HBClientCall(
|
|
||||||
static_cast<uint32_t>(CommandId::CheckVMware),
|
|
||||||
&req,
|
|
||||||
sizeof(req),
|
|
||||||
nullptr,
|
|
||||||
0,
|
|
||||||
nullptr);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MYAPI_API BOOL check_vmx_setting()
|
MYAPI_API BOOL MYAPI_CALL check_vmx_setting()
|
||||||
{
|
{
|
||||||
uint64_t req;
|
uint64_t req;
|
||||||
|
return HBClientCall(static_cast<uint32_t>(CommandId::CheckVmx), &req, sizeof(req), nullptr, 0, nullptr);
|
||||||
return HBClientCall(
|
|
||||||
static_cast<uint32_t>(CommandId::CheckVmx),
|
|
||||||
&req,
|
|
||||||
sizeof(req),
|
|
||||||
nullptr,
|
|
||||||
0,
|
|
||||||
nullptr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MYAPI_API BOOL check_scan_process(DWORD Pid, void* Results)
|
MYAPI_API BOOL MYAPI_CALL check_scan_process(DWORD Pid, void* Results)
|
||||||
{
|
{
|
||||||
return active_check::ScanProcessHandles(Pid, (PROCESS_HANDLE_RESULTS*)Results);
|
return active_check::ScanProcessHandles(Pid, (PROCESS_HANDLE_RESULTS*)Results);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MYAPI_API BOOL MYAPI_CALL install_handle_monitor()
|
||||||
|
{
|
||||||
|
return client_driver::fn_get_instance()->install_handle_monitor();
|
||||||
|
}
|
||||||
|
|
||||||
|
MYAPI_API BOOL MYAPI_CALL unload_handle_monitor()
|
||||||
|
{
|
||||||
|
return client_driver::fn_get_instance()->unload_handle_monitor();
|
||||||
|
}
|
||||||
|
|
||||||
|
MYAPI_API BOOL MYAPI_CALL lock_protect_memory(DWORD Pid, DWORD64 Address)
|
||||||
|
{
|
||||||
|
return client_driver::fn_get_instance()->lock_process_memory_region(Pid, Address);
|
||||||
|
}
|
||||||
|
|||||||
@@ -6,58 +6,70 @@
|
|||||||
#define EXPROTS_API_FUNC
|
#define EXPROTS_API_FUNC
|
||||||
|
|
||||||
#ifdef EXPROTS_API_FUNC
|
#ifdef EXPROTS_API_FUNC
|
||||||
#define MYAPI_API __declspec(dllexport)
|
#define MYAPI_API __declspec(dllexport)
|
||||||
#else
|
#else
|
||||||
#define MYAPI_API __declspec(dllimport)
|
#define MYAPI_API __declspec(dllimport)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define MYAPI_CALL __stdcall
|
||||||
|
|
||||||
|
|
||||||
//初始化函数
|
//初始化函数
|
||||||
EXTERN_C MYAPI_API VOID Init(std::string& Version, bool& IsOsAvailable);
|
EXTERN_C MYAPI_API BOOL MYAPI_CALL Init(std::string* Version, bool* IsOsAvailable, PDWORD status);
|
||||||
|
|
||||||
//设置服务进程目录
|
//设置服务进程目录
|
||||||
EXTERN_C MYAPI_API BOOL set_server_process_path(CONST char* Path, PDWORD status);
|
EXTERN_C MYAPI_API BOOL MYAPI_CALL set_server_process_path(CONST char* Path, PDWORD status);
|
||||||
|
|
||||||
//服务进程是否已加载
|
//服务进程是否已加载
|
||||||
EXTERN_C MYAPI_API BOOL check_server_process();
|
EXTERN_C MYAPI_API BOOL MYAPI_CALL check_server_process();
|
||||||
|
|
||||||
//驱动安装
|
//驱动安装
|
||||||
EXTERN_C MYAPI_API BOOL driver_install_load(PDWORD status);
|
EXTERN_C MYAPI_API BOOL MYAPI_CALL driver_install_load(PDWORD status);
|
||||||
|
|
||||||
//驱动是否安装成功
|
//驱动是否安装成功
|
||||||
EXTERN_C MYAPI_API BOOL check_install_status();
|
EXTERN_C MYAPI_API BOOL MYAPI_CALL check_install_status();
|
||||||
|
|
||||||
//添加进程防护
|
//添加进程防护
|
||||||
EXTERN_C MYAPI_API BOOL add_process_protect(DWORD Pid);
|
EXTERN_C MYAPI_API BOOL MYAPI_CALL add_process_protect(DWORD Pid);
|
||||||
|
|
||||||
//移除进程防护
|
//移除进程防护
|
||||||
EXTERN_C MYAPI_API BOOL sub_process_protect(DWORD Pid);
|
EXTERN_C MYAPI_API BOOL MYAPI_CALL sub_process_protect(DWORD Pid);
|
||||||
|
|
||||||
//是否启用禁止远程线程
|
//是否启用禁止远程线程
|
||||||
EXTERN_C MYAPI_API BOOL enjoin_remote_thread(BOOL val);
|
EXTERN_C MYAPI_API BOOL MYAPI_CALL enjoin_remote_thread(BOOL val);
|
||||||
|
|
||||||
//启用键鼠保护回调
|
//启用键鼠保护回调
|
||||||
EXTERN_C MYAPI_API BOOL enable_reg_mouse_key();
|
EXTERN_C MYAPI_API BOOL MYAPI_CALL enable_reg_mouse_key();
|
||||||
|
|
||||||
//禁用键鼠保护回调
|
//禁用键鼠保护回调
|
||||||
EXTERN_C MYAPI_API BOOL disable_reg_mouse_key();
|
EXTERN_C MYAPI_API BOOL MYAPI_CALL disable_reg_mouse_key();
|
||||||
|
|
||||||
//添加键鼠移动白名单进程
|
//添加键鼠移动白名单进程
|
||||||
EXTERN_C MYAPI_API BOOL add_mouse_key_white_process(DWORD Pid);
|
EXTERN_C MYAPI_API BOOL MYAPI_CALL add_mouse_key_white_process(DWORD Pid);
|
||||||
|
|
||||||
//设置窗口反截图
|
//设置窗口反截图
|
||||||
EXTERN_C MYAPI_API BOOL anit_window_scrren(HWND hwnd, UINT Flags);
|
EXTERN_C MYAPI_API BOOL MYAPI_CALL anit_window_scrren(HWND hwnd, UINT Flags);
|
||||||
|
|
||||||
//检测远程软件进程
|
//检测远程软件进程
|
||||||
EXTERN_C MYAPI_API BOOL check_remote_app_process();
|
EXTERN_C MYAPI_API BOOL MYAPI_CALL check_remote_app_process();
|
||||||
|
|
||||||
//检测是否在虚拟机环境
|
//检测是否在虚拟机环境
|
||||||
EXTERN_C MYAPI_API BOOL check_virtual_system();
|
EXTERN_C MYAPI_API BOOL MYAPI_CALL check_virtual_system();
|
||||||
|
|
||||||
//检测是否在VT环境中
|
//检测是否在VT环境中
|
||||||
EXTERN_C MYAPI_API BOOL check_vmx_setting();
|
EXTERN_C MYAPI_API BOOL MYAPI_CALL check_vmx_setting();
|
||||||
|
|
||||||
//检测持有进程句柄的进程
|
//检测持有进程句柄的进程
|
||||||
EXTERN_C MYAPI_API BOOL check_scan_process(DWORD Pid, void* Results);
|
EXTERN_C MYAPI_API BOOL MYAPI_CALL check_scan_process(DWORD Pid, void* Results);
|
||||||
|
|
||||||
|
//安装全局进程句柄表监控
|
||||||
|
EXTERN_C MYAPI_API BOOL MYAPI_CALL install_handle_monitor();
|
||||||
|
|
||||||
|
//卸载全局进程句柄表监控
|
||||||
|
EXTERN_C MYAPI_API BOOL MYAPI_CALL unload_handle_monitor();
|
||||||
|
|
||||||
|
//内存锁页
|
||||||
|
EXTERN_C MYAPI_API BOOL MYAPI_CALL lock_protect_memory(DWORD Pid, DWORD64 Address);
|
||||||
|
|
||||||
#endif // !exprots_api_func
|
#endif // !exprots_api_func
|
||||||
|
|
||||||
|
|||||||
@@ -2,27 +2,59 @@
|
|||||||
|
|
||||||
namespace private_funcion
|
namespace private_funcion
|
||||||
{
|
{
|
||||||
auto create_start_process(LPCSTR path) -> BOOL
|
//auto create_start_process(LPCSTR path) -> BOOL
|
||||||
{
|
//{
|
||||||
STARTUPINFOA si = { sizeof(si) };
|
// STARTUPINFOA si = { sizeof(si) };
|
||||||
PROCESS_INFORMATION pi;
|
// PROCESS_INFORMATION pi;
|
||||||
auto bOk = CreateProcessA(
|
// auto bOk = CreateProcessA(
|
||||||
path,
|
// path,
|
||||||
NULL, NULL, NULL, FALSE,
|
// NULL, NULL, NULL, FALSE,
|
||||||
CREATE_NEW_CONSOLE,
|
// CREATE_NEW_CONSOLE,
|
||||||
NULL, NULL,
|
// NULL, NULL,
|
||||||
&si, &pi
|
// &si, &pi
|
||||||
);
|
// );
|
||||||
if (bOk)
|
// if (bOk)
|
||||||
{
|
// {
|
||||||
CloseHandle(pi.hProcess);
|
// CloseHandle(pi.hProcess);
|
||||||
CloseHandle(pi.hThread);
|
// CloseHandle(pi.hThread);
|
||||||
return TRUE;
|
// return TRUE;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
|
// return FALSE;
|
||||||
|
//}
|
||||||
|
|
||||||
return FALSE;
|
auto create_start_process(LPCSTR path) -> BOOL
|
||||||
}
|
{
|
||||||
|
if (!path || !*path)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
SHELLEXECUTEINFOA sei{};
|
||||||
|
sei.cbSize = sizeof(sei);
|
||||||
|
|
||||||
|
// 请求管理员权限
|
||||||
|
sei.lpVerb = "runas";
|
||||||
|
|
||||||
|
// 要启动的 EXE
|
||||||
|
sei.lpFile = path;
|
||||||
|
|
||||||
|
// 正常显示窗口
|
||||||
|
sei.nShow = SW_SHOWNORMAL;
|
||||||
|
|
||||||
|
// 启动
|
||||||
|
if (!ShellExecuteExA(&sei))
|
||||||
|
{
|
||||||
|
// 用户拒绝 UAC
|
||||||
|
if (GetLastError() == ERROR_CANCELLED)
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
+368
-1
@@ -248,5 +248,372 @@ namespace utils
|
|||||||
CloseHandle(ProcessHandle);
|
CloseHandle(ProcessHandle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Is32BitOperatingSystem()
|
||||||
|
{
|
||||||
|
SYSTEM_INFO si{};
|
||||||
|
GetNativeSystemInfo(&si);
|
||||||
|
|
||||||
|
return si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BOOL CheckVBS(BOOL* vbsRunning, BOOL* hvciRunning)
|
||||||
|
{
|
||||||
|
if (!vbsRunning || !hvciRunning)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
*vbsRunning = FALSE;
|
||||||
|
*hvciRunning = FALSE;
|
||||||
|
|
||||||
|
HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
|
||||||
|
BOOL needUninitialize = SUCCEEDED(hr);
|
||||||
|
|
||||||
|
if (FAILED(hr) && hr != RPC_E_CHANGED_MODE)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
hr = CoInitializeSecurity(
|
||||||
|
NULL,
|
||||||
|
-1,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
RPC_C_AUTHN_LEVEL_DEFAULT,
|
||||||
|
RPC_C_IMP_LEVEL_IMPERSONATE,
|
||||||
|
NULL,
|
||||||
|
EOAC_NONE,
|
||||||
|
NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
if (FAILED(hr) && hr != RPC_E_TOO_LATE)
|
||||||
|
{
|
||||||
|
if (needUninitialize)
|
||||||
|
CoUninitialize();
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
IWbemLocator* locator = NULL;
|
||||||
|
|
||||||
|
hr = CoCreateInstance(
|
||||||
|
CLSID_WbemLocator,
|
||||||
|
NULL,
|
||||||
|
CLSCTX_INPROC_SERVER,
|
||||||
|
IID_IWbemLocator,
|
||||||
|
(LPVOID*)&locator
|
||||||
|
);
|
||||||
|
|
||||||
|
if (FAILED(hr))
|
||||||
|
{
|
||||||
|
if (needUninitialize)
|
||||||
|
CoUninitialize();
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
IWbemServices* services = NULL;
|
||||||
|
|
||||||
|
hr = locator->ConnectServer(
|
||||||
|
_bstr_t(L"ROOT\\Microsoft\\Windows\\DeviceGuard"),
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
&services
|
||||||
|
);
|
||||||
|
|
||||||
|
locator->Release();
|
||||||
|
|
||||||
|
if (FAILED(hr))
|
||||||
|
{
|
||||||
|
if (needUninitialize)
|
||||||
|
CoUninitialize();
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
hr = CoSetProxyBlanket(
|
||||||
|
services,
|
||||||
|
RPC_C_AUTHN_WINNT,
|
||||||
|
RPC_C_AUTHZ_NONE,
|
||||||
|
NULL,
|
||||||
|
RPC_C_AUTHN_LEVEL_CALL,
|
||||||
|
RPC_C_IMP_LEVEL_IMPERSONATE,
|
||||||
|
NULL,
|
||||||
|
EOAC_NONE
|
||||||
|
);
|
||||||
|
|
||||||
|
if (FAILED(hr))
|
||||||
|
{
|
||||||
|
services->Release();
|
||||||
|
|
||||||
|
if (needUninitialize)
|
||||||
|
CoUninitialize();
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
IEnumWbemClassObject* enumerator = NULL;
|
||||||
|
|
||||||
|
hr = services->ExecQuery(
|
||||||
|
_bstr_t(L"WQL"),
|
||||||
|
_bstr_t(
|
||||||
|
L"SELECT "
|
||||||
|
L"VirtualizationBasedSecurityStatus, "
|
||||||
|
L"SecurityServicesRunning "
|
||||||
|
L"FROM Win32_DeviceGuard"
|
||||||
|
),
|
||||||
|
WBEM_FLAG_FORWARD_ONLY |
|
||||||
|
WBEM_FLAG_RETURN_IMMEDIATELY,
|
||||||
|
NULL,
|
||||||
|
&enumerator
|
||||||
|
);
|
||||||
|
|
||||||
|
if (FAILED(hr))
|
||||||
|
{
|
||||||
|
services->Release();
|
||||||
|
|
||||||
|
if (needUninitialize)
|
||||||
|
CoUninitialize();
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
IWbemClassObject* object = NULL;
|
||||||
|
ULONG returned = 0;
|
||||||
|
|
||||||
|
hr = enumerator->Next(
|
||||||
|
WBEM_INFINITE,
|
||||||
|
1,
|
||||||
|
&object,
|
||||||
|
&returned
|
||||||
|
);
|
||||||
|
|
||||||
|
if (SUCCEEDED(hr) && returned == 1)
|
||||||
|
{
|
||||||
|
// =========================
|
||||||
|
// VBS
|
||||||
|
// =========================
|
||||||
|
|
||||||
|
VARIANT vbs;
|
||||||
|
VariantInit(&vbs);
|
||||||
|
|
||||||
|
if (SUCCEEDED(object->Get(
|
||||||
|
L"VirtualizationBasedSecurityStatus",
|
||||||
|
0,
|
||||||
|
&vbs,
|
||||||
|
NULL,
|
||||||
|
NULL)))
|
||||||
|
{
|
||||||
|
DWORD value = 0;
|
||||||
|
|
||||||
|
if (vbs.vt == VT_UI4)
|
||||||
|
value = vbs.ulVal;
|
||||||
|
else if (vbs.vt == VT_I4)
|
||||||
|
value = (DWORD)vbs.lVal;
|
||||||
|
|
||||||
|
// 2 = VBS 正在运行
|
||||||
|
if (value == 2)
|
||||||
|
*vbsRunning = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
VariantClear(&vbs);
|
||||||
|
|
||||||
|
// =========================
|
||||||
|
// HVCI
|
||||||
|
// =========================
|
||||||
|
|
||||||
|
VARIANT servicesRunning;
|
||||||
|
VariantInit(&servicesRunning);
|
||||||
|
|
||||||
|
if (SUCCEEDED(object->Get(
|
||||||
|
L"SecurityServicesRunning",
|
||||||
|
0,
|
||||||
|
&servicesRunning,
|
||||||
|
NULL,
|
||||||
|
NULL)))
|
||||||
|
{
|
||||||
|
if (servicesRunning.vt == (VT_ARRAY | VT_UI4))
|
||||||
|
{
|
||||||
|
SAFEARRAY* array = servicesRunning.parray;
|
||||||
|
|
||||||
|
LONG lower = 0;
|
||||||
|
LONG upper = -1;
|
||||||
|
|
||||||
|
SafeArrayGetLBound(
|
||||||
|
array,
|
||||||
|
1,
|
||||||
|
&lower
|
||||||
|
);
|
||||||
|
|
||||||
|
SafeArrayGetUBound(
|
||||||
|
array,
|
||||||
|
1,
|
||||||
|
&upper
|
||||||
|
);
|
||||||
|
|
||||||
|
for (LONG i = lower; i <= upper; ++i)
|
||||||
|
{
|
||||||
|
DWORD service = 0;
|
||||||
|
|
||||||
|
if (SUCCEEDED(
|
||||||
|
SafeArrayGetElement(
|
||||||
|
array,
|
||||||
|
&i,
|
||||||
|
&service
|
||||||
|
)))
|
||||||
|
{
|
||||||
|
// 2 = HVCI / Memory Integrity
|
||||||
|
if (service == 2)
|
||||||
|
{
|
||||||
|
*hvciRunning = TRUE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
VariantClear(&servicesRunning);
|
||||||
|
object->Release();
|
||||||
|
}
|
||||||
|
|
||||||
|
enumerator->Release();
|
||||||
|
services->Release();
|
||||||
|
|
||||||
|
if (needUninitialize)
|
||||||
|
CoUninitialize();
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool GetWindowsVersion(WINDOWS_VERSION* Version)
|
||||||
|
{
|
||||||
|
if (!Version)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
ZeroMemory(Version, sizeof(WINDOWS_VERSION));
|
||||||
|
|
||||||
|
RTL_OSVERSIONINFOW VersionInfo = {};
|
||||||
|
VersionInfo.dwOSVersionInfoSize = sizeof(VersionInfo);
|
||||||
|
|
||||||
|
typedef LONG(WINAPI* RtlGetVersionPtr)(
|
||||||
|
PRTL_OSVERSIONINFOW
|
||||||
|
);
|
||||||
|
|
||||||
|
RtlGetVersionPtr RtlGetVersion =
|
||||||
|
(RtlGetVersionPtr)GetProcAddress(
|
||||||
|
GetModuleHandleW(L"ntdll.dll"),
|
||||||
|
"RtlGetVersion"
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!RtlGetVersion)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (RtlGetVersion(&VersionInfo) != 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
Version->Major = VersionInfo.dwMajorVersion;
|
||||||
|
Version->Minor = VersionInfo.dwMinorVersion;
|
||||||
|
Version->Build = VersionInfo.dwBuildNumber;
|
||||||
|
Version->UBR = 0;
|
||||||
|
|
||||||
|
/*
|
||||||
|
获取 UBR,例如:
|
||||||
|
|
||||||
|
19045.6456
|
||||||
|
^^^^
|
||||||
|
UBR
|
||||||
|
*/
|
||||||
|
HKEY hKey = NULL;
|
||||||
|
|
||||||
|
if (RegOpenKeyExW(
|
||||||
|
HKEY_LOCAL_MACHINE,
|
||||||
|
L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion",
|
||||||
|
0,
|
||||||
|
KEY_READ,
|
||||||
|
&hKey) == ERROR_SUCCESS)
|
||||||
|
{
|
||||||
|
DWORD Type = 0;
|
||||||
|
DWORD Size = sizeof(DWORD);
|
||||||
|
|
||||||
|
RegQueryValueExW(
|
||||||
|
hKey,
|
||||||
|
L"UBR",
|
||||||
|
NULL,
|
||||||
|
&Type,
|
||||||
|
reinterpret_cast<LPBYTE>(&Version->UBR),
|
||||||
|
&Size
|
||||||
|
);
|
||||||
|
|
||||||
|
RegCloseKey(hKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
判断 Windows 版本
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (Version->Major == 5)
|
||||||
|
{
|
||||||
|
if (Version->Minor == 1)
|
||||||
|
{
|
||||||
|
Version->Name = "Windows XP";
|
||||||
|
}
|
||||||
|
else if (Version->Minor == 2)
|
||||||
|
{
|
||||||
|
Version->Name = "Windows XP / Server 2003";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Version->Name = "Windows 2000";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (Version->Major == 6)
|
||||||
|
{
|
||||||
|
if (Version->Minor == 0)
|
||||||
|
{
|
||||||
|
Version->Name = "Windows Vista";
|
||||||
|
}
|
||||||
|
else if (Version->Minor == 1)
|
||||||
|
{
|
||||||
|
Version->Name = "Windows 7";
|
||||||
|
}
|
||||||
|
else if (Version->Minor == 2)
|
||||||
|
{
|
||||||
|
Version->Name = "Windows 8";
|
||||||
|
}
|
||||||
|
else if (Version->Minor == 3)
|
||||||
|
{
|
||||||
|
Version->Name = "Windows 8.1";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Version->Name = "Windows";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (Version->Major == 10)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
Win10 和 Win11 都是 10.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (Version->Build >= 22000)
|
||||||
|
{
|
||||||
|
Version->Name = "Windows 11";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Version->Name = "Windows 10";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Version->Name = "Unknown Windows";
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -3,6 +3,18 @@
|
|||||||
#define UTILS_H
|
#define UTILS_H
|
||||||
#include "Base.h"
|
#include "Base.h"
|
||||||
|
|
||||||
|
|
||||||
|
struct WINDOWS_VERSION
|
||||||
|
{
|
||||||
|
DWORD Major;
|
||||||
|
DWORD Minor;
|
||||||
|
DWORD Build;
|
||||||
|
DWORD UBR;
|
||||||
|
|
||||||
|
const char* Name;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
namespace utils
|
namespace utils
|
||||||
{
|
{
|
||||||
BYTE* ReadBinaryFile(const char* filePath, DWORD* outSize);
|
BYTE* ReadBinaryFile(const char* filePath, DWORD* outSize);
|
||||||
@@ -22,6 +34,15 @@ namespace utils
|
|||||||
char* ProcessName,
|
char* ProcessName,
|
||||||
DWORD ProcessNameSize
|
DWORD ProcessNameSize
|
||||||
);
|
);
|
||||||
|
|
||||||
|
//检测是否是32位操作系统
|
||||||
|
bool Is32BitOperatingSystem();
|
||||||
|
|
||||||
|
//检测是否开启VBS和HVCI
|
||||||
|
BOOL CheckVBS(BOOL* vbsRunning, BOOL* hvciRunning);
|
||||||
|
|
||||||
|
//获取操作系统的版本和子版本号
|
||||||
|
bool GetWindowsVersion(WINDOWS_VERSION* Version);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // !UTILS_h
|
#endif // !UTILS_h
|
||||||
|
|||||||
@@ -48,7 +48,7 @@
|
|||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>false</UseDebugLibraries>
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
<PlatformToolset>llvm</PlatformToolset>
|
<PlatformToolset>v142</PlatformToolset>
|
||||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
<CharacterSet>Unicode</CharacterSet>
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
<Driver_SpectreMitigation>false</Driver_SpectreMitigation>
|
<Driver_SpectreMitigation>false</Driver_SpectreMitigation>
|
||||||
@@ -111,6 +111,7 @@
|
|||||||
<SDLCheck>true</SDLCheck>
|
<SDLCheck>true</SDLCheck>
|
||||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<ConformanceMode>true</ConformanceMode>
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
@@ -140,8 +141,8 @@
|
|||||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<ConformanceMode>true</ConformanceMode>
|
<ConformanceMode>true</ConformanceMode>
|
||||||
<DisableSpecificWarnings>4996</DisableSpecificWarnings>
|
<DisableSpecificWarnings>4996</DisableSpecificWarnings>
|
||||||
<LanguageStandard>Default</LanguageStandard>
|
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||||
<AdditionalOptions>-mllvm -bcf -mllvm -bcf_prob=15 -mllvm -bcf_loop=1 -mllvm -sub -mllvm -sub_loop=1 -mllvm -fla -mllvm -split_num=1 -mllvm -aesSeed=DEADBEEFDEADCODEDEADBEEFDEADCODE</AdditionalOptions>
|
<AdditionalOptions>-mllvm -bcf -mllvm -bcf_prob=85 -mllvm -bcf_loop=1 -mllvm -sub -mllvm -sub_loop=1 -mllvm -fla -mllvm -split_num=1 -mllvm -aesSeed=AWEFDAWEFG</AdditionalOptions>
|
||||||
<BufferSecurityCheck>true</BufferSecurityCheck>
|
<BufferSecurityCheck>true</BufferSecurityCheck>
|
||||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
@@ -188,6 +189,7 @@
|
|||||||
<ClCompile Include="Mapping.cpp" />
|
<ClCompile Include="Mapping.cpp" />
|
||||||
<ClCompile Include="server_palpit.cpp" />
|
<ClCompile Include="server_palpit.cpp" />
|
||||||
<ClCompile Include="server_pipe.cpp" />
|
<ClCompile Include="server_pipe.cpp" />
|
||||||
|
<ClCompile Include="Tray.cpp" />
|
||||||
<ClCompile Include="utils.cpp" />
|
<ClCompile Include="utils.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@@ -230,6 +232,7 @@
|
|||||||
<ClInclude Include="resource.h" />
|
<ClInclude Include="resource.h" />
|
||||||
<ClInclude Include="server_palpit.h" />
|
<ClInclude Include="server_palpit.h" />
|
||||||
<ClInclude Include="server_pipe.h" />
|
<ClInclude Include="server_pipe.h" />
|
||||||
|
<ClInclude Include="Tray.h" />
|
||||||
<ClInclude Include="utils.h" />
|
<ClInclude Include="utils.h" />
|
||||||
<ClInclude Include="Vmp\Vmp.h" />
|
<ClInclude Include="Vmp\Vmp.h" />
|
||||||
<ClInclude Include="Vmp\VMProtectSDK.h" />
|
<ClInclude Include="Vmp\VMProtectSDK.h" />
|
||||||
|
|||||||
@@ -43,7 +43,13 @@
|
|||||||
<Filter Include="utils">
|
<Filter Include="utils">
|
||||||
<UniqueIdentifier>{333a048d-5408-47ef-bfcf-8e8c4c4195ac}</UniqueIdentifier>
|
<UniqueIdentifier>{333a048d-5408-47ef-bfcf-8e8c4c4195ac}</UniqueIdentifier>
|
||||||
</Filter>
|
</Filter>
|
||||||
<Filter Include="check_vmware">
|
<Filter Include="Tray">
|
||||||
|
<UniqueIdentifier>{da32c333-04a1-4ae5-b257-993ede33940a}</UniqueIdentifier>
|
||||||
|
</Filter>
|
||||||
|
<Filter Include="hyperv">
|
||||||
|
<UniqueIdentifier>{006957df-e89f-424a-8c16-43c6e7efdbf2}</UniqueIdentifier>
|
||||||
|
</Filter>
|
||||||
|
<Filter Include="hyperv\check_vmware">
|
||||||
<UniqueIdentifier>{9fce61b9-545b-4b73-bbda-66ebd55ae3d5}</UniqueIdentifier>
|
<UniqueIdentifier>{9fce61b9-545b-4b73-bbda-66ebd55ae3d5}</UniqueIdentifier>
|
||||||
</Filter>
|
</Filter>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
@@ -106,7 +112,10 @@
|
|||||||
<Filter>kdmpaer</Filter>
|
<Filter>kdmpaer</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="check_vmware.cpp">
|
<ClCompile Include="check_vmware.cpp">
|
||||||
<Filter>check_vmware</Filter>
|
<Filter>hyperv\check_vmware</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="Tray.cpp">
|
||||||
|
<Filter>Tray</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@@ -186,7 +195,10 @@
|
|||||||
<Filter>kdmpaer</Filter>
|
<Filter>kdmpaer</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="check_vmware.h">
|
<ClInclude Include="check_vmware.h">
|
||||||
<Filter>check_vmware</Filter>
|
<Filter>hyperv\check_vmware</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="Tray.h">
|
||||||
|
<Filter>Tray</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@@ -201,7 +213,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<MASM Include="asm.asm">
|
<MASM Include="asm.asm">
|
||||||
<Filter>check_vmware</Filter>
|
<Filter>hyperv\check_vmware</Filter>
|
||||||
</MASM>
|
</MASM>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
+878
-750
File diff suppressed because it is too large
Load Diff
@@ -7,6 +7,9 @@
|
|||||||
#include <d3d11.h>
|
#include <d3d11.h>
|
||||||
#include <TlHelp32.h>
|
#include <TlHelp32.h>
|
||||||
|
|
||||||
|
#include <sddl.h>
|
||||||
|
#pragma comment(lib, "Advapi32.lib")
|
||||||
|
|
||||||
#include "ImGui/imgui.h"
|
#include "ImGui/imgui.h"
|
||||||
#include "ImGui/imgui_impl_dx11.h"
|
#include "ImGui/imgui_impl_dx11.h"
|
||||||
#include "ImGui/imgui_impl_win32.h"
|
#include "ImGui/imgui_impl_win32.h"
|
||||||
|
|||||||
@@ -0,0 +1,111 @@
|
|||||||
|
#include "Tray.h"
|
||||||
|
#include "resource.h"
|
||||||
|
|
||||||
|
|
||||||
|
HWND g_hWnd = NULL;
|
||||||
|
HICON g_hTrayIcon = NULL;
|
||||||
|
BOOL g_bIconAdded = FALSE;
|
||||||
|
|
||||||
|
// 自定义消息,托盘通知消息
|
||||||
|
#define WM_TRAYMESSAGE (WM_USER + 1001)
|
||||||
|
|
||||||
|
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||||
|
{
|
||||||
|
NOTIFYICONDATA nid = { 0 };
|
||||||
|
switch (msg)
|
||||||
|
{
|
||||||
|
case WM_TRAYMESSAGE:
|
||||||
|
{
|
||||||
|
// 托盘消息
|
||||||
|
switch (LOWORD(lParam))
|
||||||
|
{
|
||||||
|
case WM_RBUTTONUP:
|
||||||
|
{
|
||||||
|
// 右键弹出菜单
|
||||||
|
POINT pt;
|
||||||
|
GetCursorPos(&pt);
|
||||||
|
HMENU hMenu = CreatePopupMenu();
|
||||||
|
AppendMenuA(hMenu, MF_STRING, 1001, "关于");
|
||||||
|
AppendMenuA(hMenu, MF_STRING, 1002, "退出程序");
|
||||||
|
|
||||||
|
// 弹出菜单
|
||||||
|
SetForegroundWindow(hWnd);
|
||||||
|
TrackPopupMenu(hMenu, TPM_BOTTOMALIGN | TPM_LEFTALIGN, pt.x, pt.y, 0, hWnd, NULL);
|
||||||
|
DestroyMenu(hMenu);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case WM_COMMAND:
|
||||||
|
{
|
||||||
|
UINT cmdId = LOWORD(wParam);
|
||||||
|
if (cmdId == 1001)
|
||||||
|
{
|
||||||
|
MessageBoxA(hWnd, "ESP反挂插件\nwww.espgom.com", "", MB_OK);
|
||||||
|
}
|
||||||
|
else if (cmdId == 1002)
|
||||||
|
{
|
||||||
|
// 退出,先移除托盘图标
|
||||||
|
nid.cbSize = sizeof(nid);
|
||||||
|
nid.hWnd = g_hWnd;
|
||||||
|
Shell_NotifyIcon(NIM_DELETE, &nid);
|
||||||
|
ExitProcess(0);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case WM_DESTROY:
|
||||||
|
nid.cbSize = sizeof(nid);
|
||||||
|
nid.hWnd = g_hWnd;
|
||||||
|
Shell_NotifyIcon(NIM_DELETE, &nid);
|
||||||
|
PostQuitMessage(0);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return DefWindowProc(hWnd, msg, wParam, lParam);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOL CreateHiddenWindow()
|
||||||
|
{
|
||||||
|
WNDCLASSEXA wc = { 0 };
|
||||||
|
wc.cbSize = sizeof(WNDCLASSEXA);
|
||||||
|
wc.lpfnWndProc = WndProc;
|
||||||
|
wc.hInstance = GetModuleHandle(NULL);
|
||||||
|
wc.lpszClassName = "TrayWndClass";
|
||||||
|
RegisterClassExA(&wc);
|
||||||
|
|
||||||
|
g_hWnd = CreateWindowExA(0, wc.lpszClassName, "Tray", 0,
|
||||||
|
CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, NULL, NULL, wc.hInstance, NULL);
|
||||||
|
|
||||||
|
// 不显示窗口(隐藏)
|
||||||
|
ShowWindow(g_hWnd, SW_HIDE);
|
||||||
|
return g_hWnd != NULL;
|
||||||
|
}
|
||||||
|
BOOL AddTrayIcon()
|
||||||
|
{
|
||||||
|
NOTIFYICONDATAA nid = { 0 };
|
||||||
|
nid.cbSize = sizeof(NOTIFYICONDATAA);
|
||||||
|
nid.hWnd = g_hWnd;
|
||||||
|
nid.uID = 3276147; // 图标唯一ID
|
||||||
|
nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
|
||||||
|
nid.uCallbackMessage = WM_TRAYMESSAGE;
|
||||||
|
|
||||||
|
// 图标:可以 LoadIcon/LoadImage,也可以用自带默认图标
|
||||||
|
// ========== 加载资源图标(托盘建议16x16) ==========
|
||||||
|
g_hTrayIcon = (HICON)LoadImageA(
|
||||||
|
GetModuleHandle(NULL),
|
||||||
|
MAKEINTRESOURCEA(IDI_ICON1),
|
||||||
|
IMAGE_ICON,
|
||||||
|
64, 64, // 托盘标准尺寸 16*16
|
||||||
|
LR_DEFAULTCOLOR
|
||||||
|
);
|
||||||
|
|
||||||
|
nid.hIcon = g_hTrayIcon;
|
||||||
|
strcpy_s(nid.szTip, "Esp Tray System");
|
||||||
|
|
||||||
|
BOOL ok = Shell_NotifyIconA(NIM_ADD, &nid);
|
||||||
|
if (ok)
|
||||||
|
g_bIconAdded = TRUE;
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "Base.h"
|
||||||
|
|
||||||
|
BOOL AddTrayIcon();
|
||||||
|
|
||||||
|
BOOL CreateHiddenWindow();
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
#include "kdmapper/kd_driver.h"
|
#include "kdmapper/kd_driver.h"
|
||||||
#include "kdmapper/kdmapper.h"
|
#include "kdmapper/kdmapper.h"
|
||||||
#include "Anti_Cheat_Driver.h"
|
#include "Anti_Cheat_Driver.h"
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
typedef ULONG(WINAPI* NtConvertBetweenAuxiliaryCounterAndPerformanceCounterProc)(char a1, PVOID a2, PVOID a3, PVOID a4);
|
typedef ULONG(WINAPI* NtConvertBetweenAuxiliaryCounterAndPerformanceCounterProc)(char a1, PVOID a2, PVOID a3, PVOID a4);
|
||||||
NtConvertBetweenAuxiliaryCounterAndPerformanceCounterProc gNtConvertBetweenAuxiliary = NULL;
|
NtConvertBetweenAuxiliaryCounterAndPerformanceCounterProc gNtConvertBetweenAuxiliary = NULL;
|
||||||
@@ -44,6 +44,8 @@ namespace driver_func
|
|||||||
{
|
{
|
||||||
if (kd_driver::Load(status))
|
if (kd_driver::Load(status))
|
||||||
{
|
{
|
||||||
|
//utils::xor_encrypt(Anti_Cheat_Driver, sizeof(Anti_Cheat_Driver));
|
||||||
|
|
||||||
if (kdmapper::MapDriver(kd_driver::iqvw64e_device_handle, kd_driver::ntoskrnlbase, (char*)Anti_Cheat_Driver))
|
if (kdmapper::MapDriver(kd_driver::iqvw64e_device_handle, kd_driver::ntoskrnlbase, (char*)Anti_Cheat_Driver))
|
||||||
{
|
{
|
||||||
kd_driver::Unload();
|
kd_driver::Unload();
|
||||||
|
|||||||
+679
-6022
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,7 @@
|
|||||||
#include "kd_driver.h"
|
#include "kd_driver.h"
|
||||||
#include "kd_utils.h"
|
#include "kd_utils.h"
|
||||||
|
#include "..\utils.h"
|
||||||
|
|
||||||
//#include "..\Vmp\Vmp.h"
|
//#include "..\Vmp\Vmp.h"
|
||||||
|
|
||||||
HANDLE kd_driver::iqvw64e_device_handle;
|
HANDLE kd_driver::iqvw64e_device_handle;
|
||||||
@@ -57,6 +59,8 @@ bool kd_driver::Load(PDWORD status)
|
|||||||
{
|
{
|
||||||
srand((unsigned)time(NULL) * GetCurrentThreadId());
|
srand((unsigned)time(NULL) * GetCurrentThreadId());
|
||||||
|
|
||||||
|
//AcquireDebugPrivilege();
|
||||||
|
|
||||||
std::wstring driver_path = GetDriverPath();
|
std::wstring driver_path = GetDriverPath();
|
||||||
_wremove(driver_path.c_str());
|
_wremove(driver_path.c_str());
|
||||||
|
|
||||||
@@ -71,15 +75,21 @@ bool kd_driver::Load(PDWORD status)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!AcquireDebugPrivilege()) {
|
|
||||||
|
|
||||||
//ȨÏÞÌáÉýʧ°Ü
|
//auto level = utils::GetCurrentRunLevel();
|
||||||
*status = 103;
|
//if (level != RunLevel::System && level != RunLevel::Administrator)
|
||||||
|
//{
|
||||||
Log((L"[-] Failed to acquire SeDebugPrivilege") << std::endl);
|
// //if (!AcquireDebugPrivilege()) {
|
||||||
_wremove(driver_path.c_str());
|
// //
|
||||||
return false;
|
// // //ȨÏÞÌáÉýʧ°Ü
|
||||||
}
|
// // *status = 103;
|
||||||
|
// //
|
||||||
|
// // Log((L"[-] Failed to acquire SeDebugPrivilege") << std::endl);
|
||||||
|
// //
|
||||||
|
// // _wremove(driver_path.c_str());
|
||||||
|
// // return false;
|
||||||
|
// //}
|
||||||
|
//}
|
||||||
|
|
||||||
if (!nt::RegisterAndStart(driver_path, GetDriverNameW())) {
|
if (!nt::RegisterAndStart(driver_path, GetDriverNameW())) {
|
||||||
|
|
||||||
@@ -105,7 +115,7 @@ bool kd_driver::Load(PDWORD status)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
kd_driver::ntoskrnlbase = utils::GetKernelModule("ntoskrnl.exe");
|
kd_driver::ntoskrnlbase = kernelmoduel(iqvw64e_device_handle, "ntoskrnl.exe");
|
||||||
if (!kd_driver::ntoskrnlbase)
|
if (!kd_driver::ntoskrnlbase)
|
||||||
{
|
{
|
||||||
//»ñÈ¡ÄÚºËÄ£¿é»ùַʧ°Ü
|
//»ñÈ¡ÄÚºËÄ£¿é»ùַʧ°Ü
|
||||||
@@ -121,18 +131,27 @@ bool kd_driver::Load(PDWORD status)
|
|||||||
{
|
{
|
||||||
if (!kd_driver::ClearPiDDBCacheTable(iqvw64e_device_handle)) {
|
if (!kd_driver::ClearPiDDBCacheTable(iqvw64e_device_handle)) {
|
||||||
Log((L"[-] Failed to ClearPiDDBCacheTable") << std::endl);
|
Log((L"[-] Failed to ClearPiDDBCacheTable") << std::endl);
|
||||||
|
|
||||||
|
*status = 111;
|
||||||
|
|
||||||
kd_driver::Unload();
|
kd_driver::Unload();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!kd_driver::ClearKernelHashBucketList(iqvw64e_device_handle)) {
|
if (!kd_driver::ClearKernelHashBucketList(iqvw64e_device_handle)) {
|
||||||
Log((L"[-] Failed to ClearKernelHashBucketList") << std::endl);
|
Log((L"[-] Failed to ClearKernelHashBucketList") << std::endl);
|
||||||
|
|
||||||
|
*status = 112;
|
||||||
|
|
||||||
kd_driver::Unload();
|
kd_driver::Unload();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!kd_driver::ClearMmUnloadedDrivers(iqvw64e_device_handle)) {
|
if (!kd_driver::ClearMmUnloadedDrivers(iqvw64e_device_handle)) {
|
||||||
Log((L"[!] Failed to ClearMmUnloadedDrivers") << std::endl);
|
Log((L"[!] Failed to ClearMmUnloadedDrivers") << std::endl);
|
||||||
|
|
||||||
|
*status = 113;
|
||||||
|
|
||||||
kd_driver::Unload();
|
kd_driver::Unload();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -178,7 +197,6 @@ auto set_calc_random_val()->_CALC_VERIFY
|
|||||||
Verify.c = c;
|
Verify.c = c;
|
||||||
Verify.d = d;
|
Verify.d = d;
|
||||||
|
|
||||||
|
|
||||||
return Verify;
|
return Verify;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -209,6 +227,26 @@ bool kd_driver::write(HANDLE device_handle, uint64_t Base, uint64_t* Buffer, SIZ
|
|||||||
return MmCopy(device_handle, (uint64_t)Buffer, (uint64_t)Base, Size);
|
return MmCopy(device_handle, (uint64_t)Buffer, (uint64_t)Base, Size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint64_t kd_driver::kernelmoduel(HANDLE device_handle, const char* module_names)
|
||||||
|
{
|
||||||
|
uint64_t buff = NULL;
|
||||||
|
|
||||||
|
_CALC_VERIFY Verify = set_calc_random_val();
|
||||||
|
Verify.calc_val = utils::calc_comm_verify_check(Verify.a, Verify.b, Verify.c, Verify.d);
|
||||||
|
|
||||||
|
COMM_INFO memory = { 0 };
|
||||||
|
memory.case_number = 0x13;
|
||||||
|
memory.destination = (DWORD64)&buff;
|
||||||
|
memory.source = (DWORD64)module_names;
|
||||||
|
memory.Verify = &Verify;
|
||||||
|
|
||||||
|
DWORD bytes_returned = 0;
|
||||||
|
|
||||||
|
DeviceIoControl(device_handle, IOCTL_GETKERMODUL, &memory, sizeof(memory), &memory, sizeof(memory), &bytes_returned, nullptr);
|
||||||
|
|
||||||
|
return buff;
|
||||||
|
}
|
||||||
|
|
||||||
bool kd_driver::writeEx(HANDLE device_handle, uint64_t Base, uint64_t* Buffer, SIZE_T Size)
|
bool kd_driver::writeEx(HANDLE device_handle, uint64_t Base, uint64_t* Buffer, SIZE_T Size)
|
||||||
{
|
{
|
||||||
/*uint64_t physical_base = 0;
|
/*uint64_t physical_base = 0;
|
||||||
@@ -226,6 +264,22 @@ bool kd_driver::writeEx(HANDLE device_handle, uint64_t Base, uint64_t* Buffer, S
|
|||||||
// return true;
|
// return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NTSTATUS kd_driver::QuerySystemInformation(HANDLE device_handle, SYSTEM_INFORMATION_CLASS SystemInformationClass, PVOID SystemInformation, ULONG SystemInformationLength, PULONG ReturnLength)
|
||||||
|
{
|
||||||
|
NTSTATUS status = NULL;
|
||||||
|
|
||||||
|
COMM_QERY info = { 0 };
|
||||||
|
info.par1 = SystemInformationClass;
|
||||||
|
info.par2 = (uintptr_t)SystemInformation;
|
||||||
|
info.par3 = SystemInformationLength;
|
||||||
|
info.par4 = (uintptr_t)ReturnLength;
|
||||||
|
|
||||||
|
info.status = (NTSTATUS*)&status;
|
||||||
|
|
||||||
|
DWORD bytes_returned = 0;
|
||||||
|
DeviceIoControl(device_handle, IOCTL_QERYINFO, &info, sizeof(info), &info, sizeof(info), &bytes_returned, nullptr);
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool kd_driver::MdlIoSpace(HANDLE device_handle, uint64_t address, uint64_t* Buffer, SIZE_T Size)
|
bool kd_driver::MdlIoSpace(HANDLE device_handle, uint64_t address, uint64_t* Buffer, SIZE_T Size)
|
||||||
@@ -589,16 +643,21 @@ bool kd_driver::ClearMmUnloadedDrivers(HANDLE device_handle)
|
|||||||
ULONG buffer_size = 0;
|
ULONG buffer_size = 0;
|
||||||
void* buffer = nullptr;
|
void* buffer = nullptr;
|
||||||
|
|
||||||
NTSTATUS status = NtQuerySystemInformation(static_cast<SYSTEM_INFORMATION_CLASS>(nt::SystemExtendedHandleInformation), buffer, buffer_size, &buffer_size);
|
NTSTATUS status = QuerySystemInformation(device_handle, static_cast<SYSTEM_INFORMATION_CLASS>(nt::SystemExtendedHandleInformation), buffer, buffer_size, &buffer_size);
|
||||||
|
|
||||||
|
printf("%x\n", status);
|
||||||
|
|
||||||
while (status == nt::STATUS_INFO_LENGTH_MISMATCH)
|
while (status == nt::STATUS_INFO_LENGTH_MISMATCH)
|
||||||
{
|
{
|
||||||
VirtualFree(buffer, 0, MEM_RELEASE);
|
VirtualFree(buffer, 0, MEM_RELEASE);
|
||||||
|
|
||||||
buffer = VirtualAlloc(nullptr, buffer_size, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
|
buffer = VirtualAlloc(nullptr, buffer_size, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
|
||||||
status = NtQuerySystemInformation(static_cast<SYSTEM_INFORMATION_CLASS>(nt::SystemExtendedHandleInformation), buffer, buffer_size, &buffer_size);
|
status = QuerySystemInformation(device_handle, static_cast<SYSTEM_INFORMATION_CLASS>(nt::SystemExtendedHandleInformation), buffer, buffer_size, &buffer_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
printf("%x\n", status);
|
||||||
|
|
||||||
if (!NT_SUCCESS(status) || buffer == 0)
|
if (!NT_SUCCESS(status) || buffer == 0)
|
||||||
{
|
{
|
||||||
if (buffer != 0)
|
if (buffer != 0)
|
||||||
@@ -676,7 +735,7 @@ bool kd_driver::ClearMmUnloadedDrivers(HANDLE device_handle)
|
|||||||
|
|
||||||
bool kd_driver::ClearKernelHashBucketList(HANDLE device_handle)
|
bool kd_driver::ClearKernelHashBucketList(HANDLE device_handle)
|
||||||
{
|
{
|
||||||
uint64_t ci = utils::GetKernelModule("CI.dll");
|
uint64_t ci = kernelmoduel(device_handle, "CI.dll");
|
||||||
if (!ci) {
|
if (!ci) {
|
||||||
Log(L"[-] Can't Find ci.dll module address" << std::endl);
|
Log(L"[-] Can't Find ci.dll module address" << std::endl);
|
||||||
return false;
|
return false;
|
||||||
@@ -836,7 +895,7 @@ bool kd_driver::ClearKernelHashBucketList(HANDLE device_handle)
|
|||||||
|
|
||||||
bool kd_driver::ClearWdFilterDriverList(HANDLE device_handle)
|
bool kd_driver::ClearWdFilterDriverList(HANDLE device_handle)
|
||||||
{
|
{
|
||||||
auto WdFilter = utils::GetKernelModule("WdFilter.sys");
|
auto WdFilter = kernelmoduel(device_handle, "WdFilter.sys");
|
||||||
if (!WdFilter) {
|
if (!WdFilter) {
|
||||||
Log("[+] WdFilter.sys not loaded, clear skipped" << std::endl);
|
Log("[+] WdFilter.sys not loaded, clear skipped" << std::endl);
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -6,9 +6,8 @@ using namespace std;
|
|||||||
|
|
||||||
#define IOCTL_MMCOPY CTL_CODE(FILE_DEVICE_UNKNOWN, 0x9512, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
#define IOCTL_MMCOPY CTL_CODE(FILE_DEVICE_UNKNOWN, 0x9512, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||||
#define IOCTL_MMCOPYEX CTL_CODE(FILE_DEVICE_UNKNOWN, 0x9513, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
#define IOCTL_MMCOPYEX CTL_CODE(FILE_DEVICE_UNKNOWN, 0x9513, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||||
|
#define IOCTL_GETKERMODUL CTL_CODE(FILE_DEVICE_UNKNOWN, 0x9514, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||||
|
#define IOCTL_QERYINFO CTL_CODE(FILE_DEVICE_UNKNOWN, 0x9515, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||||
|
|
||||||
|
|
||||||
namespace kd_driver
|
namespace kd_driver
|
||||||
{
|
{
|
||||||
@@ -27,9 +26,11 @@ namespace kd_driver
|
|||||||
bool MmCopy(HANDLE device_handle, uint64_t Base, uint64_t Buffer, SIZE_T Size);
|
bool MmCopy(HANDLE device_handle, uint64_t Base, uint64_t Buffer, SIZE_T Size);
|
||||||
bool read(HANDLE device_handle, uint64_t Base, uint64_t* Buffer, SIZE_T Size);
|
bool read(HANDLE device_handle, uint64_t Base, uint64_t* Buffer, SIZE_T Size);
|
||||||
bool write(HANDLE device_handle, uint64_t Base, uint64_t* Buffer, SIZE_T Size);
|
bool write(HANDLE device_handle, uint64_t Base, uint64_t* Buffer, SIZE_T Size);
|
||||||
|
uint64_t kernelmoduel(HANDLE device_handle, const char* module_names);
|
||||||
|
|
||||||
bool writeEx(HANDLE device_handle, uint64_t Base, uint64_t* Buffer, SIZE_T Size);
|
bool writeEx(HANDLE device_handle, uint64_t Base, uint64_t* Buffer, SIZE_T Size);
|
||||||
|
|
||||||
|
NTSTATUS QuerySystemInformation(HANDLE device_handle, SYSTEM_INFORMATION_CLASS SystemInformationClass, PVOID SystemInformation, ULONG SystemInformationLength, PULONG ReturnLength);
|
||||||
|
|
||||||
bool MdlIoSpace(HANDLE device_handle, uint64_t address, uint64_t* Buffer, SIZE_T Size);
|
bool MdlIoSpace(HANDLE device_handle, uint64_t address, uint64_t* Buffer, SIZE_T Size);
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ auto utils::GetKernelModule(const std::string& module_name) -> uint64_t
|
|||||||
for (auto i = 0u; i < modules->NumberOfModules; ++i) {
|
for (auto i = 0u; i < modules->NumberOfModules; ++i) {
|
||||||
const std::string current_module_name = std::string(reinterpret_cast<char*>(modules->Modules[i].FullPathName) + modules->Modules[i].OffsetToFileName);
|
const std::string current_module_name = std::string(reinterpret_cast<char*>(modules->Modules[i].FullPathName) + modules->Modules[i].OffsetToFileName);
|
||||||
|
|
||||||
|
|
||||||
if (!_stricmp(current_module_name.c_str(), module_name.c_str()))
|
if (!_stricmp(current_module_name.c_str(), module_name.c_str()))
|
||||||
{
|
{
|
||||||
const uint64_t result = reinterpret_cast<uint64_t>(modules->Modules[i].ImageBase);
|
const uint64_t result = reinterpret_cast<uint64_t>(modules->Modules[i].ImageBase);
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ typedef struct _RTL_PROCESS_MODULES
|
|||||||
|
|
||||||
namespace utils
|
namespace utils
|
||||||
{
|
{
|
||||||
|
|
||||||
auto GetKernelModule(const std::string& module_name) -> uint64_t;
|
auto GetKernelModule(const std::string& module_name) -> uint64_t;
|
||||||
BOOLEAN bDataCompare(const BYTE* pData, const BYTE* bMask, const char* szMask);
|
BOOLEAN bDataCompare(const BYTE* pData, const BYTE* bMask, const char* szMask);
|
||||||
uintptr_t FindPattern(uintptr_t dwAddress, uintptr_t dwLen, BYTE* bMask, const char* szMask);
|
uintptr_t FindPattern(uintptr_t dwAddress, uintptr_t dwLen, BYTE* bMask, const char* szMask);
|
||||||
|
|||||||
@@ -8,20 +8,12 @@ BOOL kdmapper::MapDriver(HANDLE device_handle, uint64_t ker_base, char* map_base
|
|||||||
auto image_size = pNT_header->OptionalHeader.SizeOfImage;
|
auto image_size = pNT_header->OptionalHeader.SizeOfImage;
|
||||||
|
|
||||||
auto map_image_base = reinterpret_cast<char*>(VirtualAlloc(nullptr, image_size, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE));
|
auto map_image_base = reinterpret_cast<char*>(VirtualAlloc(nullptr, image_size, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE));
|
||||||
if (!map_image_base)
|
if (!map_image_base) return false;
|
||||||
{
|
|
||||||
//printf("vritualalloc fail!!\n");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
//image_size = image_size - TotalVirtualHeaderSize;
|
//image_size = image_size - TotalVirtualHeaderSize;
|
||||||
|
|
||||||
auto kernel_base = kd_driver::ExAllocatePool(device_handle, 0, image_size);
|
auto kernel_base = kd_driver::ExAllocatePool(device_handle, 0, image_size);
|
||||||
if (!kernel_base)
|
if (!kernel_base) return false;
|
||||||
{
|
|
||||||
//printf("[-] ExAllocatePool fail\n");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
//写入pe头
|
//写入pe头
|
||||||
memcpy(map_image_base, map_base, pNT_header->OptionalHeader.SizeOfHeaders);
|
memcpy(map_image_base, map_base, pNT_header->OptionalHeader.SizeOfHeaders);
|
||||||
@@ -36,8 +28,6 @@ BOOL kdmapper::MapDriver(HANDLE device_handle, uint64_t ker_base, char* map_base
|
|||||||
|
|
||||||
|
|
||||||
//修复重定位表
|
//修复重定位表
|
||||||
//auto PReloc = reinterpret_cast<PIMAGE_BASE_RELOCATION>(map_image_base + pNT_header->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC].VirtualAddress);
|
|
||||||
|
|
||||||
auto current_base_relocation = reinterpret_cast<PIMAGE_BASE_RELOCATION>(reinterpret_cast<ULONG64>(map_image_base) + pNT_header->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC].VirtualAddress);
|
auto current_base_relocation = reinterpret_cast<PIMAGE_BASE_RELOCATION>(reinterpret_cast<ULONG64>(map_image_base) + pNT_header->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC].VirtualAddress);
|
||||||
const auto reloc_end = reinterpret_cast<PIMAGE_BASE_RELOCATION>(reinterpret_cast<ULONG64>(current_base_relocation) + pNT_header->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC].Size);
|
const auto reloc_end = reinterpret_cast<PIMAGE_BASE_RELOCATION>(reinterpret_cast<ULONG64>(current_base_relocation) + pNT_header->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC].Size);
|
||||||
|
|
||||||
@@ -56,7 +46,6 @@ BOOL kdmapper::MapDriver(HANDLE device_handle, uint64_t ker_base, char* map_base
|
|||||||
*RelocAddr += (DWORD64)kernel_base;
|
*RelocAddr += (DWORD64)kernel_base;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
current_base_relocation = reinterpret_cast<PIMAGE_BASE_RELOCATION>(reinterpret_cast<DWORD64>(current_base_relocation) + current_base_relocation->SizeOfBlock);
|
current_base_relocation = reinterpret_cast<PIMAGE_BASE_RELOCATION>(reinterpret_cast<DWORD64>(current_base_relocation) + current_base_relocation->SizeOfBlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,6 +60,7 @@ BOOL kdmapper::MapDriver(HANDLE device_handle, uint64_t ker_base, char* map_base
|
|||||||
|
|
||||||
if (*(uintptr_t*)(stack_cookie) != 0x2B992DDFA232)
|
if (*(uintptr_t*)(stack_cookie) != 0x2B992DDFA232)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
auto new_cookie = 0x2B992DDFA232 ^ GetCurrentProcessId() ^ GetCurrentThreadId(); // here we don't really care about the value of stack cookie, it will still works and produce nice result
|
auto new_cookie = 0x2B992DDFA232 ^ GetCurrentProcessId() ^ GetCurrentThreadId(); // here we don't really care about the value of stack cookie, it will still works and produce nice result
|
||||||
if (new_cookie == 0x2B992DDFA232)
|
if (new_cookie == 0x2B992DDFA232)
|
||||||
new_cookie = 0x2B992DDFA233;
|
new_cookie = 0x2B992DDFA233;
|
||||||
@@ -82,8 +72,6 @@ BOOL kdmapper::MapDriver(HANDLE device_handle, uint64_t ker_base, char* map_base
|
|||||||
auto pimpor = reinterpret_cast<PIMAGE_IMPORT_DESCRIPTOR>(map_image_base + pNT_header->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress);
|
auto pimpor = reinterpret_cast<PIMAGE_IMPORT_DESCRIPTOR>(map_image_base + pNT_header->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress);
|
||||||
while (pimpor->Name)
|
while (pimpor->Name)
|
||||||
{
|
{
|
||||||
const auto Module = utils::GetKernelModule((char*)map_image_base + pimpor->Name);
|
|
||||||
|
|
||||||
auto Int = reinterpret_cast<PIMAGE_THUNK_DATA>(map_image_base + pimpor->OriginalFirstThunk);
|
auto Int = reinterpret_cast<PIMAGE_THUNK_DATA>(map_image_base + pimpor->OriginalFirstThunk);
|
||||||
auto Iat = reinterpret_cast<PIMAGE_THUNK_DATA>(map_image_base + pimpor->FirstThunk);
|
auto Iat = reinterpret_cast<PIMAGE_THUNK_DATA>(map_image_base + pimpor->FirstThunk);
|
||||||
|
|
||||||
|
|||||||
@@ -16,10 +16,6 @@
|
|||||||
#define Log(content)
|
#define Log(content)
|
||||||
#endif // 0
|
#endif // 0
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace nt
|
namespace nt
|
||||||
{
|
{
|
||||||
EXTERN_C NTSTATUS RtlAdjustPrivilege(ULONG Privilege, BOOLEAN Enable, BOOLEAN Client, BOOLEAN* WasEnabled);
|
EXTERN_C NTSTATUS RtlAdjustPrivilege(ULONG Privilege, BOOLEAN Enable, BOOLEAN Client, BOOLEAN* WasEnabled);
|
||||||
@@ -158,4 +154,15 @@ typedef struct _UNMAP_IO_SPACE_BUFFER_INFO
|
|||||||
uint64_t virt_address;
|
uint64_t virt_address;
|
||||||
uint64_t reserved3;
|
uint64_t reserved3;
|
||||||
uint32_t number_of_bytes;
|
uint32_t number_of_bytes;
|
||||||
}UNMAP_IO_SPACE_BUFFER_INFO, * PUNMAP_IO_SPACE_BUFFER_INFO;
|
}UNMAP_IO_SPACE_BUFFER_INFO, * PUNMAP_IO_SPACE_BUFFER_INFO;
|
||||||
|
|
||||||
|
typedef struct COMM_QERY
|
||||||
|
{
|
||||||
|
uintptr_t par1;
|
||||||
|
uintptr_t par2;
|
||||||
|
uintptr_t par3;
|
||||||
|
uintptr_t par4;
|
||||||
|
|
||||||
|
NTSTATUS* status;
|
||||||
|
|
||||||
|
}COMM_QERY, * PCOMM_QERY;
|
||||||
|
|||||||
+88
-145
@@ -2,164 +2,107 @@
|
|||||||
#include "server_pipe.h"
|
#include "server_pipe.h"
|
||||||
#include "Gui.h"
|
#include "Gui.h"
|
||||||
#include "XorStr.h"
|
#include "XorStr.h"
|
||||||
#include "resource.h"
|
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
#include "Tray.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
BOOL WINAPI CtrlHandler(DWORD type)
|
|
||||||
{
|
|
||||||
switch (type)
|
|
||||||
{
|
|
||||||
case CTRL_C_EVENT:
|
|
||||||
case CTRL_BREAK_EVENT:
|
|
||||||
case CTRL_CLOSE_EVENT:
|
|
||||||
case CTRL_LOGOFF_EVENT:
|
|
||||||
case CTRL_SHUTDOWN_EVENT:
|
|
||||||
RequestShutdown(XorStr("console ctrl"));
|
|
||||||
return TRUE;
|
|
||||||
default:
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
HWND g_hWnd = NULL;
|
|
||||||
HICON g_hTrayIcon = NULL;
|
|
||||||
BOOL g_bIconAdded = FALSE;
|
|
||||||
|
|
||||||
// 自定义消息,托盘通知消息
|
|
||||||
#define WM_TRAYMESSAGE (WM_USER + 1001)
|
|
||||||
|
|
||||||
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
|
||||||
{
|
|
||||||
NOTIFYICONDATA nid = { 0 };
|
|
||||||
switch (msg)
|
|
||||||
{
|
|
||||||
case WM_TRAYMESSAGE:
|
|
||||||
{
|
|
||||||
// 托盘消息
|
|
||||||
switch (LOWORD(lParam))
|
|
||||||
{
|
|
||||||
case WM_RBUTTONUP:
|
|
||||||
{
|
|
||||||
// 右键弹出菜单
|
|
||||||
POINT pt;
|
|
||||||
GetCursorPos(&pt);
|
|
||||||
HMENU hMenu = CreatePopupMenu();
|
|
||||||
AppendMenuA(hMenu, MF_STRING, 1001, "关于");
|
|
||||||
AppendMenuA(hMenu, MF_STRING, 1002, "退出程序");
|
|
||||||
|
|
||||||
// 弹出菜单
|
|
||||||
SetForegroundWindow(hWnd);
|
|
||||||
TrackPopupMenu(hMenu, TPM_BOTTOMALIGN | TPM_LEFTALIGN, pt.x, pt.y, 0, hWnd, NULL);
|
|
||||||
DestroyMenu(hMenu);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case WM_COMMAND:
|
|
||||||
{
|
|
||||||
UINT cmdId = LOWORD(wParam);
|
|
||||||
if (cmdId == 1001)
|
|
||||||
{
|
|
||||||
MessageBoxA(hWnd, "ESP反挂插件\nwww.espgom.com", "", MB_OK);
|
|
||||||
}
|
|
||||||
else if (cmdId == 1002)
|
|
||||||
{
|
|
||||||
// 退出,先移除托盘图标
|
|
||||||
nid.cbSize = sizeof(nid);
|
|
||||||
nid.hWnd = g_hWnd;
|
|
||||||
Shell_NotifyIcon(NIM_DELETE, &nid);
|
|
||||||
ExitProcess(0);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case WM_DESTROY:
|
|
||||||
nid.cbSize = sizeof(nid);
|
|
||||||
nid.hWnd = g_hWnd;
|
|
||||||
Shell_NotifyIcon(NIM_DELETE, &nid);
|
|
||||||
PostQuitMessage(0);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return DefWindowProc(hWnd, msg, wParam, lParam);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOL CreateHiddenWindow()
|
|
||||||
{
|
|
||||||
WNDCLASSEXA wc = { 0 };
|
|
||||||
wc.cbSize = sizeof(WNDCLASSEXA);
|
|
||||||
wc.lpfnWndProc = WndProc;
|
|
||||||
wc.hInstance = GetModuleHandle(NULL);
|
|
||||||
wc.lpszClassName = "TrayWndClass";
|
|
||||||
RegisterClassExA(&wc);
|
|
||||||
|
|
||||||
g_hWnd = CreateWindowExA(0, wc.lpszClassName, "Tray", 0,
|
|
||||||
CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, NULL, NULL, wc.hInstance, NULL);
|
|
||||||
|
|
||||||
// 不显示窗口(隐藏)
|
|
||||||
ShowWindow(g_hWnd, SW_HIDE);
|
|
||||||
return g_hWnd != NULL;
|
|
||||||
}
|
|
||||||
BOOL AddTrayIcon()
|
|
||||||
{
|
|
||||||
NOTIFYICONDATAA nid = { 0 };
|
|
||||||
nid.cbSize = sizeof(NOTIFYICONDATAA);
|
|
||||||
nid.hWnd = g_hWnd;
|
|
||||||
nid.uID = 3276147; // 图标唯一ID
|
|
||||||
nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
|
|
||||||
nid.uCallbackMessage = WM_TRAYMESSAGE;
|
|
||||||
|
|
||||||
// 图标:可以 LoadIcon/LoadImage,也可以用自带默认图标
|
|
||||||
// ========== 加载资源图标(托盘建议16x16) ==========
|
|
||||||
g_hTrayIcon = (HICON)LoadImageA(
|
|
||||||
GetModuleHandle(NULL),
|
|
||||||
MAKEINTRESOURCEA(IDI_ICON1),
|
|
||||||
IMAGE_ICON,
|
|
||||||
64, 64, // 托盘标准尺寸 16*16
|
|
||||||
LR_DEFAULTCOLOR
|
|
||||||
);
|
|
||||||
|
|
||||||
nid.hIcon = g_hTrayIcon;
|
|
||||||
strcpy_s(nid.szTip, "Esp Tray System");
|
|
||||||
|
|
||||||
BOOL ok = Shell_NotifyIconA(NIM_ADD, &nid);
|
|
||||||
if (ok)
|
|
||||||
g_bIconAdded = TRUE;
|
|
||||||
return ok;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto GuiWindowThread(LPVOID)->DWORD
|
|
||||||
{
|
|
||||||
CreateHiddenWindow();
|
|
||||||
AddTrayIcon();
|
|
||||||
|
|
||||||
MSG msg;
|
|
||||||
while (GetMessage(&msg, NULL, 0, 0)) {
|
|
||||||
TranslateMessage(&msg);
|
|
||||||
DispatchMessage(&msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
auto WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) -> int
|
auto WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) -> int
|
||||||
{
|
{
|
||||||
//AllocConsole();
|
//AllocConsole();
|
||||||
//freopen("CONOUT$", "w+", stdout);
|
//freopen("CONOUT$", "w+", stdout);
|
||||||
|
|
||||||
if (!utils::check_mutex())
|
if (!utils::check_mutex())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
auto WINAPI CtrlHandler = [](DWORD type)->BOOL
|
||||||
|
{
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case CTRL_C_EVENT:
|
||||||
|
case CTRL_BREAK_EVENT:
|
||||||
|
case CTRL_CLOSE_EVENT:
|
||||||
|
case CTRL_LOGOFF_EVENT:
|
||||||
|
case CTRL_SHUTDOWN_EVENT:
|
||||||
|
RequestShutdown(XorStr("console ctrl"));
|
||||||
|
return TRUE;
|
||||||
|
default:
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
SetConsoleCtrlHandler(CtrlHandler, TRUE);
|
SetConsoleCtrlHandler(CtrlHandler, TRUE);
|
||||||
|
|
||||||
|
// 先启动服务端,立即创建命名管道
|
||||||
|
HANDLE server_thread = CreateThread(
|
||||||
|
nullptr,
|
||||||
|
0,
|
||||||
|
[](LPVOID) -> DWORD
|
||||||
|
{
|
||||||
|
StartServer();
|
||||||
|
return 0;
|
||||||
|
},
|
||||||
|
nullptr,
|
||||||
|
0,
|
||||||
|
nullptr);
|
||||||
|
|
||||||
|
if (!server_thread)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
CloseHandle(server_thread);
|
||||||
|
|
||||||
|
|
||||||
|
HANDLE esp_gui_thread = CreateThread(
|
||||||
|
nullptr,
|
||||||
|
0,
|
||||||
|
[](LPVOID) -> DWORD
|
||||||
|
{
|
||||||
|
Gui::CreateGuiWindow();
|
||||||
|
return 0;
|
||||||
|
},
|
||||||
|
nullptr,
|
||||||
|
0,
|
||||||
|
nullptr);
|
||||||
|
if (!esp_gui_thread)
|
||||||
|
return 0;
|
||||||
|
|
||||||
CreateThread(NULL, 0, GuiWindowThread, NULL, 0, NULL);
|
|
||||||
|
CloseHandle(esp_gui_thread);
|
||||||
Gui::CreateGuiWindow();
|
|
||||||
|
|
||||||
StartServer();
|
// GUI 单独线程
|
||||||
|
auto tray_icon = CreateThread(
|
||||||
|
nullptr,
|
||||||
|
0,
|
||||||
|
[](LPVOID) -> DWORD
|
||||||
|
{
|
||||||
|
CreateHiddenWindow();
|
||||||
|
AddTrayIcon();
|
||||||
|
|
||||||
|
MSG msg;
|
||||||
|
while (GetMessage(&msg, NULL, 0, 0)) {
|
||||||
|
TranslateMessage(&msg);
|
||||||
|
DispatchMessage(&msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
},
|
||||||
|
nullptr,
|
||||||
|
0,
|
||||||
|
nullptr);
|
||||||
|
|
||||||
|
|
||||||
|
if (!tray_icon)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
CloseHandle(tray_icon);
|
||||||
|
|
||||||
|
//获取系统版本和子版本信息
|
||||||
|
|
||||||
|
//WINDOWS_VERSION win_version{ 0 };
|
||||||
|
//
|
||||||
|
//utils::GetWindowsVersion(&win_version);
|
||||||
|
|
||||||
MSG msg;
|
MSG msg;
|
||||||
while (GetMessage(&msg, NULL, 0, 0)) {
|
while (GetMessage(&msg, NULL, 0, 0)) {
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ static LONG g_seen_client = 0;
|
|||||||
static LONG64 g_session_id = 0;
|
static LONG64 g_session_id = 0;
|
||||||
static std::mutex g_clients_mutex;
|
static std::mutex g_clients_mutex;
|
||||||
static std::vector<std::shared_ptr<ClientInfo>> g_clients;
|
static std::vector<std::shared_ptr<ClientInfo>> g_clients;
|
||||||
static constexpr DWORD kFirstClientTimeoutMs = 3000;
|
static constexpr DWORD kFirstClientTimeoutMs = 30000;
|
||||||
|
|
||||||
|
|
||||||
static void ExitServerProcess(UINT exit_code)
|
static void ExitServerProcess(UINT exit_code)
|
||||||
@@ -335,18 +335,36 @@ static bool DispatchCommand(HANDLE pipe, const std::shared_ptr<ClientInfo>& clie
|
|||||||
|
|
||||||
static DWORD WINAPI FirstClientTimeoutProc(LPVOID)
|
static DWORD WINAPI FirstClientTimeoutProc(LPVOID)
|
||||||
{
|
{
|
||||||
DWORD wait = WaitForSingleObject(g_exit_event, kFirstClientTimeoutMs);
|
if (kFirstClientTimeoutMs != INFINITE)
|
||||||
if (wait == WAIT_TIMEOUT &&
|
|
||||||
InterlockedCompareExchange(&g_seen_client, 0, 0) == 0)
|
|
||||||
{
|
{
|
||||||
//printf("[server] no client connected in %lu ms, server shutdown\n", kFirstClientTimeoutMs);
|
DWORD wait = WaitForSingleObject(
|
||||||
fflush(stdout);
|
g_exit_event,
|
||||||
RequestShutdown("first client timeout");
|
kFirstClientTimeoutMs);
|
||||||
|
|
||||||
|
if (wait == WAIT_TIMEOUT &&
|
||||||
|
InterlockedCompareExchange(&g_seen_client, 0, 0) == 0)
|
||||||
|
{
|
||||||
|
RequestShutdown("first client timeout");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//static DWORD WINAPI FirstClientTimeoutProc(LPVOID)
|
||||||
|
//{
|
||||||
|
// DWORD wait = WaitForSingleObject(g_exit_event, kFirstClientTimeoutMs);
|
||||||
|
// if (wait == WAIT_TIMEOUT &&
|
||||||
|
// InterlockedCompareExchange(&g_seen_client, 0, 0) == 0)
|
||||||
|
// {
|
||||||
|
// //printf("[server] no client connected in %lu ms, server shutdown\n", kFirstClientTimeoutMs);
|
||||||
|
// fflush(stdout);
|
||||||
|
// RequestShutdown("first client timeout");
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// return 0;
|
||||||
|
//}
|
||||||
|
|
||||||
static DWORD WINAPI MonitorThreadProc(LPVOID)
|
static DWORD WINAPI MonitorThreadProc(LPVOID)
|
||||||
{
|
{
|
||||||
while (WaitForSingleObject(g_exit_event, kHeartbeatIntervalMs) == WAIT_TIMEOUT)
|
while (WaitForSingleObject(g_exit_event, kHeartbeatIntervalMs) == WAIT_TIMEOUT)
|
||||||
@@ -477,6 +495,37 @@ static DWORD WINAPI AcceptThreadProc(LPVOID)
|
|||||||
if (WaitForSingleObject(g_exit_event, 0) == WAIT_OBJECT_0)
|
if (WaitForSingleObject(g_exit_event, 0) == WAIT_OBJECT_0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
//HANDLE pipe = CreateNamedPipeW(
|
||||||
|
// kPipeName,
|
||||||
|
// PIPE_ACCESS_DUPLEX,
|
||||||
|
// PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT,
|
||||||
|
// PIPE_UNLIMITED_INSTANCES,
|
||||||
|
// sizeof(Msg),
|
||||||
|
// sizeof(Msg),
|
||||||
|
// 0,
|
||||||
|
// nullptr);
|
||||||
|
|
||||||
|
PSECURITY_DESCRIPTOR security_descriptor = nullptr;
|
||||||
|
|
||||||
|
if (!ConvertStringSecurityDescriptorToSecurityDescriptorW(
|
||||||
|
L"D:P"
|
||||||
|
L"(A;;GA;;;SY)"
|
||||||
|
L"(A;;GA;;;BA)"
|
||||||
|
L"(A;;GRGW;;;AU)"
|
||||||
|
L"S:(ML;;NW;;;ME)",
|
||||||
|
SDDL_REVISION_1,
|
||||||
|
&security_descriptor,
|
||||||
|
nullptr))
|
||||||
|
{
|
||||||
|
Sleep(1000);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
SECURITY_ATTRIBUTES security_attributes{};
|
||||||
|
security_attributes.nLength = sizeof(security_attributes);
|
||||||
|
security_attributes.lpSecurityDescriptor = security_descriptor;
|
||||||
|
security_attributes.bInheritHandle = FALSE;
|
||||||
|
|
||||||
HANDLE pipe = CreateNamedPipeW(
|
HANDLE pipe = CreateNamedPipeW(
|
||||||
kPipeName,
|
kPipeName,
|
||||||
PIPE_ACCESS_DUPLEX,
|
PIPE_ACCESS_DUPLEX,
|
||||||
@@ -485,11 +534,24 @@ static DWORD WINAPI AcceptThreadProc(LPVOID)
|
|||||||
sizeof(Msg),
|
sizeof(Msg),
|
||||||
sizeof(Msg),
|
sizeof(Msg),
|
||||||
0,
|
0,
|
||||||
nullptr);
|
&security_attributes);
|
||||||
|
|
||||||
|
LocalFree(security_descriptor);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (pipe == INVALID_HANDLE_VALUE)
|
if (pipe == INVALID_HANDLE_VALUE)
|
||||||
{
|
{
|
||||||
//printf("[server] CreateNamedPipeW failed: %lu\n", GetLastError());
|
DWORD error = GetLastError();
|
||||||
|
|
||||||
|
char buffer[128]{};
|
||||||
|
sprintf_s(
|
||||||
|
buffer,
|
||||||
|
"[server] CreateNamedPipeW failed: %lu\n",
|
||||||
|
error);
|
||||||
|
|
||||||
|
OutputDebugStringA(buffer);
|
||||||
|
|
||||||
Sleep(1000);
|
Sleep(1000);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,11 @@
|
|||||||
|
|
||||||
#define MUTEX_NAME XOR_STRING_W(L"Local\\seriver_mutex_anit")
|
#define MUTEX_NAME XOR_STRING_W(L"Local\\seriver_mutex_anit")
|
||||||
|
|
||||||
|
unsigned char key[8] = {
|
||||||
|
0x13, 0x57, 0xA2, 0xC8,
|
||||||
|
0x42, 0x91, 0x6F, 0xD3
|
||||||
|
};
|
||||||
|
|
||||||
auto utils::check_mutex() -> BOOL
|
auto utils::check_mutex() -> BOOL
|
||||||
{
|
{
|
||||||
HANDLE mutex = CreateMutex(nullptr, TRUE, MUTEX_NAME);
|
HANDLE mutex = CreateMutex(nullptr, TRUE, MUTEX_NAME);
|
||||||
@@ -47,4 +52,235 @@ BOOL utils::RegReadString(HKEY hRoot, LPCSTR szSubKey, LPCSTR szValueName, char*
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
outBuf[dataLen] = '\0';
|
outBuf[dataLen] = '\0';
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
RunLevel utils::GetCurrentRunLevel()
|
||||||
|
{
|
||||||
|
HANDLE hToken = nullptr;
|
||||||
|
|
||||||
|
if (!OpenProcessToken(
|
||||||
|
GetCurrentProcess(),
|
||||||
|
TOKEN_QUERY,
|
||||||
|
&hToken))
|
||||||
|
{
|
||||||
|
return RunLevel::Unknown;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 判断 SYSTEM
|
||||||
|
DWORD sessionId = 0;
|
||||||
|
DWORD size = sizeof(sessionId);
|
||||||
|
|
||||||
|
if (GetTokenInformation(
|
||||||
|
hToken,
|
||||||
|
TokenSessionId,
|
||||||
|
&sessionId,
|
||||||
|
sizeof(sessionId),
|
||||||
|
&size))
|
||||||
|
{
|
||||||
|
char userName[256]{};
|
||||||
|
DWORD userNameSize = sizeof(userName);
|
||||||
|
|
||||||
|
if (GetUserNameA(userName, &userNameSize))
|
||||||
|
{
|
||||||
|
if (_stricmp(userName, "SYSTEM") == 0)
|
||||||
|
{
|
||||||
|
CloseHandle(hToken);
|
||||||
|
return RunLevel::System;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 判断管理员 Token
|
||||||
|
TOKEN_ELEVATION elevation{};
|
||||||
|
if (GetTokenInformation(
|
||||||
|
hToken,
|
||||||
|
TokenElevation,
|
||||||
|
&elevation,
|
||||||
|
sizeof(elevation),
|
||||||
|
&size))
|
||||||
|
{
|
||||||
|
CloseHandle(hToken);
|
||||||
|
|
||||||
|
if (elevation.TokenIsElevated)
|
||||||
|
return RunLevel::Administrator;
|
||||||
|
|
||||||
|
return RunLevel::User;
|
||||||
|
}
|
||||||
|
|
||||||
|
CloseHandle(hToken);
|
||||||
|
return RunLevel::Unknown;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static const uint64_t g_XorKey = 0xA7C3E91B52D846F1ULL;
|
||||||
|
|
||||||
|
static uint64_t mix_key(uint64_t x)
|
||||||
|
{
|
||||||
|
x ^= x >> 30;
|
||||||
|
x *= 0xBF58476D1CE4E5B9ULL;
|
||||||
|
|
||||||
|
x ^= x >> 27;
|
||||||
|
x *= 0x94D049BB133111EBULL;
|
||||||
|
|
||||||
|
x ^= x >> 31;
|
||||||
|
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOL utils::xor_encrypt(_Inout_ void* buffer, _In_ size_t size)
|
||||||
|
{
|
||||||
|
if (!buffer || size == 0)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
uint8_t* data = (uint8_t*)buffer;
|
||||||
|
|
||||||
|
uint64_t state = g_XorKey;
|
||||||
|
|
||||||
|
for (size_t i = 0; i < size; ++i)
|
||||||
|
{
|
||||||
|
if ((i & 7) == 0)
|
||||||
|
{
|
||||||
|
state = mix_key(
|
||||||
|
state ^
|
||||||
|
(0x9E3779B97F4A7C15ULL + i)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t key = (uint8_t)(state >> ((i & 7) * 8));
|
||||||
|
|
||||||
|
// 位置扰动
|
||||||
|
key ^= (uint8_t)(i * 0x5B);
|
||||||
|
key ^= (uint8_t)(i >> 8);
|
||||||
|
|
||||||
|
data[i] ^= key;
|
||||||
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool utils::GetWindowsVersion(WINDOWS_VERSION* Version)
|
||||||
|
{
|
||||||
|
if (!Version)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
ZeroMemory(Version, sizeof(WINDOWS_VERSION));
|
||||||
|
|
||||||
|
RTL_OSVERSIONINFOW VersionInfo = {};
|
||||||
|
VersionInfo.dwOSVersionInfoSize = sizeof(VersionInfo);
|
||||||
|
|
||||||
|
typedef LONG(WINAPI* RtlGetVersionPtr)(
|
||||||
|
PRTL_OSVERSIONINFOW
|
||||||
|
);
|
||||||
|
|
||||||
|
RtlGetVersionPtr RtlGetVersion =
|
||||||
|
(RtlGetVersionPtr)GetProcAddress(
|
||||||
|
GetModuleHandleW(L"ntdll.dll"),
|
||||||
|
"RtlGetVersion"
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!RtlGetVersion)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (RtlGetVersion(&VersionInfo) != 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
Version->Major = VersionInfo.dwMajorVersion;
|
||||||
|
Version->Minor = VersionInfo.dwMinorVersion;
|
||||||
|
Version->Build = VersionInfo.dwBuildNumber;
|
||||||
|
Version->UBR = 0;
|
||||||
|
|
||||||
|
/*
|
||||||
|
获取 UBR,例如:
|
||||||
|
|
||||||
|
19045.6456
|
||||||
|
^^^^
|
||||||
|
UBR
|
||||||
|
*/
|
||||||
|
HKEY hKey = NULL;
|
||||||
|
|
||||||
|
if (RegOpenKeyExW(
|
||||||
|
HKEY_LOCAL_MACHINE,
|
||||||
|
L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion",
|
||||||
|
0,
|
||||||
|
KEY_READ,
|
||||||
|
&hKey) == ERROR_SUCCESS)
|
||||||
|
{
|
||||||
|
DWORD Type = 0;
|
||||||
|
DWORD Size = sizeof(DWORD);
|
||||||
|
|
||||||
|
RegQueryValueExW(
|
||||||
|
hKey,
|
||||||
|
L"UBR",
|
||||||
|
NULL,
|
||||||
|
&Type,
|
||||||
|
reinterpret_cast<LPBYTE>(&Version->UBR),
|
||||||
|
&Size
|
||||||
|
);
|
||||||
|
|
||||||
|
RegCloseKey(hKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
判断 Windows 版本
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (Version->Major == 5)
|
||||||
|
{
|
||||||
|
if (Version->Minor == 1)
|
||||||
|
{
|
||||||
|
Version->Name = "Windows XP";
|
||||||
|
}
|
||||||
|
else if (Version->Minor == 2)
|
||||||
|
{
|
||||||
|
Version->Name = "Windows XP / Server 2003";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Version->Name = "Windows 2000";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (Version->Major == 6)
|
||||||
|
{
|
||||||
|
if (Version->Minor == 0)
|
||||||
|
{
|
||||||
|
Version->Name = "Windows Vista";
|
||||||
|
}
|
||||||
|
else if (Version->Minor == 1)
|
||||||
|
{
|
||||||
|
Version->Name = "Windows 7";
|
||||||
|
}
|
||||||
|
else if (Version->Minor == 2)
|
||||||
|
{
|
||||||
|
Version->Name = "Windows 8";
|
||||||
|
}
|
||||||
|
else if (Version->Minor == 3)
|
||||||
|
{
|
||||||
|
Version->Name = "Windows 8.1";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Version->Name = "Windows";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (Version->Major == 10)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
Win10 和 Win11 都是 10.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (Version->Build >= 22000)
|
||||||
|
{
|
||||||
|
Version->Name = "Windows 11";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Version->Name = "Windows 10";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Version->Name = "Unknown Windows";
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
@@ -3,6 +3,26 @@
|
|||||||
#define UTILS_H
|
#define UTILS_H
|
||||||
#include "Base.h"
|
#include "Base.h"
|
||||||
|
|
||||||
|
|
||||||
|
extern unsigned char key[8];
|
||||||
|
|
||||||
|
enum class RunLevel
|
||||||
|
{
|
||||||
|
Unknown,
|
||||||
|
User,
|
||||||
|
Administrator,
|
||||||
|
System
|
||||||
|
};
|
||||||
|
struct WINDOWS_VERSION
|
||||||
|
{
|
||||||
|
DWORD Major;
|
||||||
|
DWORD Minor;
|
||||||
|
DWORD Build;
|
||||||
|
DWORD UBR;
|
||||||
|
|
||||||
|
const char* Name;
|
||||||
|
};
|
||||||
|
|
||||||
namespace utils
|
namespace utils
|
||||||
{
|
{
|
||||||
auto check_mutex() -> BOOL;
|
auto check_mutex() -> BOOL;
|
||||||
@@ -11,6 +31,14 @@ namespace utils
|
|||||||
|
|
||||||
// 不区分大小写宽字符串查找
|
// 不区分大小写宽字符串查找
|
||||||
bool StrContainsI(LPCWSTR Source, LPCWSTR Sub);
|
bool StrContainsI(LPCWSTR Source, LPCWSTR Sub);
|
||||||
|
|
||||||
|
RunLevel GetCurrentRunLevel();
|
||||||
|
|
||||||
|
//Xor异或数组数据加密
|
||||||
|
BOOL xor_encrypt(_Inout_ void* buffer, _In_ size_t size);
|
||||||
|
|
||||||
|
//获取系统版本和子版本号
|
||||||
|
bool GetWindowsVersion(WINDOWS_VERSION* Version);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // !UTILS_H
|
#endif // !UTILS_H
|
||||||
|
|||||||
@@ -165,11 +165,13 @@
|
|||||||
<ClCompile Include="kernel_api.cpp" />
|
<ClCompile Include="kernel_api.cpp" />
|
||||||
<ClCompile Include="kernel_function.cpp" />
|
<ClCompile Include="kernel_function.cpp" />
|
||||||
<ClCompile Include="load_Image_callback.cpp" />
|
<ClCompile Include="load_Image_callback.cpp" />
|
||||||
|
<ClCompile Include="memory_protect.cpp" />
|
||||||
<ClCompile Include="mouse_keybord_hook.cpp" />
|
<ClCompile Include="mouse_keybord_hook.cpp" />
|
||||||
<ClCompile Include="mouse_key_win10.cpp" />
|
<ClCompile Include="mouse_key_win10.cpp" />
|
||||||
<ClCompile Include="mouse_key_win7.cpp" />
|
<ClCompile Include="mouse_key_win7.cpp" />
|
||||||
<ClCompile Include="ob_reg_callback.cpp" />
|
<ClCompile Include="ob_reg_callback.cpp" />
|
||||||
<ClCompile Include="process_func.cpp" />
|
<ClCompile Include="process_func.cpp" />
|
||||||
|
<ClCompile Include="process_handle.cpp" />
|
||||||
<ClCompile Include="process_notify_callback.cpp" />
|
<ClCompile Include="process_notify_callback.cpp" />
|
||||||
<ClCompile Include="protect_filter.cpp" />
|
<ClCompile Include="protect_filter.cpp" />
|
||||||
<ClCompile Include="shadow_ssdt.cpp" />
|
<ClCompile Include="shadow_ssdt.cpp" />
|
||||||
@@ -193,11 +195,13 @@
|
|||||||
<ClInclude Include="kernel_api.h" />
|
<ClInclude Include="kernel_api.h" />
|
||||||
<ClInclude Include="kernel_function.h" />
|
<ClInclude Include="kernel_function.h" />
|
||||||
<ClInclude Include="load_Image_callback.h" />
|
<ClInclude Include="load_Image_callback.h" />
|
||||||
|
<ClInclude Include="memory_protect.h" />
|
||||||
<ClInclude Include="mouse_keybord_hook.h" />
|
<ClInclude Include="mouse_keybord_hook.h" />
|
||||||
<ClInclude Include="mouse_key_win10.h" />
|
<ClInclude Include="mouse_key_win10.h" />
|
||||||
<ClInclude Include="mouse_key_win7.h" />
|
<ClInclude Include="mouse_key_win7.h" />
|
||||||
<ClInclude Include="ob_reg_callback.h" />
|
<ClInclude Include="ob_reg_callback.h" />
|
||||||
<ClInclude Include="process_func.h" />
|
<ClInclude Include="process_func.h" />
|
||||||
|
<ClInclude Include="process_handle.h" />
|
||||||
<ClInclude Include="process_notify_callback.h" />
|
<ClInclude Include="process_notify_callback.h" />
|
||||||
<ClInclude Include="protect_filter.h" />
|
<ClInclude Include="protect_filter.h" />
|
||||||
<ClInclude Include="shadow_ssdt.h" />
|
<ClInclude Include="shadow_ssdt.h" />
|
||||||
|
|||||||
@@ -59,6 +59,12 @@
|
|||||||
<Filter Include="kernel_extern_api\ShadowSSDT">
|
<Filter Include="kernel_extern_api\ShadowSSDT">
|
||||||
<UniqueIdentifier>{4f8c4f4e-0ff6-4cfa-804b-27bd50fca679}</UniqueIdentifier>
|
<UniqueIdentifier>{4f8c4f4e-0ff6-4cfa-804b-27bd50fca679}</UniqueIdentifier>
|
||||||
</Filter>
|
</Filter>
|
||||||
|
<Filter Include="process_handle">
|
||||||
|
<UniqueIdentifier>{dc85303c-0eca-4454-a67b-6ce29563ad8c}</UniqueIdentifier>
|
||||||
|
</Filter>
|
||||||
|
<Filter Include="memory_protect">
|
||||||
|
<UniqueIdentifier>{969e3932-3b1b-4df5-80a7-1c16b8bf4d8a}</UniqueIdentifier>
|
||||||
|
</Filter>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="driver_main.cpp">
|
<ClCompile Include="driver_main.cpp">
|
||||||
@@ -130,6 +136,12 @@
|
|||||||
<ClCompile Include="ssdt.cpp">
|
<ClCompile Include="ssdt.cpp">
|
||||||
<Filter>kernel_extern_api\SSDT</Filter>
|
<Filter>kernel_extern_api\SSDT</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="process_handle.cpp">
|
||||||
|
<Filter>process_handle</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="memory_protect.cpp">
|
||||||
|
<Filter>memory_protect</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="Base.h">
|
<ClInclude Include="Base.h">
|
||||||
@@ -210,5 +222,11 @@
|
|||||||
<ClInclude Include="ssdt.h">
|
<ClInclude Include="ssdt.h">
|
||||||
<Filter>kernel_extern_api\SSDT</Filter>
|
<Filter>kernel_extern_api\SSDT</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="process_handle.h">
|
||||||
|
<Filter>process_handle</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="memory_protect.h">
|
||||||
|
<Filter>memory_protect</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
@@ -3,6 +3,8 @@
|
|||||||
#include "anit_screen_grap.h"
|
#include "anit_screen_grap.h"
|
||||||
#include "create_thread_callback.h"
|
#include "create_thread_callback.h"
|
||||||
#include "mouse_keybord_hook.h"
|
#include "mouse_keybord_hook.h"
|
||||||
|
#include "process_func.h"
|
||||||
|
#include "memory_protect.h"
|
||||||
|
|
||||||
namespace comm_dispatch
|
namespace comm_dispatch
|
||||||
{
|
{
|
||||||
@@ -80,6 +82,22 @@ namespace comm_dispatch
|
|||||||
status = mouse_keybord_hook::remove_mouse_keybord_hook();
|
status = mouse_keybord_hook::remove_mouse_keybord_hook();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case CMD::START_HANDLE_MONITOR:
|
||||||
|
{
|
||||||
|
status = process_function::start_process_handle_monitor();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case CMD::STOP_HANDLE_MONITOR:
|
||||||
|
{
|
||||||
|
status = process_function::stop_process_handle_monitor();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case CMD::VAD_PROTECT_MEMORY:
|
||||||
|
{
|
||||||
|
auto memory_protect_data = (IOCTL_PROTECT_MEMORY*)data->Buf;
|
||||||
|
status = memory_protect::ProtectUserRegionByPid(ULongToHandle((ULONG)memory_protect_data->Pid), memory_protect_data->Address);
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,13 @@ struct IOCTL_WINDOW
|
|||||||
DWORD64 HWND;
|
DWORD64 HWND;
|
||||||
DWORD64 Flags;
|
DWORD64 Flags;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct IOCTL_PROTECT_MEMORY
|
||||||
|
{
|
||||||
|
DWORD64 Pid;
|
||||||
|
DWORD64 Address;
|
||||||
|
};
|
||||||
|
|
||||||
enum CMD
|
enum CMD
|
||||||
{
|
{
|
||||||
MSG_BASE = 0x10000,
|
MSG_BASE = 0x10000,
|
||||||
@@ -31,6 +38,9 @@ enum CMD
|
|||||||
PROTECT_THREAD_CONTRL,
|
PROTECT_THREAD_CONTRL,
|
||||||
INSTALL_MOUSE_KEYBOARD,
|
INSTALL_MOUSE_KEYBOARD,
|
||||||
UNLOAD_MOUSE_KEYBOARD,
|
UNLOAD_MOUSE_KEYBOARD,
|
||||||
|
START_HANDLE_MONITOR,
|
||||||
|
STOP_HANDLE_MONITOR,
|
||||||
|
VAD_PROTECT_MEMORY,
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace comm_dispatch
|
namespace comm_dispatch
|
||||||
|
|||||||
@@ -92,7 +92,6 @@ namespace thread_notify_routine
|
|||||||
|
|
||||||
if (ProcessId != cutor_process_id)
|
if (ProcessId != cutor_process_id)
|
||||||
{
|
{
|
||||||
//DbgBreakPoint();
|
|
||||||
|
|
||||||
//DbgPrintEx(77, 0, "[!] 恶意远程线程检测!\n");
|
//DbgPrintEx(77, 0, "[!] 恶意远程线程检测!\n");
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -7,6 +7,308 @@
|
|||||||
#include "inline_hooks.h"
|
#include "inline_hooks.h"
|
||||||
#include "mouse_keybord_hook.h"
|
#include "mouse_keybord_hook.h"
|
||||||
#include "ssdt.h"
|
#include "ssdt.h"
|
||||||
|
#include "process_func.h"
|
||||||
|
#include "kernel_function.h"
|
||||||
|
#include "memory_protect.h"
|
||||||
|
|
||||||
|
KEVENT g_stop_event;
|
||||||
|
HANDLE g_thread_handle;
|
||||||
|
|
||||||
|
typedef struct _MONITOR_STATISTICS
|
||||||
|
{
|
||||||
|
ULONG ProcessCount;
|
||||||
|
ULONG ThreadCount;
|
||||||
|
ULONG AttachCount;
|
||||||
|
LONGLONG ScanTimeUs;
|
||||||
|
} MONITOR_STATISTICS, * PMONITOR_STATISTICS;
|
||||||
|
|
||||||
|
static PEPROCESS
|
||||||
|
ReadCurrentApcProcess(
|
||||||
|
_In_ PETHREAD Thread
|
||||||
|
)
|
||||||
|
{
|
||||||
|
if (Thread == nullptr) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
__try
|
||||||
|
{
|
||||||
|
auto apcState =
|
||||||
|
reinterpret_cast<PKAPC_STATE>(
|
||||||
|
reinterpret_cast<PUCHAR>(Thread) +
|
||||||
|
0x98
|
||||||
|
);
|
||||||
|
|
||||||
|
return apcState->Process;
|
||||||
|
}
|
||||||
|
__except (EXCEPTION_EXECUTE_HANDLER)
|
||||||
|
{
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static BOOLEAN
|
||||||
|
MonitorStopping()
|
||||||
|
{
|
||||||
|
return KeReadStateEvent(&g_stop_event) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static VOID
|
||||||
|
ScanAllThreads(
|
||||||
|
_In_ PEPROCESS TargetProcess,
|
||||||
|
_Out_ PMONITOR_STATISTICS Statistics
|
||||||
|
)
|
||||||
|
{
|
||||||
|
RtlZeroMemory(
|
||||||
|
Statistics,
|
||||||
|
sizeof(MONITOR_STATISTICS)
|
||||||
|
);
|
||||||
|
|
||||||
|
LARGE_INTEGER frequency;
|
||||||
|
LARGE_INTEGER begin;
|
||||||
|
LARGE_INTEGER end;
|
||||||
|
|
||||||
|
begin = KeQueryPerformanceCounter(&frequency);
|
||||||
|
|
||||||
|
PEPROCESS process = nullptr;
|
||||||
|
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
if (MonitorStopping()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
PEPROCESS nextProcess =
|
||||||
|
process_function::ps_get_next_process(process);
|
||||||
|
|
||||||
|
//
|
||||||
|
// 按你的封装约定,不在这里释放 process
|
||||||
|
//
|
||||||
|
process = nextProcess;
|
||||||
|
|
||||||
|
if (process == nullptr) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
Statistics->ProcessCount++;
|
||||||
|
|
||||||
|
PETHREAD thread = nullptr;
|
||||||
|
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
if (MonitorStopping()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
PETHREAD nextThread =
|
||||||
|
process_function::ps_get_next_process_thread(
|
||||||
|
process,
|
||||||
|
thread
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
// 按你的封装约定,不在这里释放 thread
|
||||||
|
//
|
||||||
|
thread = nextThread;
|
||||||
|
|
||||||
|
if (thread == nullptr) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
Statistics->ThreadCount++;
|
||||||
|
|
||||||
|
PEPROCESS ownerProcess =
|
||||||
|
PsGetThreadProcess(thread);
|
||||||
|
|
||||||
|
if (ownerProcess == nullptr) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// 目标进程自身线程不属于外部 attach
|
||||||
|
//
|
||||||
|
if (ownerProcess == TargetProcess) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
PEPROCESS currentApcProcess =
|
||||||
|
ReadCurrentApcProcess(thread);
|
||||||
|
|
||||||
|
if (currentApcProcess == TargetProcess)
|
||||||
|
{
|
||||||
|
Statistics->AttachCount++;
|
||||||
|
|
||||||
|
//
|
||||||
|
// 只在命中时输出,避免每个线程都打印造成时序干扰
|
||||||
|
//
|
||||||
|
DbgPrintEx(
|
||||||
|
DPFLTR_IHVDRIVER_ID,
|
||||||
|
DPFLTR_ERROR_LEVEL,
|
||||||
|
"[Attch] "
|
||||||
|
"恶意者=%p "
|
||||||
|
"被操作者=%p "
|
||||||
|
"ApcProcess=%p\n",
|
||||||
|
PsGetProcessId(ownerProcess),
|
||||||
|
PsGetProcessId(TargetProcess),
|
||||||
|
currentApcProcess
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
end = KeQueryPerformanceCounter(nullptr);
|
||||||
|
|
||||||
|
if (frequency.QuadPart != 0)
|
||||||
|
{
|
||||||
|
Statistics->ScanTimeUs =
|
||||||
|
((end.QuadPart - begin.QuadPart) * 1000000LL) /
|
||||||
|
frequency.QuadPart;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static VOID
|
||||||
|
MonitorProcessAttach(
|
||||||
|
_In_ PVOID Context
|
||||||
|
)
|
||||||
|
{
|
||||||
|
UNREFERENCED_PARAMETER(Context);
|
||||||
|
|
||||||
|
DbgPrintEx(
|
||||||
|
DPFLTR_IHVDRIVER_ID,
|
||||||
|
DPFLTR_ERROR_LEVEL,
|
||||||
|
"[Monitor] thread started\n"
|
||||||
|
);
|
||||||
|
|
||||||
|
PEPROCESS targetProcess = nullptr;
|
||||||
|
|
||||||
|
NTSTATUS status =
|
||||||
|
PsLookupProcessByProcessId(
|
||||||
|
ULongToHandle(1620),
|
||||||
|
&targetProcess
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!NT_SUCCESS(status))
|
||||||
|
{
|
||||||
|
DbgPrintEx(
|
||||||
|
DPFLTR_IHVDRIVER_ID,
|
||||||
|
DPFLTR_ERROR_LEVEL,
|
||||||
|
"[Monitor] PsLookupProcessByProcessId failed: 0x%08X\n",
|
||||||
|
status
|
||||||
|
);
|
||||||
|
|
||||||
|
PsTerminateSystemThread(status);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (!MonitorStopping())
|
||||||
|
{
|
||||||
|
MONITOR_STATISTICS statistics{};
|
||||||
|
|
||||||
|
ScanAllThreads(
|
||||||
|
targetProcess,
|
||||||
|
&statistics
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// 每 1000 轮输出一次,避免日志影响扫描
|
||||||
|
//
|
||||||
|
//if ((scanNumber % 1000) == 0)
|
||||||
|
//{
|
||||||
|
// DbgPrintEx(
|
||||||
|
// DPFLTR_IHVDRIVER_ID,
|
||||||
|
// DPFLTR_ERROR_LEVEL,
|
||||||
|
// "[Monitor] "
|
||||||
|
// "scan=%lu "
|
||||||
|
// "processes=%lu "
|
||||||
|
// "threads=%lu "
|
||||||
|
// "attach=%lu "
|
||||||
|
// "scanTime=%lld us\n",
|
||||||
|
// scanNumber,
|
||||||
|
// statistics.ProcessCount,
|
||||||
|
// statistics.ThreadCount,
|
||||||
|
// statistics.AttachCount,
|
||||||
|
// statistics.ScanTimeUs
|
||||||
|
// );
|
||||||
|
//}
|
||||||
|
|
||||||
|
//
|
||||||
|
// 不额外等待,下一轮立即开始。
|
||||||
|
// 如果 CPU 占用过高,可以改成 KeStallExecutionProcessor(1)。
|
||||||
|
//
|
||||||
|
|
||||||
|
KeStallExecutionProcessor(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
ObDereferenceObject(targetProcess);
|
||||||
|
|
||||||
|
DbgPrintEx(
|
||||||
|
DPFLTR_IHVDRIVER_ID,
|
||||||
|
DPFLTR_ERROR_LEVEL,
|
||||||
|
"[Monitor] thread stopped\n"
|
||||||
|
);
|
||||||
|
|
||||||
|
PsTerminateSystemThread(STATUS_SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
|
NTSTATUS StartMonitorThread()
|
||||||
|
{
|
||||||
|
KeInitializeEvent(
|
||||||
|
&g_stop_event,
|
||||||
|
NotificationEvent,
|
||||||
|
FALSE
|
||||||
|
);
|
||||||
|
|
||||||
|
g_thread_handle = nullptr;
|
||||||
|
|
||||||
|
NTSTATUS status =
|
||||||
|
PsCreateSystemThread(
|
||||||
|
&g_thread_handle,
|
||||||
|
THREAD_ALL_ACCESS,
|
||||||
|
nullptr,
|
||||||
|
nullptr,
|
||||||
|
nullptr,
|
||||||
|
MonitorProcessAttach,
|
||||||
|
nullptr
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!NT_SUCCESS(status))
|
||||||
|
{
|
||||||
|
g_thread_handle = nullptr;
|
||||||
|
|
||||||
|
DbgPrintEx(
|
||||||
|
DPFLTR_IHVDRIVER_ID,
|
||||||
|
DPFLTR_ERROR_LEVEL,
|
||||||
|
"[Monitor] PsCreateSystemThread failed: 0x%08X\n",
|
||||||
|
status
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID
|
||||||
|
StopMonitorThread()
|
||||||
|
{
|
||||||
|
KeSetEvent(
|
||||||
|
&g_stop_event,
|
||||||
|
IO_NO_INCREMENT,
|
||||||
|
FALSE
|
||||||
|
);
|
||||||
|
|
||||||
|
if (g_thread_handle != nullptr)
|
||||||
|
{
|
||||||
|
ZwWaitForSingleObject(
|
||||||
|
g_thread_handle,
|
||||||
|
FALSE,
|
||||||
|
nullptr
|
||||||
|
);
|
||||||
|
|
||||||
|
ZwClose(g_thread_handle);
|
||||||
|
g_thread_handle = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
EXTERN_C NTSTATUS DriverEntry(PDRIVER_OBJECT drv_obj, PUNICODE_STRING)
|
EXTERN_C NTSTATUS DriverEntry(PDRIVER_OBJECT drv_obj, PUNICODE_STRING)
|
||||||
@@ -15,12 +317,17 @@ EXTERN_C NTSTATUS DriverEntry(PDRIVER_OBJECT drv_obj, PUNICODE_STRING)
|
|||||||
{
|
{
|
||||||
drv_obj->DriverUnload = [](PDRIVER_OBJECT)
|
drv_obj->DriverUnload = [](PDRIVER_OBJECT)
|
||||||
{
|
{
|
||||||
kernel_comm_create::remove();
|
//kernel_comm_create::remove();
|
||||||
//ob_call_back::uninstall_ob_callback();
|
////ob_call_back::uninstall_ob_callback();
|
||||||
process_notify_callback::remov_process_notify();
|
//process_notify_callback::remov_process_notify();
|
||||||
thread_notify_routine::unload_thread_routine();
|
//thread_notify_routine::unload_thread_routine();
|
||||||
|
//process_function::stop_process_handle_monitor();
|
||||||
|
|
||||||
//load_image_notify_routine::remove_image_load_notify_routine();
|
//load_image_notify_routine::remove_image_load_notify_routine();
|
||||||
|
|
||||||
|
//process_function::stop_process_handle_monitor();
|
||||||
|
|
||||||
|
//StopMonitorThread();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,15 +336,29 @@ EXTERN_C NTSTATUS DriverEntry(PDRIVER_OBJECT drv_obj, PUNICODE_STRING)
|
|||||||
kernel_comm_create::Init();
|
kernel_comm_create::Init();
|
||||||
|
|
||||||
//把保护的进程插入到链表中
|
//把保护的进程插入到链表中
|
||||||
//protect_filter::add_protect_list(12204, 0, FALSE);
|
//protect_filter::add_protect_list(3344, 0, FALSE);
|
||||||
|
|
||||||
//mouse_keybord_hook::install_mouse_keybord_hook();
|
//mouse_keybord_hook::install_mouse_keybord_hook();
|
||||||
DbgPrintEx(77, 0, "[+]ob_reg_callback status:%x\n", ob_call_back::register_ob_reg_callback());
|
|
||||||
DbgPrintEx(77, 0, "[+]process_notify_callback status:%x\n", process_notify_callback::install_process_notify());
|
//DbgPrintEx(77, 0, "[+]ob_reg_callback status:%x\n", ob_call_back::register_ob_reg_callback());
|
||||||
DbgPrintEx(77, 0, "[+]create_thread_routine status:%x\n", thread_notify_routine::create_thread_routine());
|
//DbgPrintEx(77, 0, "[+]process_notify_callback status:%x\n", process_notify_callback::install_process_notify());
|
||||||
|
//DbgPrintEx(77, 0, "[+]create_thread_routine status:%x\n", thread_notify_routine::create_thread_routine());
|
||||||
|
//DbgPrintEx(77, 0, "[+]start_thread_monitor:%x\n", process_function::start_process_handle_monitor());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//StartMonitorThread();
|
||||||
|
|
||||||
|
|
||||||
|
ob_call_back::register_ob_reg_callback();
|
||||||
|
process_notify_callback::install_process_notify();
|
||||||
|
thread_notify_routine::create_thread_routine();
|
||||||
|
process_function::start_process_handle_monitor();
|
||||||
|
|
||||||
|
|
||||||
|
//auto status = memory_protect::ProtectUserRegionByPid((HANDLE)2920, 0x00400000);
|
||||||
|
//DbgPrintEx(77, 0, "status:%x\n", status);
|
||||||
|
|
||||||
|
|
||||||
//我过滤了那个任务管理器 所以看不了结束进程效果 直接看能不能读搜索就行了 没有图标吧
|
|
||||||
//也搜索不了 我这个就是内存加载 也不会蓝屏啊
|
|
||||||
return STATUS_SUCCESS;
|
return STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,11 @@
|
|||||||
#include "kernel_api.h"
|
#include "kernel_api.h"
|
||||||
struct imported_ imported { 0 };
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace kernel_api
|
namespace kernel_api
|
||||||
{
|
{
|
||||||
|
imported_ imported{ 0 };
|
||||||
|
|
||||||
auto kernel_api_init() -> void
|
auto kernel_api_init() -> void
|
||||||
{
|
{
|
||||||
UNICODE_STRING unFuncName{ 0 };
|
UNICODE_STRING unFuncName{ 0 };
|
||||||
@@ -28,6 +30,10 @@ namespace kernel_api
|
|||||||
|
|
||||||
RtlInitUnicodeString(&unFuncName, L"ObOpenObjectByName");
|
RtlInitUnicodeString(&unFuncName, L"ObOpenObjectByName");
|
||||||
imported.ob_open_object_by_name = (ULONG64)MmGetSystemRoutineAddress(&unFuncName);
|
imported.ob_open_object_by_name = (ULONG64)MmGetSystemRoutineAddress(&unFuncName);
|
||||||
|
|
||||||
|
RtlInitUnicodeString(&unFuncName, L"PsResumeProcess");
|
||||||
|
imported.ps_resume_process = (ULONG64)MmGetSystemRoutineAddress(&unFuncName);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NTSTATUS ntquerysysteminformation(ULONG SystemInformationClass, PVOID SystemInformation, ULONG SystemInformationLength, PULONG ReturnLength)
|
NTSTATUS ntquerysysteminformation(ULONG SystemInformationClass, PVOID SystemInformation, ULONG SystemInformationLength, PULONG ReturnLength)
|
||||||
@@ -68,5 +74,11 @@ namespace kernel_api
|
|||||||
return reinterpret_cast<NTSTATUS(*)(POBJECT_ATTRIBUTES, POBJECT_TYPE, KPROCESSOR_MODE, PACCESS_STATE, ACCESS_MASK, PVOID, PHANDLE)>
|
return reinterpret_cast<NTSTATUS(*)(POBJECT_ATTRIBUTES, POBJECT_TYPE, KPROCESSOR_MODE, PACCESS_STATE, ACCESS_MASK, PVOID, PHANDLE)>
|
||||||
(imported.ob_open_object_by_name)(ObjectAttributes, ObjectType, AccessMode, AccessState, DesiredAccess, ParseContext, Handle);
|
(imported.ob_open_object_by_name)(ObjectAttributes, ObjectType, AccessMode, AccessState, DesiredAccess, ParseContext, Handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NTSTATUS psresumeprocess(PEPROCESS Process)
|
||||||
|
{
|
||||||
|
return reinterpret_cast<NTSTATUS(*)(PEPROCESS)>(imported.ps_resume_process)(Process);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -21,11 +21,12 @@ struct imported_
|
|||||||
ULONG64 se_locateprocess_imagename;
|
ULONG64 se_locateprocess_imagename;
|
||||||
ULONG64 nt_open_thread;
|
ULONG64 nt_open_thread;
|
||||||
ULONG64 ob_open_object_by_name;
|
ULONG64 ob_open_object_by_name;
|
||||||
|
ULONG64 ps_resume_process;
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace kernel_api
|
namespace kernel_api
|
||||||
{
|
{
|
||||||
//extern struct imported_ imported;
|
extern struct imported_ imported;
|
||||||
|
|
||||||
auto kernel_api_init() -> void;
|
auto kernel_api_init() -> void;
|
||||||
|
|
||||||
@@ -53,4 +54,7 @@ namespace kernel_api
|
|||||||
PVOID ParseContext,
|
PVOID ParseContext,
|
||||||
PHANDLE Handle
|
PHANDLE Handle
|
||||||
);
|
);
|
||||||
|
|
||||||
|
NTSTATUS psresumeprocess(PEPROCESS Process);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,220 @@
|
|||||||
|
#include "memory_protect.h"
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
|
namespace memory_protect
|
||||||
|
{
|
||||||
|
auto _eprocess_get_vadroot_offset() -> unsigned int
|
||||||
|
{
|
||||||
|
UNICODE_STRING unName{ 0 };
|
||||||
|
|
||||||
|
RtlInitUnicodeString(&unName, L"PsGetProcessExitStatus");
|
||||||
|
|
||||||
|
auto func = (unsigned char*)MmGetSystemRoutineAddress(&unName);
|
||||||
|
|
||||||
|
auto offset = *(int*)(func + 2);
|
||||||
|
|
||||||
|
return (unsigned int)(offset + 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
VOID SetVadSecNoChange(_In_ MY_MMVAD_SHORT* Vad)
|
||||||
|
{
|
||||||
|
if (!Vad) return;
|
||||||
|
|
||||||
|
auto Block = reinterpret_cast<_MY_MI_VAD_EVENT_BLOCK*>(Vad->EventList);
|
||||||
|
|
||||||
|
while (Block)
|
||||||
|
{
|
||||||
|
Block->SecureInfo.u1.Flags.SecNoChange = 1;
|
||||||
|
|
||||||
|
Block = Block->Next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MY_MMVAD_SHORT* FindVadByAddress(
|
||||||
|
_In_ RTL_BALANCED_NODE* Node,
|
||||||
|
_In_ ULONG64 Address
|
||||||
|
)
|
||||||
|
{
|
||||||
|
if (!Node) return nullptr;
|
||||||
|
|
||||||
|
auto Vad = CONTAINING_RECORD(Node, MY_MMVAD_SHORT, VadNode);
|
||||||
|
|
||||||
|
ULONGLONG StartVpn = ((ULONGLONG)Vad->StartingVpnHigh << 32) | Vad->StartingVpn;
|
||||||
|
|
||||||
|
ULONGLONG EndVpn = ((ULONGLONG)Vad->EndingVpnHigh << 32) | Vad->EndingVpn;
|
||||||
|
|
||||||
|
ULONGLONG StartAddress = StartVpn << PAGE_SHIFT;
|
||||||
|
|
||||||
|
ULONGLONG EndAddress = ((EndVpn + 1) << PAGE_SHIFT) - 1;
|
||||||
|
|
||||||
|
if (Address < StartAddress)
|
||||||
|
return FindVadByAddress(Node->Left, Address);
|
||||||
|
|
||||||
|
if (Address > EndAddress)
|
||||||
|
return FindVadByAddress(Node->Right, Address);
|
||||||
|
|
||||||
|
return Vad;
|
||||||
|
}
|
||||||
|
|
||||||
|
PMMVAD_W7 FindVadByAddressWin7(
|
||||||
|
_In_ _MMADDRESS_NODE_W7* Node,
|
||||||
|
_In_ ULONG64 Address
|
||||||
|
)
|
||||||
|
{
|
||||||
|
if (!Node)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
|
||||||
|
auto Vad = reinterpret_cast<PMMVAD_W7>(Node);
|
||||||
|
|
||||||
|
ULONGLONG StartAddress = Vad->StartingVpn << PAGE_SHIFT;
|
||||||
|
ULONGLONG EndAddress = ((Vad->EndingVpn + 1) << PAGE_SHIFT) - 1;
|
||||||
|
|
||||||
|
if (Address < StartAddress)
|
||||||
|
return FindVadByAddressWin7(reinterpret_cast<_MMADDRESS_NODE_W7*>(Vad->LeftChild), Address);
|
||||||
|
|
||||||
|
if (Address > EndAddress)
|
||||||
|
return FindVadByAddressWin7(reinterpret_cast<_MMADDRESS_NODE_W7*>(Vad->RightChild), Address);
|
||||||
|
|
||||||
|
return Vad;
|
||||||
|
}
|
||||||
|
|
||||||
|
NTSTATUS ProtectUserRegionByPidWin7(
|
||||||
|
HANDLE Pid,
|
||||||
|
ULONG64 Address
|
||||||
|
)
|
||||||
|
{
|
||||||
|
PEPROCESS Process = nullptr;
|
||||||
|
|
||||||
|
NTSTATUS Status = PsLookupProcessByProcessId(Pid, &Process);
|
||||||
|
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
|
return Status;
|
||||||
|
|
||||||
|
KAPC_STATE ApcState{ 0 };
|
||||||
|
|
||||||
|
KeStackAttachProcess(Process, &ApcState);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Win7 x64:
|
||||||
|
//
|
||||||
|
// EPROCESS + 0x448
|
||||||
|
// |
|
||||||
|
// +---- _MM_AVL_TABLE
|
||||||
|
// |
|
||||||
|
// +0x000 BalancedRoot
|
||||||
|
// |
|
||||||
|
// +0x010 RightChild
|
||||||
|
//
|
||||||
|
// BalancedRoot.RightChild ²ÅÊÇʵ¼Ê VAD Tree Root
|
||||||
|
//
|
||||||
|
|
||||||
|
ULONG VadRootOffset = _eprocess_get_vadroot_offset();
|
||||||
|
|
||||||
|
auto BalancedRoot = reinterpret_cast<_MMADDRESS_NODE_W7*>(reinterpret_cast<PUCHAR>(Process) + VadRootOffset);
|
||||||
|
|
||||||
|
auto VadRoot = BalancedRoot->RightChild;
|
||||||
|
|
||||||
|
//DbgPrintEx(
|
||||||
|
// 77,
|
||||||
|
// 0,
|
||||||
|
// "[VAD] Process=%p VadRootOffset=%X BalancedRoot=%p VadRoot=%p Address=%llX\n",
|
||||||
|
// Process,
|
||||||
|
// VadRootOffset,
|
||||||
|
// BalancedRoot,
|
||||||
|
// VadRoot,
|
||||||
|
// Address
|
||||||
|
//);
|
||||||
|
|
||||||
|
auto Vad = FindVadByAddressWin7(VadRoot, Address);
|
||||||
|
|
||||||
|
//DbgPrintEx(77, 0, "[VAD] Vad=%p\n", Vad);
|
||||||
|
|
||||||
|
if (!Vad)
|
||||||
|
{
|
||||||
|
KeUnstackDetachProcess(&ApcState);
|
||||||
|
ObDereferenceObject(Process);
|
||||||
|
return STATUS_NOT_FOUND;
|
||||||
|
}
|
||||||
|
|
||||||
|
ULONGLONG StartAddress = Vad->StartingVpn << PAGE_SHIFT;
|
||||||
|
ULONGLONG EndAddress = ((Vad->EndingVpn + 1) << PAGE_SHIFT) - 1;
|
||||||
|
|
||||||
|
SIZE_T RegionSize = (SIZE_T)(EndAddress - StartAddress + 1);
|
||||||
|
|
||||||
|
//DbgPrintEx(
|
||||||
|
// 77,
|
||||||
|
// 0,
|
||||||
|
// "[VAD] Start=%llX End=%llX Size=%llX\n",
|
||||||
|
// StartAddress,
|
||||||
|
// EndAddress,
|
||||||
|
// RegionSize
|
||||||
|
//);
|
||||||
|
|
||||||
|
Vad->u.VadFlags.NoChange = 1;
|
||||||
|
Vad->u2.VadFlags2.SecNoChange = 1;
|
||||||
|
|
||||||
|
|
||||||
|
KeUnstackDetachProcess(&ApcState);
|
||||||
|
ObDereferenceObject(Process);
|
||||||
|
|
||||||
|
return STATUS_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
NTSTATUS ProtectUserRegionByPid(HANDLE Pid, ULONG64 Address)
|
||||||
|
{
|
||||||
|
if (!Pid || !Address) return STATUS_INVALID_PARAMETER;
|
||||||
|
|
||||||
|
auto version = utils::GetVersion();
|
||||||
|
|
||||||
|
if (version.dwBuildNumber == 7600 || version.dwBuildNumber == 7601)
|
||||||
|
return ProtectUserRegionByPidWin7(Pid, Address);
|
||||||
|
|
||||||
|
PEPROCESS Process = nullptr;
|
||||||
|
|
||||||
|
NTSTATUS Status = PsLookupProcessByProcessId(Pid, &Process);
|
||||||
|
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
|
return Status;
|
||||||
|
|
||||||
|
KAPC_STATE ApcState{ 0 };
|
||||||
|
KeStackAttachProcess(Process, &ApcState);
|
||||||
|
|
||||||
|
auto VadRoot = *reinterpret_cast<RTL_BALANCED_NODE**>(reinterpret_cast<ULONG64>(Process) + _eprocess_get_vadroot_offset());
|
||||||
|
|
||||||
|
auto Vad = FindVadByAddress(VadRoot, Address);
|
||||||
|
|
||||||
|
if (!Vad)
|
||||||
|
{
|
||||||
|
KeUnstackDetachProcess(&ApcState);
|
||||||
|
ObDereferenceObject(Process);
|
||||||
|
return STATUS_NOT_FOUND;
|
||||||
|
}
|
||||||
|
|
||||||
|
ULONGLONG StartVpn = ((ULONGLONG)Vad->StartingVpnHigh << 32) | Vad->StartingVpn;
|
||||||
|
|
||||||
|
ULONGLONG EndVpn = ((ULONGLONG)Vad->EndingVpnHigh << 32) | Vad->EndingVpn;
|
||||||
|
|
||||||
|
ULONGLONG StartAddress = StartVpn << PAGE_SHIFT;
|
||||||
|
|
||||||
|
ULONGLONG EndAddress = ((EndVpn + 1) << PAGE_SHIFT) - 1;
|
||||||
|
|
||||||
|
SIZE_T RegionSize = (SIZE_T)(EndAddress - StartAddress + 1);
|
||||||
|
|
||||||
|
PVOID SecureHandle = MmSecureVirtualMemory((PVOID)StartAddress, RegionSize, PAGE_READONLY);
|
||||||
|
|
||||||
|
if (SecureHandle) SetVadSecNoChange(Vad);
|
||||||
|
|
||||||
|
|
||||||
|
KeUnstackDetachProcess(&ApcState);
|
||||||
|
ObDereferenceObject(Process);
|
||||||
|
|
||||||
|
if (!SecureHandle)
|
||||||
|
return STATUS_ACCESS_DENIED;
|
||||||
|
|
||||||
|
return STATUS_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,172 @@
|
|||||||
|
#pragma once
|
||||||
|
#ifndef MEMORY_PROTECT_H
|
||||||
|
#define MEMORY_PROTECT_H
|
||||||
|
#include "Base.h"
|
||||||
|
|
||||||
|
#pragma warning(disable : 4201)
|
||||||
|
|
||||||
|
struct _MMSECURE_FLAGS
|
||||||
|
{
|
||||||
|
ULONG ReadOnly : 1; //0x0
|
||||||
|
ULONG ReadWrite : 1; //0x0
|
||||||
|
ULONG SecNoChange : 1; //0x0
|
||||||
|
ULONG NoDelete : 1; //0x0
|
||||||
|
ULONG RequiresPteReversal : 1; //0x0
|
||||||
|
ULONG ExclusiveSecure : 1; //0x0
|
||||||
|
ULONG UserModeOnly : 1; //0x0
|
||||||
|
ULONG NoInherit : 1; //0x0
|
||||||
|
ULONG CheckVad : 1; //0x0
|
||||||
|
ULONG Spare : 3; //0x0
|
||||||
|
};
|
||||||
|
|
||||||
|
struct _MMADDRESS_LIST
|
||||||
|
{
|
||||||
|
union
|
||||||
|
{
|
||||||
|
struct _MMSECURE_FLAGS Flags; //0x0
|
||||||
|
ULONG FlagsLong; //0x0
|
||||||
|
VOID* StartVa; //0x0
|
||||||
|
} u1; //0x0
|
||||||
|
VOID* EndVa; //0x8
|
||||||
|
};
|
||||||
|
typedef struct _MY_MI_VAD_EVENT_BLOCK
|
||||||
|
{
|
||||||
|
struct _MY_MI_VAD_EVENT_BLOCK* Next; // +0x00
|
||||||
|
|
||||||
|
union
|
||||||
|
{
|
||||||
|
_MMADDRESS_LIST SecureInfo; // +0x08
|
||||||
|
};
|
||||||
|
|
||||||
|
UCHAR Reserved[0x38]; // +0x18 ~ +0x4F
|
||||||
|
|
||||||
|
ULONG WaitReason; // +0x40
|
||||||
|
|
||||||
|
} MY_MI_VAD_EVENT_BLOCK, * PMY_MI_VAD_EVENT_BLOCK;
|
||||||
|
|
||||||
|
typedef struct _MY_MMVAD_SHORT
|
||||||
|
{
|
||||||
|
union
|
||||||
|
{
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
struct _MY_MMVAD_SHORT* NextVad;
|
||||||
|
PVOID ExtraCreateInfo;
|
||||||
|
};
|
||||||
|
|
||||||
|
RTL_BALANCED_NODE VadNode;
|
||||||
|
};
|
||||||
|
|
||||||
|
ULONG StartingVpn; // +0x18
|
||||||
|
ULONG EndingVpn; // +0x1C
|
||||||
|
UCHAR StartingVpnHigh; // +0x20
|
||||||
|
UCHAR EndingVpnHigh; // +0x21
|
||||||
|
UCHAR CommitChargeHigh; // +0x22
|
||||||
|
UCHAR SpareNT64VadUChar; // +0x23
|
||||||
|
LONG ReferenceCount; // +0x24
|
||||||
|
EX_PUSH_LOCK PushLock; // +0x28
|
||||||
|
|
||||||
|
union
|
||||||
|
{
|
||||||
|
ULONG LongFlags; // +0x30
|
||||||
|
ULONG VadFlags;
|
||||||
|
} u;
|
||||||
|
|
||||||
|
ULONG LongFlags1; // +0x34
|
||||||
|
PMY_MI_VAD_EVENT_BLOCK EventList; // +0x38
|
||||||
|
|
||||||
|
} MY_MMVAD_SHORT, * PMY_MMVAD_SHORT;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//0x28 bytes (sizeof)
|
||||||
|
typedef struct _MMADDRESS_NODE_W7
|
||||||
|
{
|
||||||
|
union
|
||||||
|
{
|
||||||
|
LONGLONG Balance : 2; //0x0
|
||||||
|
struct _MMADDRESS_NODE_W7* Parent; //0x0
|
||||||
|
} u1; //0x0
|
||||||
|
struct _MMADDRESS_NODE_W7* LeftChild; //0x8
|
||||||
|
struct _MMADDRESS_NODE_W7* RightChild; //0x10
|
||||||
|
ULONGLONG StartingVpn; //0x18
|
||||||
|
ULONGLONG EndingVpn; //0x20
|
||||||
|
|
||||||
|
}MMADDRESS_NODE_W7, * PMMADDRESS_NODE_W7;
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct _MMVAD_FLAGS
|
||||||
|
{
|
||||||
|
ULONGLONG CommitCharge : 51; //0x0
|
||||||
|
ULONGLONG NoChange : 1; //0x0
|
||||||
|
ULONGLONG VadType : 3; //0x0
|
||||||
|
ULONGLONG MemCommit : 1; //0x0
|
||||||
|
ULONGLONG Protection : 5; //0x0
|
||||||
|
ULONGLONG Spare : 2; //0x0
|
||||||
|
ULONGLONG PrivateMemory : 1; //0x0
|
||||||
|
} MMVAD_FLAGS, * PMMVAD_FLAGS;
|
||||||
|
|
||||||
|
typedef struct _MMVAD_FLAGS2
|
||||||
|
{
|
||||||
|
ULONG FileOffset : 24; //0x0
|
||||||
|
ULONG SecNoChange : 1; //0x0
|
||||||
|
ULONG OneSecured : 1; //0x0
|
||||||
|
ULONG MultipleSecured : 1; //0x0
|
||||||
|
ULONG Spare : 1; //0x0
|
||||||
|
ULONG LongVad : 1; //0x0
|
||||||
|
ULONG ExtendableFile : 1; //0x0
|
||||||
|
ULONG Inherit : 1; //0x0
|
||||||
|
ULONG CopyOnWrite : 1; //0x0
|
||||||
|
} MMVAD_FLAGS2, * PMMVAD_FLAGS2;
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct _MMVAD_W7
|
||||||
|
{
|
||||||
|
union
|
||||||
|
{
|
||||||
|
struct _MMVAD_W7* Parent;
|
||||||
|
LONGLONG Balance : 2;
|
||||||
|
} u1; // 0x00
|
||||||
|
|
||||||
|
struct _MMVAD_W7* LeftChild; // 0x08
|
||||||
|
struct _MMVAD_W7* RightChild; // 0x10
|
||||||
|
|
||||||
|
ULONGLONG StartingVpn; // 0x18
|
||||||
|
ULONGLONG EndingVpn; // 0x20
|
||||||
|
|
||||||
|
union
|
||||||
|
{
|
||||||
|
ULONGLONG LongFlags; // 0x28
|
||||||
|
MMVAD_FLAGS VadFlags;
|
||||||
|
} u; // 0x28
|
||||||
|
|
||||||
|
BYTE Reserved1[0x10]; // 0x30
|
||||||
|
|
||||||
|
union
|
||||||
|
{
|
||||||
|
ULONG LongFlags2; // 0x40
|
||||||
|
MMVAD_FLAGS2 VadFlags2;
|
||||||
|
} u2; // 0x40
|
||||||
|
|
||||||
|
} MMVAD_W7, * PMMVAD_W7;
|
||||||
|
|
||||||
|
namespace memory_protect
|
||||||
|
{
|
||||||
|
VOID SetVadSecNoChange(
|
||||||
|
_In_ MY_MMVAD_SHORT* Vad
|
||||||
|
);
|
||||||
|
|
||||||
|
MY_MMVAD_SHORT* FindVadByAddress(
|
||||||
|
_In_ RTL_BALANCED_NODE* Node,
|
||||||
|
_In_ ULONG64 Address
|
||||||
|
);
|
||||||
|
|
||||||
|
NTSTATUS ProtectUserRegionByPid(
|
||||||
|
HANDLE Pid,
|
||||||
|
ULONG64 Address
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif // !MEMORY_PROTECT_H
|
||||||
@@ -66,6 +66,7 @@ namespace mouse_keybord_hook
|
|||||||
{
|
{
|
||||||
if (_ntSendInput[0] == 0xff || _ntSendInput[1] == 0x25)
|
if (_ntSendInput[0] == 0xff || _ntSendInput[1] == 0x25)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
else return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto os = utils::GetVersion();
|
auto os = utils::GetVersion();
|
||||||
@@ -80,7 +81,7 @@ namespace mouse_keybord_hook
|
|||||||
|
|
||||||
//kernel_function::ke_unstack_detach_process(apc_state);
|
//kernel_function::ke_unstack_detach_process(apc_state);
|
||||||
//ObDereferenceObject(_eprocess_process);
|
//ObDereferenceObject(_eprocess_process);
|
||||||
return 0;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto remove_mouse_keybord_hook() -> BOOL
|
auto remove_mouse_keybord_hook() -> BOOL
|
||||||
|
|||||||
@@ -1,7 +1,14 @@
|
|||||||
#include "process_func.h"
|
#include "process_func.h"
|
||||||
|
#include "kernel_function.h"
|
||||||
|
#include "process_handle.h"
|
||||||
|
#include "utils.h"
|
||||||
|
#include "kernel_api.h"
|
||||||
|
|
||||||
namespace process_function
|
namespace process_function
|
||||||
{
|
{
|
||||||
ULONG orin_protect_val;
|
ULONG orin_protect_val;
|
||||||
|
HANDLE g_thread_handle;
|
||||||
|
KEVENT g_stop_event;
|
||||||
|
|
||||||
auto eprocess_get_protect_offset() -> UINT32
|
auto eprocess_get_protect_offset() -> UINT32
|
||||||
{
|
{
|
||||||
@@ -12,6 +19,131 @@ namespace process_function
|
|||||||
return offset;
|
return offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto ps_get_next_process_thread(PEPROCESS Process, PETHREAD Thread)->PETHREAD
|
||||||
|
{
|
||||||
|
typedef PETHREAD(NTAPI* fnPsGetNextProcessThread)(IN PEPROCESS Process, IN PETHREAD Thread);
|
||||||
|
static fnPsGetNextProcessThread _PsGetNextProcessThread = NULL;
|
||||||
|
if (!_PsGetNextProcessThread)
|
||||||
|
{
|
||||||
|
auto ps_resume_process = reinterpret_cast<unsigned char*>(kernel_api::imported.ps_resume_process);
|
||||||
|
if (!ps_resume_process) return 0;
|
||||||
|
|
||||||
|
unsigned int break_by_count = 0;
|
||||||
|
unsigned int cur_index_count = 0;
|
||||||
|
unsigned int cur_ref_count = 0;
|
||||||
|
|
||||||
|
auto os = utils::GetVersion();
|
||||||
|
if (os.dwBuildNumber == 7600 || os.dwBuildNumber == 7601)
|
||||||
|
{
|
||||||
|
break_by_count = 3;
|
||||||
|
while (cur_index_count < break_by_count)
|
||||||
|
{
|
||||||
|
if (ps_resume_process[cur_ref_count++] == 0xe8)
|
||||||
|
{
|
||||||
|
cur_index_count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_PsGetNextProcessThread = (fnPsGetNextProcessThread)((*(int*)&ps_resume_process[cur_ref_count]) + &ps_resume_process[cur_ref_count] + 4);
|
||||||
|
}
|
||||||
|
else if (os.dwBuildNumber >= 14393 && os.dwBuildNumber <= 19045)
|
||||||
|
{
|
||||||
|
break_by_count = 2;
|
||||||
|
|
||||||
|
while (cur_index_count < break_by_count)
|
||||||
|
{
|
||||||
|
if (ps_resume_process[cur_ref_count++] == 0xe8)
|
||||||
|
{
|
||||||
|
cur_index_count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_PsGetNextProcessThread = (fnPsGetNextProcessThread)((*(int*)&ps_resume_process[cur_ref_count]) + &ps_resume_process[cur_ref_count] + 4);
|
||||||
|
}
|
||||||
|
else if (os.dwBuildNumber >= 22000)
|
||||||
|
{
|
||||||
|
auto ntoskrnl = kernel_function::GetKernelModule("ntoskrnl.exe");
|
||||||
|
|
||||||
|
auto address = utils::FindSectionsCode(ntoskrnl,
|
||||||
|
"\xF7\x00\x74\x00\x00\x20\x00\x75\x00\xBA\x01\x00\x00\x00\x48\x8B\x00\xE8",
|
||||||
|
"x?xxxxxx?xxxxxxx?x", ".text");
|
||||||
|
|
||||||
|
if (!address) return 0;
|
||||||
|
|
||||||
|
|
||||||
|
while (break_by_count < 1)
|
||||||
|
{
|
||||||
|
if (*reinterpret_cast<unsigned char*>(address) == 0xe8)
|
||||||
|
{
|
||||||
|
++break_by_count;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
--reinterpret_cast<unsigned char*&>(address);
|
||||||
|
}
|
||||||
|
|
||||||
|
_PsGetNextProcessThread = (fnPsGetNextProcessThread)((*(int*)&ps_resume_process[cur_ref_count] + 1) + &ps_resume_process[cur_ref_count] + 5);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!_PsGetNextProcessThread) return 0;
|
||||||
|
|
||||||
|
return _PsGetNextProcessThread(Process, Thread);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
auto ps_get_next_process(PEPROCESS process)->PEPROCESS
|
||||||
|
{
|
||||||
|
typedef PEPROCESS(NTAPI* fnPsGetNextProcess)(IN PEPROCESS Process);
|
||||||
|
static fnPsGetNextProcess _PsGetNextProcess = NULL;
|
||||||
|
|
||||||
|
if (!_PsGetNextProcess)
|
||||||
|
{
|
||||||
|
auto os = utils::GetVersion();
|
||||||
|
if (os.dwBuildNumber == 7601 || os.dwBuildNumber == 7600)
|
||||||
|
{
|
||||||
|
|
||||||
|
auto kmoudle = kernel_function::GetKernelModule("ntoskrnl.exe");
|
||||||
|
if (!kmoudle) return 0;
|
||||||
|
|
||||||
|
auto address = utils::FindSectionsCode(kmoudle,
|
||||||
|
"\xE8\x00\x00\x00\x00\x48\x8B\xF8\x48\x89\x44\x24\x48\x48\x3B\xC3\xB9\x01\x00\x00\x00",
|
||||||
|
"x????xxxxxxxxxxxxxxxx", "PAGE");
|
||||||
|
|
||||||
|
if (!address) return 0;
|
||||||
|
|
||||||
|
_PsGetNextProcess = (fnPsGetNextProcess)((*(int*)(address + 1)) + address + 5);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
auto kmoudle = kernel_function::GetKernelModule("ntoskrnl.exe");
|
||||||
|
if (!kmoudle) return 0;
|
||||||
|
|
||||||
|
auto address = utils::FindSectionsCode(kmoudle, "\x81\x00\x22\x00\x00\xC0\x75\x00\x48\x8B\x00\x24\x00\x48\x8B", "x?xxxxx?xx?x?xx", "PAGE");
|
||||||
|
if (!address) return 0;
|
||||||
|
|
||||||
|
|
||||||
|
unsigned int break_by_count = 0;
|
||||||
|
while (break_by_count < 1)
|
||||||
|
{
|
||||||
|
if (*reinterpret_cast<unsigned char*>(address) == 0xe8)
|
||||||
|
{
|
||||||
|
++break_by_count;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
++reinterpret_cast<unsigned char*&>(address);
|
||||||
|
}
|
||||||
|
|
||||||
|
_PsGetNextProcess = (fnPsGetNextProcess)((*(int*)(address + 1)) + address + 5);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!_PsGetNextProcess) return 0;
|
||||||
|
|
||||||
|
|
||||||
|
return _PsGetNextProcess(process);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
auto eprocess_protect_process_on(UINT32 Pid) -> NTSTATUS
|
auto eprocess_protect_process_on(UINT32 Pid) -> NTSTATUS
|
||||||
{
|
{
|
||||||
@@ -51,6 +183,85 @@ namespace process_function
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto monitor_process_handle(LPVOID)->VOID
|
||||||
|
{
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
NTSTATUS status{ 0 };
|
||||||
|
for (ULONG i = 4; i < 0x401000; i += 4)
|
||||||
|
{
|
||||||
|
PEPROCESS process{ 0 };
|
||||||
|
|
||||||
|
status = PsLookupProcessByProcessId(ULongToHandle((ULONG)i), &process);
|
||||||
|
if (!NT_SUCCESS(status))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (PsGetProcessExitStatus(process) != STATUS_PENDING) {
|
||||||
|
ObDereferenceObject(process);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
KAPC_STATE apc_state{ 0 };
|
||||||
|
KeStackAttachProcess(process, &apc_state);
|
||||||
|
|
||||||
|
process_handle::scan_and_protect_handles(process);
|
||||||
|
|
||||||
|
KeUnstackDetachProcess(&apc_state);
|
||||||
|
|
||||||
|
ObDereferenceObject(process);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
LARGE_INTEGER interval{ 0 };
|
||||||
|
interval.QuadPart = -20 * 1000 * 1000;
|
||||||
|
if (KeWaitForSingleObject(&g_stop_event,
|
||||||
|
Executive,
|
||||||
|
KernelMode,
|
||||||
|
FALSE,
|
||||||
|
&interval) != STATUS_TIMEOUT)
|
||||||
|
{
|
||||||
|
PsTerminateSystemThread(STATUS_SUCCESS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
auto start_process_handle_monitor()->NTSTATUS
|
||||||
|
{
|
||||||
|
KeInitializeEvent(&g_stop_event, NotificationEvent, FALSE);
|
||||||
|
return PsCreateSystemThread(&g_thread_handle, THREAD_ALL_ACCESS, 0, 0, 0, monitor_process_handle, 0);
|
||||||
|
}
|
||||||
|
auto stop_process_handle_monitor() -> NTSTATUS
|
||||||
|
{
|
||||||
|
|
||||||
|
KeSetEvent(&g_stop_event, IO_NO_INCREMENT, FALSE);
|
||||||
|
if (g_thread_handle)
|
||||||
|
{
|
||||||
|
PETHREAD thread_object = nullptr;
|
||||||
|
NTSTATUS reference_status = ObReferenceObjectByHandle(
|
||||||
|
g_thread_handle,
|
||||||
|
0,
|
||||||
|
*PsThreadType,
|
||||||
|
KernelMode,
|
||||||
|
reinterpret_cast<PVOID*>(&thread_object),
|
||||||
|
nullptr);
|
||||||
|
if (NT_SUCCESS(reference_status) && thread_object)
|
||||||
|
{
|
||||||
|
KeWaitForSingleObject(
|
||||||
|
thread_object,
|
||||||
|
Executive,
|
||||||
|
KernelMode,
|
||||||
|
FALSE,
|
||||||
|
nullptr);
|
||||||
|
ObDereferenceObject(thread_object);
|
||||||
|
}
|
||||||
|
ObCloseHandle(g_thread_handle, KernelMode);
|
||||||
|
g_thread_handle = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NTSTATUS();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -6,11 +6,21 @@
|
|||||||
|
|
||||||
namespace process_function
|
namespace process_function
|
||||||
{
|
{
|
||||||
|
|
||||||
|
auto ps_get_next_process(PEPROCESS process)->PEPROCESS;
|
||||||
|
|
||||||
|
auto ps_get_next_process_thread(PEPROCESS Process, PETHREAD Thread)->PETHREAD;
|
||||||
|
|
||||||
auto eprocess_protect_process_on(UINT32 Pid)->NTSTATUS;
|
auto eprocess_protect_process_on(UINT32 Pid)->NTSTATUS;
|
||||||
|
|
||||||
auto eprocess_protect_process_off(UINT32 Pid)->NTSTATUS;
|
auto eprocess_protect_process_off(UINT32 Pid)->NTSTATUS;
|
||||||
|
|
||||||
auto kernel_kill_process(UINT32 Pid)->NTSTATUS;
|
auto kernel_kill_process(UINT32 Pid)->NTSTATUS;
|
||||||
|
|
||||||
|
auto start_process_handle_monitor()->NTSTATUS;
|
||||||
|
|
||||||
|
auto stop_process_handle_monitor()->NTSTATUS;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // !PROCESS_FUNC
|
#endif // !PROCESS_FUNC
|
||||||
|
|||||||
@@ -0,0 +1,191 @@
|
|||||||
|
#include "process_handle.h"
|
||||||
|
#include "utils.h"
|
||||||
|
#include "protect_filter.h"
|
||||||
|
namespace process_handle
|
||||||
|
{
|
||||||
|
auto get_eprocess_objectTable() -> ULONG
|
||||||
|
{
|
||||||
|
auto os = utils::GetVersion();
|
||||||
|
if (os.dwBuildNumber == 7601 || os.dwBuildNumber == 7600)
|
||||||
|
return 0x200;
|
||||||
|
|
||||||
|
UNICODE_STRING unstr{ 0 };
|
||||||
|
RtlInitUnicodeString(&unstr, L"PsGetProcessWow64Process");
|
||||||
|
|
||||||
|
auto func = (unsigned char*)MmGetSystemRoutineAddress(&unstr);
|
||||||
|
auto offset = *(int*)(func + 3);
|
||||||
|
|
||||||
|
return (ULONG)(offset - 0x10);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PHANDLE_TABLE_ENTRY GetHandleTableEntry(ULONG64 TableCode, ULONG handle_value)
|
||||||
|
{
|
||||||
|
if (!TableCode)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
if (handle_value < 4 || (handle_value & 3))
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
ULONG index = handle_value >> 2;
|
||||||
|
|
||||||
|
ULONG level = static_cast<ULONG>(TableCode & 3);
|
||||||
|
|
||||||
|
ULONG64 table = TableCode & ~3ULL;
|
||||||
|
|
||||||
|
if (!table)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
constexpr ULONG entries_per_page = PAGE_SIZE / sizeof(HANDLE_TABLE_ENTRY);
|
||||||
|
|
||||||
|
constexpr ULONG pointers_per_page = PAGE_SIZE / sizeof(ULONG64);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* level 0
|
||||||
|
*/
|
||||||
|
if (level == 0)
|
||||||
|
{
|
||||||
|
if (index >= entries_per_page)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
auto entries = reinterpret_cast<PHANDLE_TABLE_ENTRY>(table);
|
||||||
|
|
||||||
|
return &entries[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* level 1
|
||||||
|
*/
|
||||||
|
if (level == 1)
|
||||||
|
{
|
||||||
|
ULONG page_index = index / entries_per_page;
|
||||||
|
|
||||||
|
ULONG entry_index = index % entries_per_page;
|
||||||
|
|
||||||
|
if (page_index >= pointers_per_page)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
auto table_array = reinterpret_cast<PULONG64>(table);
|
||||||
|
|
||||||
|
ULONG64 entry_page = table_array[page_index];
|
||||||
|
|
||||||
|
if (!entry_page)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
return reinterpret_cast<PHANDLE_TABLE_ENTRY>(entry_page) + entry_index;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* level 2
|
||||||
|
*/
|
||||||
|
if (level == 2)
|
||||||
|
{
|
||||||
|
constexpr ULONG entries_per_level2 = pointers_per_page * entries_per_page;
|
||||||
|
|
||||||
|
ULONG level1_index = index / entries_per_level2;
|
||||||
|
|
||||||
|
ULONG remainder = index % entries_per_level2;
|
||||||
|
|
||||||
|
ULONG level2_index = remainder / entries_per_page;
|
||||||
|
|
||||||
|
ULONG entry_index = remainder % entries_per_page;
|
||||||
|
|
||||||
|
if (level1_index >= pointers_per_page)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
auto table_array1 = reinterpret_cast<PULONG64>(table);
|
||||||
|
|
||||||
|
ULONG64 table2 = table_array1[level1_index];
|
||||||
|
|
||||||
|
if (!table2)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
auto table_array2 = reinterpret_cast<PULONG64>(table2);
|
||||||
|
|
||||||
|
if (level2_index >= pointers_per_page)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
ULONG64 entry_page = table_array2[level2_index];
|
||||||
|
|
||||||
|
if (!entry_page)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
return reinterpret_cast<PHANDLE_TABLE_ENTRY>(entry_page) + entry_index;
|
||||||
|
}
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto scan_and_protect_handles(PEPROCESS process) -> BOOL
|
||||||
|
{
|
||||||
|
|
||||||
|
_HANDLE_TABLE_W7* handle_table_w7{ 0 };
|
||||||
|
_HANDLE_TABLE_w10* handle_table_w10{ 0 };
|
||||||
|
|
||||||
|
ULONG64 TableCode = NULL;
|
||||||
|
ULONG max_handle = 0;
|
||||||
|
|
||||||
|
auto os = utils::GetVersion();
|
||||||
|
|
||||||
|
if (os.dwBuildNumber == 7601 || os.dwBuildNumber == 7600)
|
||||||
|
{
|
||||||
|
handle_table_w7 = *(_HANDLE_TABLE_W7**)((ULONG64)process + get_eprocess_objectTable());
|
||||||
|
|
||||||
|
if (!handle_table_w7)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
TableCode = handle_table_w7->TableCode;
|
||||||
|
|
||||||
|
max_handle = handle_table_w7->NextHandleNeedingPool;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
handle_table_w10 = *(_HANDLE_TABLE_w10**)((ULONG64)process + get_eprocess_objectTable());
|
||||||
|
|
||||||
|
if (!handle_table_w10)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
TableCode = handle_table_w10->TableCode;
|
||||||
|
|
||||||
|
max_handle = handle_table_w10->NextHandleNeedingPool;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!TableCode)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
for (ULONG value = 4; value < max_handle; value += 4)
|
||||||
|
{
|
||||||
|
HANDLE Handle = (HANDLE)(ULONG_PTR)value;
|
||||||
|
|
||||||
|
PEPROCESS Process = nullptr;
|
||||||
|
|
||||||
|
auto status = ObReferenceObjectByHandle(Handle, 0, *PsProcessType, UserMode, reinterpret_cast<PVOID*>(&Process), nullptr);
|
||||||
|
|
||||||
|
if (!NT_SUCCESS(status))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
auto entry = GetHandleTableEntry(TableCode, value);
|
||||||
|
if (entry)
|
||||||
|
{
|
||||||
|
auto dwPid = PsGetProcessId(Process);
|
||||||
|
if (dwPid != NULL)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (protect_filter::is_protect_pid(HandleToLong(dwPid)) &&
|
||||||
|
entry->GrantedAccessBits != 0)
|
||||||
|
{
|
||||||
|
if (PsGetProcessId(process) != dwPid)
|
||||||
|
{
|
||||||
|
entry->GrantedAccessBits = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ObDereferenceObject(Process);
|
||||||
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,147 @@
|
|||||||
|
#pragma once
|
||||||
|
#ifndef PROCESS_HANDLE_H
|
||||||
|
#define PROCESS_HANDLE_H
|
||||||
|
#include "Base.h"
|
||||||
|
|
||||||
|
#pragma warning(disable : 4201)
|
||||||
|
struct _EX_PUSH_LOCK
|
||||||
|
{
|
||||||
|
union
|
||||||
|
{
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
ULONGLONG Locked : 1; //0x0
|
||||||
|
ULONGLONG Waiting : 1; //0x0
|
||||||
|
ULONGLONG Waking : 1; //0x0
|
||||||
|
ULONGLONG MultipleShared : 1; //0x0
|
||||||
|
ULONGLONG Shared : 60; //0x0
|
||||||
|
};
|
||||||
|
ULONGLONG Value; //0x0
|
||||||
|
VOID* Ptr; //0x0
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
struct _HANDLE_TABLE_FREE_LIST
|
||||||
|
{
|
||||||
|
struct _EX_PUSH_LOCK FreeListLock; //0x0
|
||||||
|
union _HANDLE_TABLE_ENTRY* FirstFreeHandleEntry; //0x8
|
||||||
|
union _HANDLE_TABLE_ENTRY* LastFreeHandleEntry; //0x10
|
||||||
|
LONG HandleCount; //0x18
|
||||||
|
ULONG HighWaterMark; //0x1c
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
struct _HANDLE_TABLE_w10
|
||||||
|
{
|
||||||
|
ULONG NextHandleNeedingPool; //0x0
|
||||||
|
LONG ExtraInfoPages; //0x4
|
||||||
|
volatile ULONGLONG TableCode; //0x8
|
||||||
|
struct _EPROCESS* QuotaProcess; //0x10
|
||||||
|
struct _LIST_ENTRY HandleTableList; //0x18
|
||||||
|
ULONG UniqueProcessId; //0x28
|
||||||
|
union
|
||||||
|
{
|
||||||
|
ULONG Flags; //0x2c
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
UCHAR StrictFIFO : 1; //0x2c
|
||||||
|
UCHAR EnableHandleExceptions : 1; //0x2c
|
||||||
|
UCHAR Rundown : 1; //0x2c
|
||||||
|
UCHAR Duplicated : 1; //0x2c
|
||||||
|
UCHAR RaiseUMExceptionOnInvalidHandleClose : 1; //0x2c
|
||||||
|
};
|
||||||
|
};
|
||||||
|
struct _EX_PUSH_LOCK HandleContentionEvent; //0x30
|
||||||
|
struct _EX_PUSH_LOCK HandleTableLock; //0x38
|
||||||
|
union
|
||||||
|
{
|
||||||
|
struct _HANDLE_TABLE_FREE_LIST FreeLists[1]; //0x40
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
UCHAR ActualEntry[32]; //0x40
|
||||||
|
struct _HANDLE_TRACE_DEBUG_INFO* DebugInfo; //0x60
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
struct _HANDLE_TABLE_W7
|
||||||
|
{
|
||||||
|
ULONGLONG TableCode; //0x0
|
||||||
|
struct _EPROCESS* QuotaProcess; //0x8
|
||||||
|
VOID* UniqueProcessId; //0x10
|
||||||
|
struct _EX_PUSH_LOCK HandleLock; //0x18
|
||||||
|
struct _LIST_ENTRY HandleTableList; //0x20
|
||||||
|
struct _EX_PUSH_LOCK HandleContentionEvent; //0x30
|
||||||
|
struct _HANDLE_TRACE_DEBUG_INFO* DebugInfo; //0x38
|
||||||
|
LONG ExtraInfoPages; //0x40
|
||||||
|
union
|
||||||
|
{
|
||||||
|
ULONG Flags; //0x44
|
||||||
|
UCHAR StrictFIFO : 1; //0x44
|
||||||
|
};
|
||||||
|
ULONG FirstFreeHandle; //0x48
|
||||||
|
struct _HANDLE_TABLE_ENTRY_EX* LastFreeHandleEntry; //0x50
|
||||||
|
ULONG HandleCount; //0x58
|
||||||
|
ULONG NextHandleNeedingPool; //0x5c
|
||||||
|
ULONG HandleCountHighWatermark; //0x60
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
struct _HANDLE_TABLE_ENTRY_INFO
|
||||||
|
{
|
||||||
|
ULONG AuditMask; //0x0
|
||||||
|
ULONG MaxRelativeAccessMask; //0x4
|
||||||
|
};
|
||||||
|
|
||||||
|
struct _EXHANDLE
|
||||||
|
{
|
||||||
|
union
|
||||||
|
{
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
ULONG TagBits : 2; //0x0
|
||||||
|
ULONG Index : 30; //0x0
|
||||||
|
};
|
||||||
|
VOID* GenericHandleOverlay; //0x0
|
||||||
|
ULONGLONG Value; //0x0
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
// Windows x64 stores one handle entry in 16 bytes. The encoded object pointer
|
||||||
|
// is in the first qword and the granted-access mask is in the second.
|
||||||
|
typedef struct _HANDLE_TABLE_ENTRY_EX
|
||||||
|
{
|
||||||
|
union
|
||||||
|
{
|
||||||
|
volatile LONG64 VolatileLowValue;
|
||||||
|
LONG64 LowValue;
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
ULONGLONG Unlocked : 1;
|
||||||
|
ULONGLONG RefCnt : 16;
|
||||||
|
ULONGLONG Attributes : 3;
|
||||||
|
ULONGLONG ObjectPointerBits : 44;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
union
|
||||||
|
{
|
||||||
|
LONG64 HighValue;
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
ULONG GrantedAccessBits : 25;
|
||||||
|
ULONG NoRightsUpgrade : 1;
|
||||||
|
ULONG Spare1 : 6;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
} HANDLE_TABLE_ENTRY, * PHANDLE_TABLE_ENTRY;
|
||||||
|
|
||||||
|
|
||||||
|
namespace process_handle
|
||||||
|
{
|
||||||
|
auto scan_and_protect_handles(PEPROCESS process)->BOOL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif // !PROCESS_HANDLE_H
|
||||||
Reference in New Issue
Block a user