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
69 lines
3.4 KiB
C++
69 lines
3.4 KiB
C++
#pragma once
|
||
//
|
||
// 内嵌服务端 TLS 信任锚块(客户端与服务端共用)—— 见 docs/ClientEmbeddedTLS_Design.md §3.3。
|
||
//
|
||
// 生成客户端时,主控把「服务端自己的 TLS 证书 PEM」写进客户端镜像里的这个块;客户端
|
||
// 启动后拿它当信任锚,于是首次连接就是 TLS,不必等主控在线下发。
|
||
//
|
||
// 为什么单独成块、不扩 CONNECT_ADDRESS:
|
||
// 1. 结构体尾部只有 szFuture[496] 连续可用(前 16 字节已被「运行测试程序」的
|
||
// LOCAL_TEST_CLIENT_MAGIC 占用),而内置证书 PEM 就有 1042 字节;
|
||
// 2. 生成端是按 sizeof(CONNECT_ADDRESS) 做 memcpy 原地覆盖的,扩了结构体就会把新
|
||
// 长度写进老 stub 里,越界且无声(详见设计文档 §3.2 的方案 A 否决理由)。
|
||
//
|
||
// 块与 CONNECT_ADDRESS 走同一条字节搬运路径:生成端扫描 → 原地写入 → 之后才做
|
||
// UPX / ShellCode / 图片伪装。凡 CONNECT_ADDRESS 能活到运行时的包装形态,本块也一定能。
|
||
//
|
||
#include <stddef.h>
|
||
#include <stdint.h>
|
||
#include <string.h>
|
||
|
||
#pragma pack(push, 4)
|
||
struct EmbeddedTlsAnchor {
|
||
char magic[16]; // kAnchorMagic(见 IsAnchorMagic)
|
||
uint32_t version; // kAnchorVersion
|
||
uint32_t capacity; // sizeof(pem):stub 的编译期常量,生成端读它才知道能不能写
|
||
uint32_t length; // 实际写入的 PEM 字节数;0 = 未内嵌
|
||
uint32_t hash; // Fnv1a32(pem[0..length)),半截写入/被改动可立刻识别
|
||
char master[100]; // 生成时配置的主控地址(明文原样,含分号分隔的多地址)
|
||
char pem[4096]; // 证书 PEM(内置自签单张,或用户自备的 fullchain)
|
||
};
|
||
#pragma pack(pop)
|
||
|
||
constexpr uint32_t kAnchorVersion = 1;
|
||
constexpr uint32_t kAnchorCapacity = 4096; // == sizeof(EmbeddedTlsAnchor::pem)
|
||
|
||
// 布局一变,已分发的 stub 就会被生成端读错(capacity 校验会拦住,但别靠它兜底)。
|
||
static_assert(sizeof(EmbeddedTlsAnchor) == 4228, "EmbeddedTlsAnchor 布局变了,见设计文档 §3.3");
|
||
|
||
// FNV-1a 32 位。与 common/iniFile.h 的 GetExeHashStr() 同一算法族(那里是 64 位),
|
||
// 此处取 32 位只为塞进固定宽度的字段。用途是识别「写了一半」与「被改动」,不是安全边界
|
||
// ——锚本身就是公开信息,能改它的人也能改整个文件。
|
||
inline uint32_t Fnv1a32(const char* data, size_t len)
|
||
{
|
||
uint32_t h = 2166136261u;
|
||
for (size_t i = 0; i < len; ++i) {
|
||
h ^= (unsigned char)data[i];
|
||
h *= 16777619u;
|
||
}
|
||
return h;
|
||
}
|
||
|
||
// magic 的字面量在 .rdata 里还会有一份副本(本函数用的常量),所以生成端不能「找到
|
||
// 第一处就写」,必须对每个命中做结构校验——见 IsAnchorBlockValid 与设计文档 §3.3。
|
||
inline bool IsAnchorMagic(const char* p)
|
||
{
|
||
static const char kMagic[16] = { 'Y','A','M','A','_','T','L','S','_','A','N','C','H','O','R','\0' };
|
||
return memcmp(p, kMagic, sizeof(kMagic)) == 0;
|
||
}
|
||
|
||
// 结构校验:magic + version + capacity + hash 全对,才算「这是我们的锚块」。
|
||
inline bool IsAnchorBlockValid(const EmbeddedTlsAnchor& a)
|
||
{
|
||
if (!IsAnchorMagic(a.magic)) return false;
|
||
if (a.version != kAnchorVersion || a.capacity != kAnchorCapacity) return false;
|
||
if (a.length == 0) return a.hash == 0;
|
||
if (a.length > sizeof(a.pem)) return false;
|
||
return a.hash == Fnv1a32(a.pem, a.length);
|
||
}
|