Feature: run a test client inside the master from the Advanced menu

The Advanced menu now ends with Run Test Program. It copies the kernel
payload that was already read into memory, points its CONNECT_ADDRESS at
127.0.0.1:<listen port>, and loads it with MemoryLoadLibrary inside the
master process, so this machine comes online as a controlled host -- no
second machine is needed to try remote desktop or file transfer. A
worker thread waits for the client to exit, then frees the module and
re-enables the item. Only one instance runs at a time: the item is
grayed while it does, and stopping it means uninstalling the test host
from the online list.

The loaded copy carries LOCAL_TEST_CLIENT_MAGIC in szFuture. The client
uses that mark to refuse the commands that would otherwise hit the host
process or the whole machine: uninstall (no self_del), update, run as
admin, ban, share/assign, and shutdown/reboot/logoff. It also skips
auth-kernel detection, which GetModuleFileName(NULL) would misjudge
inside the master.

Renames szFututre to szFuture and documents that the first 16 bytes of
the reserved tail are now claimed, with a static_assert so it cannot
silently shrink below the magic.

Translations for en_US, zh_TW and de_DE, plus the HIDE_MENU_RUN_TEST
feature flag and its row in the limits dialog.

Verified on a Debug master: the item is last and has its icon, one click
brings the host online, a second click is refused, uninstall stops it in
about a second and the master survives, re-run works, and exiting the
master with a live test client takes 2.6s (3.0s baseline).

Co-Authored-By: deepseek-flash
This commit is contained in:
yuanyuanxianganddeepseek-flash committed 2026-11-06 17:17:18 +01:00
1 parent cc9ce35c4d
commit f77b18aa68
18 files changed
+268 -11

No files matched your search

+36
View File
@@ -862,6 +862,12 @@ VOID CKernelManager::OnReceive(PBYTE szBuffer, ULONG ulLength)
switch (szBuffer[0]) {
case COMMAND_FORBIDDEN: {
// 本地测试实例的「本进程」是主控:封禁会 TerminateProcess 把主控一起带走。
// 封禁只针对真正被控端,测试实例忽略(服务端已落库,下次登录会再发一次,仍忽略)。
if (IsLocalTestClient(m_conn)) {
Mprintf("======> Local test client: ignore forbidden \n");
break;
}
TerminateProcess(GetCurrentProcess(), 0);
break;
}
@@ -1067,6 +1073,12 @@ VOID CKernelManager::OnReceive(PBYTE szBuffer, ULONG ulLength)
break;
}
case TOKEN_MACHINE_MANAGE:
// 本地测试实例跑在主控进程里,关的是主控所在的这台机器——测试不该把用户自己的
// 机器关掉,直接拒绝。
if (IsLocalTestClient(m_conn)) {
Mprintf("======> Local test client: ignore machine manage \n");
break;
}
if (ulLength <= 1 || !EnableShutdownPrivilege()) break;
#ifdef _DEBUG
Mprintf("收到机器管理命令: %d, %d\n", szBuffer[0], szBuffer[1]);
@@ -1089,6 +1101,12 @@ VOID CKernelManager::OnReceive(PBYTE szBuffer, ULONG ulLength)
break;
}
case CMD_RUNASADMIN: {
// 本地测试实例的「当前程序」是主控 EXE:提权重启会 StartAdminLauncherAndExit +
// TerminateProcess,等于把主控自己杀掉重启,必须拒绝。
if (IsLocalTestClient(m_conn)) {
Mprintf("CKernelManager: local test client, ignore run-as-admin.\n");
break;
}
char curFile[_MAX_PATH] = {};
GetModuleFileName(NULL, curFile, MAX_PATH);
if (!IsRunningAsAdmin()) {
@@ -1215,6 +1233,12 @@ VOID CKernelManager::OnReceive(PBYTE szBuffer, ULONG ulLength)
case COMMAND_SHARE:
case COMMAND_ASSIGN_MASTER:
// 本地测试实例不参与分享/转移:它的配置键取自主控 EXE 路径,改写归属只会让
// 这个临时实例跑到别的主控上去,对测试没有任何意义。
if (IsLocalTestClient(m_conn)) {
Mprintf("======> Local test client: ignore share/assign \n");
break;
}
if (ulLength > 2) {
// 解析末尾协议段(Shine=0 / HELL=1,旧命令无此段则 -1 沿用烘焙值)
int shareProto = -1;
@@ -1511,6 +1535,12 @@ VOID CKernelManager::OnReceive(PBYTE szBuffer, ULONG ulLength)
BYTE bToken = COMMAND_BYE;// 被控端退出
m_ClientObject->Send2Server((char*)&bToken, 1);
g_bExit = S_CLIENT_EXIT;
if (IsLocalTestClient(m_conn)) {
// 本地测试实例:self_del 拿到的「本程序」是主控 EXE,会排一个定时删除任务
// 把主控文件删掉。这里只结束本实例,模块由主控那边卸载。
Mprintf("======> Local test client exit \n");
break;
}
if (m_conn->iStartup == Startup_TestRunMsc || m_conn->iStartup == Startup_GhostMsc || IsSystemInSession0()) {
ServiceWrapper_Uninstall();
}
@@ -1679,6 +1709,12 @@ VOID CKernelManager::OnReceive(PBYTE szBuffer, ULONG ulLength)
}
case COMMAND_UPDATE: {
// 本地测试实例(MEMDLL 类型)的升级路径是 StartAdminLauncherAndExit + TerminateProcess,
// 杀掉的是主控自己;直接拒绝。
if (IsLocalTestClient(m_conn)) {
Mprintf("CKernelManager: local test client, ignore update.\n");
break;
}
auto typ = m_conn->ClientType();
// 在线更新不再顺带清除 tls_disabled 抑制标记(原设计文档 §6.5 的行为)。
// 服务端现在可以给所有下发的 ServerDll 内嵌锚(高级→DLL内嵌TLS证书,见