Skip to content

Commit f2e4baf

Browse files
committed
fix bugs
1 parent bf9592b commit f2e4baf

File tree

7 files changed

+86
-20
lines changed

7 files changed

+86
-20
lines changed

CECheater/CECheater.vcxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
<PrecompiledHeader>NotUsing</PrecompiledHeader>
9696
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
9797
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
98+
<LanguageStandard>stdcpp17</LanguageStandard>
9899
</ClCompile>
99100
<Link>
100101
<SubSystem>Windows</SubSystem>
@@ -113,6 +114,7 @@
113114
<PrecompiledHeader>NotUsing</PrecompiledHeader>
114115
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
115116
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
117+
<LanguageStandard>stdcpp17</LanguageStandard>
116118
</ClCompile>
117119
<Link>
118120
<SubSystem>Windows</SubSystem>
@@ -131,6 +133,7 @@
131133
<PrecompiledHeader>NotUsing</PrecompiledHeader>
132134
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
133135
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
136+
<LanguageStandard>stdcpp17</LanguageStandard>
134137
</ClCompile>
135138
<Link>
136139
<SubSystem>Windows</SubSystem>
@@ -149,6 +152,7 @@
149152
<PrecompiledHeader>NotUsing</PrecompiledHeader>
150153
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
151154
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
155+
<LanguageStandard>stdcpp17</LanguageStandard>
152156
</ClCompile>
153157
<Link>
154158
<SubSystem>Windows</SubSystem>

CECheater/MemLoadDriver.cpp

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ static BYTE shellcode_JmpDriverEntry[] = {
473473
};
474474

475475
// 加载自己的未签名驱动
476-
bool DBK_LoadMyDriver(const wchar_t* driverFileName, const wchar_t* driverName)
476+
bool DBK_LoadMyDriver(LoadType loadType, const wchar_t* driverFilePath, const wchar_t* driverName)
477477
{
478478
bool result = true;
479479

@@ -492,14 +492,6 @@ bool DBK_LoadMyDriver(const wchar_t* driverFileName, const wchar_t* driverName)
492492
{
493493
// 构造映像内存Image
494494
// 1.将文件映射到内存pFileBuffer,文件大小为fileBufferLen,映像大小为imageSize
495-
WCHAR driverFilePath[MAX_PATH] = { 0 };
496-
if (!GetCurrentModuleDirPath(driverFilePath))
497-
{
498-
LOG("GetCurrentModuleDirPath failed");
499-
result = false;
500-
break;
501-
}
502-
wcscat(driverFilePath, driverFileName);
503495
pFileBuffer = LoadFileToMemory(driverFilePath, fileBufferLen);
504496
if (NULL == pFileBuffer || 0 == fileBufferLen)
505497
{
@@ -563,8 +555,7 @@ bool DBK_LoadMyDriver(const wchar_t* driverFileName, const wchar_t* driverName)
563555
// 获取驱动起始地址
564556
UINT64 pDriverInitialize = (UINT64)CONVERT_RVA(pKernelImage, pImageNtHeaders->OptionalHeader.AddressOfEntryPoint);
565557

566-
bool useIoCreateDriver = true;
567-
if (useIoCreateDriver)
558+
if (LoadByIoCreateDriver == loadType)
568559
{
569560
// 构造调用IoCreateDriver来创建驱动的shellcode
570561
// 1.shellcode大小为shellcodeSize
@@ -608,7 +599,7 @@ bool DBK_LoadMyDriver(const wchar_t* driverFileName, const wchar_t* driverName)
608599
break;
609600
}
610601
}
611-
else
602+
else if (LoadByShellcode == loadType)
612603
{
613604
// 构造直接调用DriverEntry的shellcode
614605
shellcodeSize = sizeof(shellcode_JmpDriverEntry);

CECheater/MemLoadDriver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
#include "DBKControl.h"
33

44
// ¼ÓÔØ×Ô¼ºµÄδǩÃûÇý¶¯
5-
bool DBK_LoadMyDriver(const wchar_t* driverFileName, const wchar_t* driverName);
5+
bool DBK_LoadMyDriver(LoadType loadType, const wchar_t* driverFilePath, const wchar_t* driverName);

CECheater/common.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include <string>
55
#include <thread>
66
#include <assert.h>
7+
#include <iostream>
8+
#include <filesystem>
79

810
#pragma warning(disable: 4996)
911

@@ -23,6 +25,12 @@
2325
#define DBK_DRIVER_NAME L"richstuffk32.sys"
2426
#endif
2527

28+
enum LoadType
29+
{
30+
LoadByShellcode, // 当作shellcode来加载驱动,会由当前进程直接运行驱动的入口点代码
31+
LoadByIoCreateDriver, // 调用IoCreateDriver加载驱动,会创建驱动对象,并由系统进程运行驱动的入口点代码
32+
};
33+
2634
std::string Format(const char* format, ...);
2735
std::wstring Format(const wchar_t* format, ...);
2836

CECheater/dllmain.cpp

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,61 @@
33
#include "DBKControl.h"
44
#include "MemLoadDriver.h"
55

6+
static LoadType g_LoadType;
7+
static WCHAR g_DriverFilePath[MAX_PATH] = { 0 };
8+
static WCHAR g_DriverName[100] = L"\\FileSystem\\";
9+
10+
bool ParseCommandLine()
11+
{
12+
int nArgs = 0;
13+
LPWSTR* argList = CommandLineToArgvW(GetCommandLineW(), &nArgs);
14+
if (nArgs < 3)
15+
{
16+
LOG("Number of command args is too few: %d", nArgs);
17+
return false;
18+
}
19+
20+
// 判断驱动文件是否存在
21+
if (!std::filesystem::exists(argList[2]))
22+
{
23+
LOG("Parameter error, path not exist: %ws", argList[2]);
24+
return false;
25+
}
26+
LOG("Find driver file path: %ws", g_DriverFilePath);
27+
28+
// 获取驱动文件绝对路径
29+
std::filesystem::path driverFilePath = std::filesystem::absolute(argList[2]);
30+
wcscpy(g_DriverFilePath, driverFilePath.c_str());
31+
32+
// 获取驱动文件名
33+
std::wstring driverName = driverFilePath.stem();
34+
if (driverName.length() > 90)
35+
{
36+
LOG("Parameter error, file name is too long: %ws", driverName.c_str());
37+
return false;
38+
}
39+
wcscat(g_DriverName, driverName.c_str());
40+
41+
// 获取加载类型
42+
if (0 == _wcsicmp(argList[1], L"-load_by_shellcode"))
43+
{
44+
g_LoadType = LoadByShellcode;
45+
LOG("Parameter error, load type: load by shellcode");
46+
}
47+
else if (0 == _wcsicmp(argList[1], L"-load_by_driver"))
48+
{
49+
g_LoadType = LoadByIoCreateDriver;
50+
LOG("load type: load by driver, driver name: %ws", g_DriverName);
51+
}
52+
else
53+
{
54+
LOG("Unknown load type: %ws", argList[1]);
55+
return false;
56+
}
57+
58+
return true;
59+
}
60+
661
void Worker()
762
{
863
// 提权
@@ -41,7 +96,7 @@ void Worker()
4196
LOG("init DBKDriver success");
4297

4398
// 加载自定义驱动
44-
if (!DBK_LoadMyDriver(DRIVER_TO_LOAD, DRIVER_NAME))
99+
if (!DBK_LoadMyDriver(g_LoadType, g_DriverFilePath, g_DriverName))
45100
{
46101
LOG("load my driver failed");
47102
return;
@@ -59,6 +114,12 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReser
59114

60115
__try
61116
{
117+
if (!ParseCommandLine())
118+
{
119+
LOG("ParseCommandLine failed");
120+
__leave;
121+
}
122+
62123
Worker();
63124
}
64125
__finally

README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,19 @@ https://bbs.kanxue.com/thread-277919.htm
1515

1616

1717
# 编译
18-
visual studio 2022 + x64 config(低版本的visual studio应该也是可以的)
18+
CECheater项目的编译配置为“C++17 + vs2022 + x64 config”,编译完后将生成的lua53-64.dll替换掉bin64里原来的lua53-64.dll就可以了
1919

2020

21-
# 部署
22-
1.如果要直接使用部署结果,bin64.7z文件夹中提供了两种不同的方式加载未签名驱动MyDriver.sys,在“bin64\READMD.md”中有具体描述,您可以选择其中一种方式后替换掉MyDriver.sys即可
21+
# 运行
22+
文件夹bin64.7z里提供了最终部署结果,需要以管理员权限运行,提供了两种不同的方式加载未签名驱动MyDriver.sys
2323

24-
2.如果要自己编译源码,则编译完后将CECheater项目生成的lua53-64.dll替换掉bin64里原来的lua53-64.dll就可以了
24+
1.将MyDriver.sys映射到内存中,修复其RVA和导入表,之后由当前进程直接运行驱动的入口点代码
2525

26+
richstuff-x86_64.exe -load_by_shellcode .\\MyDriver.sys
2627

27-
# 运行
28-
以管理员权限运行bin64.7z里的richstuff-x86_64.exe,进程会导入lua53-64.dll,这个dll会加载richstuffk64.sys,之后利用richstuffk64.sys提供的功能将MyDriver.sys映射到内存中,修复其RVA和导入表,并运行该驱动
28+
2.将MyDriver.sys映射到内存中,修复其RVA和导入表,之后调用IoCreateDriver来加载驱动,会创建驱动对象,并由系统进程运行驱动的入口点代码
29+
30+
richstuff-x86_64.exe -load_by_driver .\\MyDriver.sys
2931

3032

3133
# 支持平台

bin64.7z

-528 KB
Binary file not shown.

0 commit comments

Comments
 (0)