From 7172ab376d1906d2e252ef7b1c4578b8fdb58d16 Mon Sep 17 00:00:00 2001 From: yuanyuanxiang <962914132@qq.com> Date: Sun, 15 Nov 2026 20:26:39 +0100 Subject: [PATCH] Feature: add build_client MCP tool and improve build dialog linkage Add a service-local MCP tool, build_client, that patches a client template with this master's connect settings and writes the binary on the server. It covers ghost/TestRun/ServerDll/TinyRun plus Linux, macOS and Android, reusing the same byte path as CBuildDlg::OnBnClickedOk (CONNECT_ADDRESS overwrite, build-date check, embedded TLS anchor before UPX/padding). ShellCode AES and payload impersonation stay dialog-only. The tool is gated by a new McpBuild switch (default 0) and McpReadonly=0. It refuses to overwrite an existing file unless overwrite=true, protects the server binaries/settings.ini/upx.exe, validates names strictly and uses a unique UPX temp file so it cannot race the dialog. Results report the path, size, target, TLS-anchor status and follow-up tips. In the build dialog, Linux/macOS/Android targets now also grey out the install-location combo/label and run mode, save and restore the Windows compress choice, hide payload/download rows, grey the random-name and run-as-admin menu items, and fix the TLS-anchor label for posix targets. OnBnClickedOk is untouched; generated output is unchanged for every target. New UI strings were added to the en_US, zh_TW and de_DE language packs. McpBuild is off by default and changes require a server restart. Verified on a Debug x64 instance: MCP generation for Linux is patched correctly, Android and ghost anchor/error paths behave, and dialog-driven Linux/TestRun/SC_AES generation still succeeds. mcp/tools.json regenerated (55 tools); check_platform_table.py passes. Co-Authored-By: deepseek-flash --- docs/Mcp_BuildClient_Design.md | 135 +++ docs/Mcp_Design.md | 20 + mcp/tools.json | 232 +++- server/2015Remote/2015RemoteDlg.cpp | 2 + server/2015Remote/2015Remote_vs2015.vcxproj | 2 + .../2015Remote_vs2015.vcxproj.filters | 2 + server/2015Remote/BuildDlg.cpp | 114 +- server/2015Remote/BuildDlg.h | 11 +- server/2015Remote/McpBuildClient.cpp | 1016 +++++++++++++++++ server/2015Remote/McpBuildClient.h | 34 + server/2015Remote/McpInternal.cpp | 3 + server/2015Remote/McpServer.cpp | 22 +- server/2015Remote/McpServer.h | 8 + server/2015Remote/McpSettingsDlg.cpp | 12 + server/2015Remote/McpSettingsDlg.h | 2 + server/2015Remote/lang/de_DE.ini | 3 + server/2015Remote/lang/en_US.ini | 3 + server/2015Remote/lang/zh_TW.ini | 3 + tools/mcp_tools/README.md | 26 +- tools/mcp_tools/make_tools_json.py | 5 + 20 files changed, 1619 insertions(+), 36 deletions(-) create mode 100644 docs/Mcp_BuildClient_Design.md create mode 100644 server/2015Remote/McpBuildClient.cpp create mode 100644 server/2015Remote/McpBuildClient.h diff --git a/docs/Mcp_BuildClient_Design.md b/docs/Mcp_BuildClient_Design.md new file mode 100644 index 0000000..adb5be3 --- /dev/null +++ b/docs/Mcp_BuildClient_Design.md @@ -0,0 +1,135 @@ +# 生成客户端 MCP 工具(build_client)设计 + +> 2026-11-15。让模型把「生成一个连 1.2.3.4:443 的 Linux 客户端」这类需求直接落成 +> 服务端本机上的一个客户端文件。实现在 `server/2015Remote/McpBuildClient.{h,cpp}`。 + +## 1. 定位 + +`build_client` 是**服务端本地工具**,不针对任何在线主机: + +- 入参没有 `id`,平台门禁(`CheckToolPlatform`)因拿不到主机而直接放行; +- `kToolPlatforms` 仍登记为全平台(`win|lnx|mac|apk`),与其它服务端本地工具一致; +- 工具只读模板资源、写服务端本机文件,不向任何客户端下发命令。 + +它复用「生成服务端」对话框(`BuildDlg.cpp::CBuildDlg::OnBnClickedOk`)的字节搬运路径: + +``` +读资源(res 目录优先,回退内嵌) + → 构造 CONNECT_ADDRESS(地址/端口/类型/启动方式/分组/安装目录/主控 ID/pwdHash) + → 模板发布日期校验(模板比主控新则拒绝) + → 原地覆盖所有 FLAG_FINDEN 命中处 + → 内嵌 TLS 信任锚(在 UPX / 增肥之前) + → 落盘 + → 可选 UPX / 增肥 +``` + +对话框专属的 ShellCode AES / PE→ShellCode / 载荷伪装流程(需要额外的载荷文件与 +图片容器)**不在本工具范围内**:传 `compress` 其他值会返回 `-32602` 并提示改用对话框。 + +## 2. 开关与错误码 + +| 条件 | 行为 | +|---|---| +| `McpBuild=1` 且 `McpReadonly=0` | 工具出现在 `tools/list`,可调用 | +| `McpBuild=0` | 不出现;直接调用返回 `-32006` | +| `McpReadonly=1` | 工具出现但调用返回 `-32006`(与 `host_set_remark` / `host_set_watch_level` 这类只改服务端本地数据的工具一致:列出、调用时拒绝) | + +`McpBuild` 默认 `0`,改动需重启服务端生效。之所以不复用 `McpManage` / `McpFileWrite`: +生成的是**带主控凭据、可分发的客户端二进制**,风险等级与「操作在线主机」不同,需要能 +单独关掉。工具同时要求只读模式关闭。 + +参数错误统一 `-32602`;文件已存在且 `overwrite=false`、输出路径是目录返回 `-32012`; +模板缺失 / 模板比主控新 / 找不到 `CONNECT_ADDRESS` / 写盘或 UPX 失败返回 `-32001`。 + +## 3. 参数 + +| 参数 | 必填 | 说明 | +|---|---|---| +| `target` | 是 | `ghost` / `ghost_service` / `ghost_system` / `testrun_dll` / `testrun_memdll` / `testrun_injsc` / `testrun_service` / `testrun_system` / `serverdll` / `tinyrun` / `linux` / `macos` / `android` | +| `arch` | 否 | `x64`(默认)/ `x86`;posix 固定架构,传 `x86` 返回 `-32602`;`testrun_injsc` 只支持 x64 | +| `host` | 否 | 主控地址,可含分号分隔的多地址;省略取服务端当前有效主控地址(含上级 FRP) | +| `port` | 否 | 省略取服务端当前有效端口 | +| `protocol` | 否 | `tcp`(默认)/ `udp` / `http` / `random` / `kcp` / `ws` / `wss` | +| `header_enc` | 否 | `hell`(默认)/ `shine` | +| `running` | 否 | `random`(默认)/ `parallel` | +| `group` | 否 | 分组名,≤23 字节 ANSI | +| `install_location` | 否 | `programdata`(默认)/ `programfiles` / `systemroot` / `appdata` / `localappdata` | +| `install_dir` / `install_name` | 否 | Windows 安装子目录/程序名,≤31 字节,按 Windows 文件名规则校验 | +| `run_as_admin` | 否 | 默认 `false`;安装 Windows 服务时通常需要 | +| `encrypt_address` | 否 | 默认 `true`;`testrun_injsc` 与 `tinyrun` 与对话框一致,不加密 | +| `compress` | 否 | `none`(默认)/ `upx`;仅 Windows 目标 | +| `tls_anchor` | 否 | 默认 `true`;见 §4 | +| `padding_mb` | 否 | 0–256,仅 Windows 目标 | +| `output_dir` | 否 | 默认主控程序目录;不存在会自动创建 | +| `output_name` | 否 | 默认按 target 取 `ghost.exe` / `TestRun.exe` / `ServerDll.dll` / `TinyRun.dll` / `ghost` / `ghost.apk` | +| `overwrite` | 否 | 默认 `false`;目标已存在时返回 `-32012`,确认后传 `true` 重试 | + +字符串入参按 UTF-8 接收,落到 ANSI 结构体/路径前用 `Utf8ToCpExact` 严格转换; +服务端代码页表示不了的字符直接拒绝,不用 `?` 顶替(否则会写出路径或分组名都不对的 +客户端)。 + +## 4. 内嵌 TLS 信任锚 + +只有 `ghost` / `ghost_service` / `ghost_system` / `serverdll` 的 Windows 模板里有 +`EmbeddedTlsAnchor` 块(`client/EmbeddedTlsAnchor.cpp`)。工具按以下顺序判定, +结果写入 `tlsAnchor`: + +| 状态 | 含义 | +|---|---| +| `disabled` | 入参 `tls_anchor=false` | +| `not_applicable` | TestRun / TinyRun:模板不含客户端代码(TestRun 的锚要生成进 ServerDll.dll) | +| `unsupported_platform` | Linux / macOS / Android 模板没有锚块,信任锚由主控在线下发 | +| `skipped_protocol` | 协议不是 tcp/http(ws/wss 的锚是反代那张证书) | +| `unavailable` | 服务端未启用可用 TLS 身份 | +| `no_block` | 模板里没有锚块(资源未重编),按普通客户端生成,不视为失败 | +| `embedded` | 已写入;`tlsAnchorSummary` 给出证书摘要 | + +与对话框一致:`Ambiguous` / `TooLong` / `NoAnchor` 会中止生成(`-32001`), +`NoBlock` 只提示;锚必须在 UPX / 增肥之前写入。 + +## 5. 其它行为 + +- **版本校验**:模板 `szBuildDate` 比主控 `DLL_VERSION` 新时拒绝生成。 +- **输出覆盖**:默认拒绝覆盖;`overwrite=true` 时才写。输出文件名不允许包含目录分隔符。 +- **并发**:模块内用 `std::mutex` 串行化。`ReleaseUPX()` 固定把 `upx.exe` 释放到服务端 + 目录,两个并发生成会互相踩;串行化同时避免同一输出文件的写竞争。 +- **审计**:每次成功/失败写一行 `[MCP] build_client ...` 到服务端日志(路径、目标、字节数)。 +- **结果 tips**:KCP 需要主控 UDP 参数为 1、WS/WSS 需要反代、macOS 需 `install.sh`/codesign、 + Android 需 apksigner、TestRun 需要 ServerDll.dll、锚未内嵌等。 +- **UPX 失败**:返回 `-32001`,未压缩的文件保留在原路径(与对话框一致)。 + +## 6. 「生成服务端」对话框的联动改进 + +同一批改动还修了对话框里几个平台联动问题(`BuildDlg.cpp`): + +1. 选 Linux / macOS / Android 时,「安装目录」下拉框(`IDC_COMBO_INSTALL_LOC`)及其 + 标签(`IDC_STATIC_LOCATION`)现在与安装目录/程序名一起置灰。此前它们不在禁用清单里, + 看起来仍可设置,但生成时根本不会被使用。 +2. 运行模式(`IDC_COMBO_RUNTYPE`)对非 Windows 客户端无意义(`runningType` 只有 + Windows `ClientDll` 消费),一并置灰。 +3. 加壳选择切到非 Windows 目标时暂存并显示「无」,切回 Windows 时恢复;避免 + 「控件置灰但显示 ShellCode AES」与实际生成结果(强制 NONE)不一致。 +4. 载荷类型 / 下载服务几行在非 Windows 目标下隐藏,而不是留下置灰的空行。 +5. 「随机名称」「以管理员权限运行」两个菜单项在非 Windows 目标下置灰。 +6. 内嵌 TLS 锚复选框的文案对 Linux/macOS/Android 改为「仅Windows客户端模板支持」, + 不再误报「该目标不含客户端」。 + +## 7. 验收记录(2026-11-15,Debug 实例) + +- `tools/list` 出现 `build_client`(`McpBuild=1`),关闭开关时不出现、直接调用 `-32006`。 +- Linux:生成 10,285,456 字节,`tlsAnchor=unsupported_platform`;`encrypt_address=false` + 时二进制里能检索到明文 host/port/分组/安装目录,原 `FLAG_FINDEN` 命中数归零。 +- ghost x64:`tlsAnchor=embedded`;生成的 PE 被本机 Defender 隔离,属测试环境现象。 +- Android:生成 11,929,218 字节,`tlsAnchor=unsupported_platform`,tips 提示重签。 +- `arch=x86` + Linux、`testrun_injsc` + x86、未知 target、非字符串 target、显式但解析不出 + 的 `port`(如 `"443 "`)均返回 `-32602`;同名文件不传 `overwrite` 返回 `-32012`, + 传 `true` 后 `overwritten=true`。 +- 保护主控自身文件:`output_dir=Bin` + `output_name=Yama_x64d.exe` + `overwrite=true` + 返回 `-32012`,不会覆盖运行中的服务端;`settings.ini` / `upx.exe` 同样受保护。 +- 省略 `group` 时与对话框一致写入 `default`;`protocol` 允许数字形式(5 → ws)。 +- `padding_mb=3` 的 TinyRun 产物比模板大 3 MB(分块追加,不一次性分配 256 MB); + `compress=upx` 因 Defender 拒绝读取生成的 PE 而返回 `-32001`(UPX 自身报 + `IOException: Invalid argument`),错误路径符合预期;UPX 临时文件按 + `upx_mcp__.exe` 释放,测后无残留,也不会与对话框的固定 `upx.exe` 抢文件。 +- `mcp/tools.json` 已用 Debug 实例的 `McpMachine=1` / `McpMachine=0` 两份抓取重新生成 + (55 个工具),`check_platform_table.py` PASS。 diff --git a/docs/Mcp_Design.md b/docs/Mcp_Design.md index 7110661..1c9a2fb 100644 --- a/docs/Mcp_Design.md +++ b/docs/Mcp_Design.md @@ -263,6 +263,7 @@ Json::Value BuildHostJson(context* ctx, _ClientList* clientMap); | `McpBind` | `127.0.0.1` | 监听地址;默认仅本机;可设 `0.0.0.0`(所有网卡)或内网 IP(如 `192.168.0.92`)以支持远程 | | `McpToken` | 空(UI 默认随机值) | 静态 token;对话框内「token 必填、默认随机值」——首次打开若为空则预填随机并随保存持久化。运行时优先级:env `YAMA_MCP_TOKEN` → `McpToken` → 皆空则随机生成(见 §3.5) | | `McpKeylog` | `0` | 键盘记录工具 `get_keylog` 的独立开关(见 §9.3);与 `McpReadonly` 无关,改动需重启生效 | +| `McpBuild` | `0` | 生成客户端工具 `build_client` 的独立开关(见 §25);另要求 `McpReadonly=0`,改动需重启生效 | | `McpToolTimeoutMs` | `20000` | 工具等待客户端响应的默认超时(ms),clamp 到 `[1000, 600000]`;各工具自己的 `timeout_ms` 参数优先。**ini-only**(无设置界面控件),改动需重启生效 | | `McpHttps` | `0` | `1` = 对外端口说 HTTPS(native TLS,见 §13),httplib 退到 `127.0.0.1:McpInternalPort`;`0` = 保持明文。经「MCP设置」对话框的「启用 HTTPS」复选框设置,改动需重启生效 | | `McpCertPath` | 空(回退 `[tls] CertPath`) | MCP 专用证书(PEM)。面向公网客户端时应为公共 CA 证书(如 Let's Encrypt 的 `fullchain.pem`),不要复用设备端口的自签证书。对话框「证书路径」行可填/浏览;为空时按回退规则预填 `[tls]` 的值 | @@ -1352,3 +1353,22 @@ macOS 客户端此前有大量「实现了但服务端不认」的功能,断 - `remote_open` 仍拒绝 `MAC`(屏幕/注入链路的 macOS 实机验证还没做),本批不动。 - `mcp/tools.json` 是生成物(`tools/mcp_tools/`),平台表变更后要用跑起来的服务端 重新生成。 + +## 25. 增补(2026-11-15:生成客户端工具 `build_client`) + +服务端本地工具:按本主控的上线配置 patch 客户端模板(ghost / TestRun / ServerDll / +TinyRun / Linux / macOS / Android)并落盘,不针对任何在线主机。入参没有 `id`,平台 +门禁直接放行;`kToolPlatforms` 登记为全平台。 + +- 独立开关 `McpBuild`(默认 `0`),并额外要求 `McpReadonly=0`。它写出的是带主控 + 凭据、可分发的客户端二进制,风险等级与「操作在线主机」不同,因此不复用 + `McpManage` / `McpFileWrite`。 +- 与「生成服务端」对话框共用同一套字节搬运路径:CONNECT_ADDRESS 原地覆盖、版本日期 + 校验、内嵌 TLS 锚(在 UPX / 增肥之前)。ShellCode AES / PE→ShellCode / 载荷伪装 + 仍只能在对话框里做。 +- 默认拒绝覆盖同名文件(`overwrite=true` 才覆盖);默认 `encrypt_address=true`, + `testrun_injsc` / `tinyrun` 与对话框一致不加密。 +- 生成逻辑在 `server/2015Remote/McpBuildClient.{h,cpp}`;完整参数、TLS 锚状态表、 + 错误码、对话框联动改进与验收记录见 `docs/Mcp_BuildClient_Design.md`。 +- 同批改动:选 Linux/macOS/Android 时「安装目录」下拉框/标签、运行模式一并置灰, + 载荷/下载服务行隐藏,随机名称/管理员权限菜单项置灰(`BuildDlg.cpp`)。 diff --git a/mcp/tools.json b/mcp/tools.json index 9a2b1a1..35ace51 100644 --- a/mcp/tools.json +++ b/mcp/tools.json @@ -18,7 +18,7 @@ ], "version": 2, "protocolVersion": "2025-06-18", - "toolCount": 54, + "toolCount": 55, "tools": [ { "name": "list_hosts", @@ -1207,7 +1207,7 @@ }, { "name": "get_server_status", - "description": "获取 YAMA 服务端自身的状态:程序版本与 exe 构建时间、进程已运行秒数、MCP 监听地址与端口、各功能开关(只读/终端/远程控制/文件传输/管理/主机管理/高风险操作/键盘记录/远程交谈)、在线与离线主机数、各类在飞会话数、当前被封禁的来源 IP 数。只读、纯内存,不返回 token。", + "description": "获取 YAMA 服务端自身的状态:程序版本与 exe 构建时间、进程已运行秒数、MCP 监听地址与端口、各功能开关(只读/终端/远程控制/文件传输/文件写入/管理/主机管理/高风险操作/键盘记录/远程交谈/生成客户端)、在线与离线主机数、各类在飞会话数、当前被封禁的来源 IP 数。只读、纯内存,不返回 token。", "gate": null, "platforms": [ "win", @@ -4995,6 +4995,234 @@ "type": "object" } }, + { + "name": "build_client", + "description": "在服务端本机生成一个客户端文件(按本主控的上线配置 patch 客户端模板后落盘)。这不会修改任何在线主机,也不依赖在线主机;生成目标是模板类型而不是某台设备。支持 Windows(ghost 单文件/服务/SYSTEM、TestRun 加载器、ServerDll.dll、TinyRun.dll)、Linux、macOS 与 Android。生成地址默认取服务端当前有效主控地址(含上级 FRP 配置),也可显式传 host/port。默认会在客户端模板存在内嵌 TLS 锚块且协议为 tcp/http 时写入服务端当前证书(首连即 TLS),其余目标如实标注 tlsAnchor 状态。输出目录默认主控程序目录,已存在同名文件时默认拒绝(传 overwrite=true 才覆盖)。Windows 目标可选 upx 压缩与 padding_mb 增肥;ShellCode AES / PE→ShellCode 等需要载荷文件的模式只能用生成对话框。需服务端开启 McpBuild 且关闭只读模式。生成后可把 path 交给用户;Windows/Linux/macOS 主机可用 upload_file 送达(文件格式需与目标平台匹配),Android 需用户自行安装。", + "gate": "build", + "write": true, + "platforms": [ + "win", + "lnx", + "mac", + "apk" + ], + "impl": "mfc", + "inputSchema": { + "properties": { + "arch": { + "description": "Windows 目标架构,默认 x64;x86 对 testrun_injsc 与 linux/macos/android 无效(会被拒绝)。", + "enum": [ + "x64", + "x86" + ], + "type": "string" + }, + "compress": { + "description": "压缩方式,默认 none;upx 仅 Windows 目标支持。ShellCode AES / PE→ShellCode 等需要载荷文件,只能在生成对话框里操作。", + "enum": [ + "none", + "upx" + ], + "type": "string" + }, + "encrypt_address": { + "description": "是否加密写进客户端的 CONNECT_ADDRESS(地址/端口),默认 true。testrun_injsc 与 tinyrun 与对话框一致,不加密。", + "type": "boolean" + }, + "group": { + "description": "分组名称,最长 23 字节(ANSI)。省略时与对话框一致使用 default。", + "type": "string" + }, + "header_enc": { + "description": "包头加密方式,默认 hell。", + "enum": [ + "shine", + "hell" + ], + "type": "string" + }, + "host": { + "description": "主控地址,可写分号分隔的多个地址(客户端随机选择)。省略时使用服务端当前有效主控地址(含上级 FRP 配置);两者都为空则报错。最长 99 字符。", + "type": "string" + }, + "install_dir": { + "description": "Windows 安装子目录名,最长 31 字节,不能含 \\ / : * ? \" < > |。", + "type": "string" + }, + "install_location": { + "description": "Windows 安装位置,默认 programdata。仅 Windows 目标有效。", + "enum": [ + "programdata", + "programfiles", + "systemroot", + "appdata", + "localappdata" + ], + "type": "string" + }, + "install_name": { + "description": "Windows 安装程序名,最长 31 字节,不能含 \\ / : * ? \" < > |。", + "type": "string" + }, + "output_dir": { + "description": "输出目录(服务端本机路径),默认主控程序所在目录;不存在会自动创建。", + "type": "string" + }, + "output_name": { + "description": "输出文件名(仅文件名,不含目录),默认按 target 取 ghost.exe / TestRun.exe / ServerDll.dll / TinyRun.dll / ghost / ghost.apk。", + "type": "string" + }, + "overwrite": { + "description": "目标文件已存在时是否覆盖,默认 false。为 false 时返回 -32012,确认覆盖后再传 true 重试。", + "type": "boolean" + }, + "padding_mb": { + "description": "程序增肥的追加字节数(MB),默认 0;仅 Windows 目标支持。", + "maximum": 256, + "minimum": 0, + "type": "integer" + }, + "port": { + "description": "主控端口,省略时使用服务端当前有效端口。", + "maximum": 65535, + "minimum": 1, + "type": "integer" + }, + "protocol": { + "description": "传输协议,默认 tcp。ws/wss 需反向代理(如 nginx 443)转发到主控端口;kcp 需要主控 UDP 协议参数为 1。", + "enum": [ + "tcp", + "udp", + "http", + "random", + "kcp", + "ws", + "wss" + ], + "type": "string" + }, + "run_as_admin": { + "description": "生成的 Windows 客户端是否请求管理员权限运行,默认 false;安装 Windows 服务时通常需要 true。", + "type": "boolean" + }, + "running": { + "description": "上线方式,默认 random(随机上线)。", + "enum": [ + "random", + "parallel" + ], + "type": "string" + }, + "target": { + "description": "生成目标:ghost(Windows 单文件 EXE)、ghost_service(Windows 服务)、ghost_system(SYSTEM 权限)、testrun_dll / testrun_memdll / testrun_injsc / testrun_service / testrun_system(TestRun 加载器)、serverdll、tinyrun、linux、macos、android。前十个是 Windows 目标;linux/macos/android 为固定架构的预编译 template,arch=x86 与 Windows 专属的 compress/padding 会被拒绝,安装目录相关参数不参与生成。", + "enum": [ + "testrun_dll", + "testrun_memdll", + "testrun_injsc", + "testrun_service", + "testrun_system", + "ghost", + "ghost_service", + "ghost_system", + "serverdll", + "tinyrun", + "linux", + "macos", + "android" + ], + "type": "string" + }, + "tls_anchor": { + "description": "是否把服务端当前 TLS 证书作为信任锚写进客户端(首连即 TLS),默认 true。仅 ghost / ghost_service / ghost_system / serverdll 模板有锚块,且协议为 tcp/http;其余目标会如实标注为未内嵌,不视为失败。", + "type": "boolean" + } + }, + "required": [ + "target" + ], + "type": "object" + }, + "outputSchema": { + "properties": { + "arch": { + "description": "实际架构:x64 / x86;posix 目标为 native。", + "type": "string" + }, + "bytes": { + "description": "最终文件字节数。", + "minimum": 0, + "type": "integer" + }, + "clientType": { + "description": "客户端类型:EXE / DLL / MDLL / SC / LNX / MAC / APK。", + "type": "string" + }, + "host": { + "description": "写入客户端的主控地址。", + "type": "string" + }, + "name": { + "description": "输出文件名。", + "type": "string" + }, + "ok": { + "description": "是否成功;失败时本工具返回 JSON-RPC error。", + "type": "boolean" + }, + "overwritten": { + "description": "是否覆盖了已存在的同名文件。", + "type": "boolean" + }, + "path": { + "description": "生成文件的绝对路径(服务端本机)。", + "type": "string" + }, + "port": { + "description": "写入客户端的主控端口。", + "maximum": 65535, + "minimum": 1, + "type": "integer" + }, + "protocol": { + "description": "写入客户端的传输协议。", + "type": "string" + }, + "target": { + "description": "生成目标(与入参 target 一致)。", + "type": "string" + }, + "targetLabel": { + "description": "生成目标的中文名,如「ghost.exe - Windows 服务」。", + "type": "string" + }, + "tips": { + "description": "生成后需要注意的事项(KCP/WS 端口、macOS/Android 重签、锚未内嵌等)。", + "items": { + "type": "string" + }, + "type": "array" + }, + "tlsAnchor": { + "description": "内嵌 TLS 信任锚状态:embedded(已内嵌)/ disabled(未请求)/ not_applicable(该目标模板不含客户端代码)/ unsupported_platform(Linux/macOS/Android 模板没有锚块)/ skipped_protocol(该协议不走设备端口 TLS)/ unavailable(服务端未启用TLS)/ no_block(模板里没有锚块,已按普通客户端生成)。", + "enum": [ + "embedded", + "disabled", + "not_applicable", + "unsupported_platform", + "skipped_protocol", + "unavailable", + "no_block" + ], + "type": "string" + }, + "tlsAnchorSummary": { + "description": "内嵌成功时的证书摘要(如 builtin 2036-11-01 sha1:...)。", + "type": "string" + } + }, + "type": "object" + } + }, { "name": "list_processes", "description": "获取指定在线主机的进程列表(PID、映像名称、架构、程序完整路径)。通过主连接下发命令、子连接回传,一次性返回。可选 name(映像名子串,ASCII 不区分大小写)/ pid(精确)在服务端过滤,过滤在分页之前生效:total 为命中数、totalAll 为过滤前的总数。结果按 limit/offset 分页。仅在 McpMachine=0(主机管理工具关闭)时出现——那是本服务端唯一能列进程的路径;开启主机管理后改用 host_inspect 的 processes 项(字段更全、支持 arch 过滤)。", diff --git a/server/2015Remote/2015RemoteDlg.cpp b/server/2015Remote/2015RemoteDlg.cpp index a1bef7e..118b520 100644 --- a/server/2015Remote/2015RemoteDlg.cpp +++ b/server/2015Remote/2015RemoteDlg.cpp @@ -2580,6 +2580,8 @@ BOOL CMy2015RemoteDlg::OnInitDialog() McpServer().SetChatEnabled(THIS_CFG.GetInt("settings", "McpChat", 0) != 0); // N3 键盘记录(get_keylog):独立开关默认关,与只读开关无关。 McpServer().SetKeylogEnabled(THIS_CFG.GetInt("settings", "McpKeylog", 0) != 0); + // 生成客户端(build_client):独立开关默认关;写客户端二进制,要求只读关。 + McpServer().SetBuildEnabled(THIS_CFG.GetInt("settings", "McpBuild", 0) != 0); // 平台门禁:默认开。调用前拦掉目标客户端根本没实现的工具(立刻 -32005), // 否则会照常下发命令然后白等超时。关掉它只影响这道拦截,不改任何工具的执行路径。 McpServer().SetPlatformGuardEnabled( diff --git a/server/2015Remote/2015Remote_vs2015.vcxproj b/server/2015Remote/2015Remote_vs2015.vcxproj index e5c86d2..b8dfe4f 100644 --- a/server/2015Remote/2015Remote_vs2015.vcxproj +++ b/server/2015Remote/2015Remote_vs2015.vcxproj @@ -330,6 +330,7 @@ + @@ -403,6 +404,7 @@ + diff --git a/server/2015Remote/2015Remote_vs2015.vcxproj.filters b/server/2015Remote/2015Remote_vs2015.vcxproj.filters index 3648366..f2038a3 100644 --- a/server/2015Remote/2015Remote_vs2015.vcxproj.filters +++ b/server/2015Remote/2015Remote_vs2015.vcxproj.filters @@ -92,6 +92,7 @@ + @@ -210,6 +211,7 @@ + diff --git a/server/2015Remote/BuildDlg.cpp b/server/2015Remote/BuildDlg.cpp index 6d5079d..68c7d53 100644 --- a/server/2015Remote/BuildDlg.cpp +++ b/server/2015Remote/BuildDlg.cpp @@ -47,6 +47,12 @@ enum Payload { Payload_PDF, }; +// Linux / macOS / Android 是固定架构的预编译模板,没有 Windows 的安装/加壳/增肥语义。 +static bool IsWindowsTarget(int index) +{ + return !(index == IndexLinuxGhost || index == IndexMacGhost || index == IndexAndroidGhost); +} + // CBuildDlg 对话框 IMPLEMENT_DYNAMIC(CBuildDlg, CDialog) @@ -223,9 +229,9 @@ CBuildDlg::CBuildDlg(CWnd* pParent) , m_sInstallDir(_T("")) , m_sInstallName(_T("")) , m_sDownloadUrl(_T("")) + , m_nWindowsCompress(CLIENT_COMPRESS_SC_AES_OLD) , m_nAnchorUserCheck(-1) { - } CBuildDlg::~CBuildDlg() @@ -904,6 +910,7 @@ BOOL CBuildDlg::OnInitDialog() m_ComboCompress.InsertStringL(CLIENT_SHELLCODE_BINARY, "ShellCode BIN"); m_ComboCompress.InsertStringL(CLIENT_COMP_SC_AES_OLD_UPX, "SC AES + UPX"); m_ComboCompress.SetCurSel(CLIENT_COMPRESS_SC_AES_OLD); + m_nWindowsCompress = m_ComboCompress.GetCurSel(); // 与上面的默认值保持一致 m_ComboLocation.InsertStringL(0, "ProgramData"); m_ComboLocation.InsertStringL(1, "ProgramFiles - Admin"); @@ -995,10 +1002,12 @@ CString CBuildDlg::GetFilePath(CString type, CString filter, BOOL isOpen) return ""; } -// 选 Linux / macOS 客户端时禁用对它们不适用的 Windows-only 选项: -// - 架构 (m_ComboBits):Linux/macOS binary 是固定架构的预编译资源 +// 选 Linux / macOS / Android 客户端时禁用对它们不适用的 Windows-only 选项: +// - 架构 (m_ComboBits):这些 binary 是固定架构的预编译资源 // - 加壳 (m_ComboCompress):UPX / ShellCode AES 等都是 Windows PE 概念 -// - 高级 group:安装目录 / 程序名称 / 载荷类型 / 增肥 / 下载服务,全是 Windows 安装/伪装相关 +// - 运行模式 (m_ComboRunType):runningType 只有 Windows 客户端(ClientDll)消费 +// - 高级 group:安装位置 / 安装目录 / 程序名称 / 载荷类型 / 增肥 / 下载服务, +// 全是 Windows 安装/伪装相关 void CBuildDlg::EnableWindowsOnlyControls(BOOL enable) { static const int ids[] = { @@ -1006,8 +1015,11 @@ void CBuildDlg::EnableWindowsOnlyControls(BOOL enable) IDC_COMBO_BITS, IDC_STATIC_BUILD_ARCH, // 加壳 IDC_COMBO_COMPRESS, IDC_STATIC_BUILD_PACK, - // 高级 group + 内部所有控件 + // 运行模式 + IDC_COMBO_RUNTYPE, IDC_STATIC_BUILD_MODE, + // 高级 group + 内部所有控件(含「安装目录」下拉框与它的标签) IDC_STATIC_BUILD_ADVANCED, + IDC_STATIC_LOCATION, IDC_COMBO_INSTALL_LOC, IDC_STATIC_PAYLOAD, IDC_STATIC_PAYLOAD2, IDC_STATIC_PAYLOAD3, IDC_STATIC_BUILD_PADDING, IDC_STATIC_DOWNLOAD, IDC_EDIT_INSTALL_DIR, IDC_EDIT_INSTALL_NAME, @@ -1019,6 +1031,41 @@ void CBuildDlg::EnableWindowsOnlyControls(BOOL enable) } } +// 载荷类型 / 下载服务几行的可见性。非 Windows 目标一律隐藏:这些控件虽然已经被 +// EnableWindowsOnlyControls 置灰,但「置灰却还占着版面」会让人以为它们仍会生效。 +void CBuildDlg::UpdatePayloadControls() +{ + const int index = m_ComboExe.GetCurSel(); + if (!IsWindowsTarget(index)) { + m_ComboPayload.ShowWindow(SW_HIDE); + m_StaticPayload.ShowWindow(SW_HIDE); + m_BtnFileServer.ShowWindow(SW_HIDE); + m_StaticDownload.ShowWindow(SW_HIDE); + m_EditDownloadUrl.ShowWindow(SW_HIDE); + return; + } + + const bool scAes = m_ComboCompress.GetCurSel() == CLIENT_COMPRESS_SC_AES; + m_ComboPayload.ShowWindow(scAes ? SW_SHOW : SW_HIDE); + m_StaticPayload.ShowWindow(scAes ? SW_SHOW : SW_HIDE); + + const bool fileServer = scAes && m_ComboPayload.GetCurSel() > Payload_Self; + m_BtnFileServer.ShowWindow(fileServer ? SW_SHOW : SW_HIDE); + const bool downloading = fileServer && m_BtnFileServer.GetCheck() == BST_CHECKED; + m_StaticDownload.ShowWindow(downloading ? SW_SHOW : SW_HIDE); + m_EditDownloadUrl.ShowWindow(downloading ? SW_SHOW : SW_HIDE); +} + +// 菜单项联动:随机名称只影响安装目录/程序名,以管理员权限运行只有 Windows 客户端消费。 +void CBuildDlg::UpdateTargetMenuState(BOOL windowsTarget) +{ + CMenu* sub = m_MainMenu.GetSubMenu(0); + if (!sub || !GetSafeHwnd()) return; + sub->EnableMenuItem(ID_RANDOM_NAME, windowsTarget ? MF_ENABLED : MF_GRAYED); + sub->EnableMenuItem(ID_CLIENT_RUNAS_ADMIN, windowsTarget ? MF_ENABLED : MF_GRAYED); + ::DrawMenuBar(GetSafeHwnd()); +} + // 「内嵌 TLS 信任锚」复选框的可用性与文案。三个条件缺一不可(设计文档 §4.7): // 1. 生成目标里真的有客户端代码(ghost.exe / ServerDll.dll); // 2. 协议会用到这份锚(TCP / HTTP;WS 走明文,WSS 的锚是反代那张证书); @@ -1036,13 +1083,22 @@ void CBuildDlg::UpdateTlsAnchorState() const bool testRun = (index == IndexTestRun_DLL || index == IndexTestRun_MemDLL || index == IndexTestRun_InjSC || index == IndexTestRunMsc || index == IndexTestRunSystem); + // Linux/macOS/Android 模板里没有锚块(只有 Windows 的 client/ 侧编译了 + // common/tls_anchor.h),它们的信任锚由主控在线下发;文案要说清这一点, + // 不能笼统写成「不含客户端」。 + const bool posixTarget = (index == IndexLinuxGhost || index == IndexMacGhost || + index == IndexAndroidGhost); CString label; bool usable = false; if (!embeddable) { // TestRun 只是加载器,锚要生成进 ServerDll.dll —— 这条提示比「不含客户端」有用。 - label = testRun ? _TR("内嵌TLS信任锚(锚在ServerDll.dll里)") - : _TR("内嵌TLS信任锚(该目标不含客户端)"); + if (testRun) + label = _TR("内嵌TLS信任锚(锚在ServerDll.dll里)"); + else if (posixTarget) + label = _TR("内嵌TLS信任锚(仅Windows客户端模板支持)"); + else + label = _TR("内嵌TLS信任锚(该目标不含客户端)"); } else if (proto != PROTO_TCP && proto != PROTO_HTTP) { label = _TR("内嵌TLS信任锚(该协议不走TLS)"); } else if (!ServerTlsIdentity::IsReady()) { @@ -1078,9 +1134,31 @@ void CBuildDlg::OnCbnSelchangeComboProto() void CBuildDlg::OnCbnSelchangeComboExe() { - auto n = m_ComboExe.GetCurSel(); - EnableWindowsOnlyControls(!(n == IndexLinuxGhost || n == IndexMacGhost || n == IndexAndroidGhost)); + const int n = m_ComboExe.GetCurSel(); + const BOOL windowsTarget = IsWindowsTarget(n); + + EnableWindowsOnlyControls(windowsTarget); UpdateTlsAnchorState(); + + // 加壳:非 Windows 目标切到「无」并记住 Windows 下的选择,切回时恢复。否则控件 + // 已置灰却还显示「ShellCode AES」,会让人以为生成时仍按它处理(生成代码其实会强制 + // 改成 NONE,界面和实际行为对不上)。 + if (!windowsTarget) { + const int cur = m_ComboCompress.GetCurSel(); + if (cur != CLIENT_COMPRESS_NONE) { + m_nWindowsCompress = cur; + m_ComboCompress.SetCurSel(CLIENT_COMPRESS_NONE); + } + } else { + if (m_ComboCompress.GetCurSel() == CLIENT_COMPRESS_NONE && + m_nWindowsCompress != CLIENT_COMPRESS_NONE) { + m_ComboCompress.SetCurSel(m_nWindowsCompress); + } + m_nWindowsCompress = m_ComboCompress.GetCurSel(); + } + UpdateTargetMenuState(windowsTarget); + UpdatePayloadControls(); + if (n == OTHER_ITEM) { CString name = GetFilePath(_T("dll"), _T("All Files (*.*)|*.*|DLL Files (*.dll)|*.dll|EXE Files (*.exe)|*.exe|")); if (!name.IsEmpty()) { @@ -1150,14 +1228,13 @@ void CBuildDlg::OnClientRunasAdmin() void CBuildDlg::OnCbnSelchangeComboCompress() { - m_ComboPayload.ShowWindow(m_ComboCompress.GetCurSel() == CLIENT_COMPRESS_SC_AES ? SW_SHOW : SW_HIDE); - m_StaticPayload.ShowWindow(m_ComboCompress.GetCurSel() == CLIENT_COMPRESS_SC_AES ? SW_SHOW : SW_HIDE); - m_ComboPayload.SetFocus(); - m_BtnFileServer.ShowWindow( - m_ComboCompress.GetCurSel() == CLIENT_COMPRESS_SC_AES && m_ComboPayload.GetCurSel() ? SW_SHOW : SW_HIDE); + // 记下用户在当前 Windows 目标下的加壳选择;切到 Linux/macOS/Android 时控件会置灰、 + // 显示值切到「无」,切回来时恢复这个值。 + if (IsWindowsTarget(m_ComboExe.GetCurSel())) + m_nWindowsCompress = m_ComboCompress.GetCurSel(); m_BtnFileServer.SetCheck(BST_UNCHECKED); - m_StaticDownload.ShowWindow(SW_HIDE); - m_EditDownloadUrl.ShowWindow(SW_HIDE); + UpdatePayloadControls(); + m_ComboPayload.SetFocus(); static bool warned = false; if (m_ComboCompress.GetCurSel() == CLIENT_COMPRESS_SC_AES && !warned) { warned = true; @@ -1313,9 +1390,6 @@ void CBuildDlg::OnBnClickedCheckFileserver() void CBuildDlg::OnCbnSelchangeComboPayload() { - m_BtnFileServer.ShowWindow( - m_ComboCompress.GetCurSel() == CLIENT_COMPRESS_SC_AES && m_ComboPayload.GetCurSel() ? SW_SHOW : SW_HIDE); m_BtnFileServer.SetCheck(BST_UNCHECKED); - m_StaticDownload.ShowWindow(SW_HIDE); - m_EditDownloadUrl.ShowWindow(SW_HIDE); + UpdatePayloadControls(); } diff --git a/server/2015Remote/BuildDlg.h b/server/2015Remote/BuildDlg.h index 4c1df22..3a54e49 100644 --- a/server/2015Remote/BuildDlg.h +++ b/server/2015Remote/BuildDlg.h @@ -17,7 +17,8 @@ namespace ResFileName { extern const char* GHOST_X86; extern const char* GHOST_X64; extern const char* GHOST_LINUX; - extern const char* GHOST_MACOS; // 预留 + extern const char* GHOST_MACOS; + extern const char* GHOST_ANDROID; // TestRun 加载器 extern const char* TESTRUN_X86; extern const char* TESTRUN_X64; @@ -109,6 +110,14 @@ public: void EnableWindowsOnlyControls(BOOL enable); CComboBox m_ComboLocation; + // 载荷/下载服务几行的可见性(由「目标是否 Windows」+「加壳方式」+「载荷类型」共同决定) + void UpdatePayloadControls(); + // 菜单项联动:随机名称 / 以管理员权限运行只对 Windows 目标有意义 + void UpdateTargetMenuState(BOOL windowsTarget); + // 非 Windows 目标期间暂存的加壳选择:控件置灰后仍显示旧值会让人误以为会按它生成, + // 所以切到 Linux/macOS/Android 时先切到「无」,切回 Windows 时恢复。 + int m_nWindowsCompress; + // 内嵌服务端 TLS 信任锚(动态创建:不改 .rc,避免 GBK 资源文件的字节级编辑)。 // 可用性三条件见 UpdateTlsAnchorState;生成时由 OnBnClickedOk 调用 EmbedTlsAnchorInto。 CButton m_ChkTlsAnchor; diff --git a/server/2015Remote/McpBuildClient.cpp b/server/2015Remote/McpBuildClient.cpp new file mode 100644 index 0000000..dd8d58c --- /dev/null +++ b/server/2015Remote/McpBuildClient.cpp @@ -0,0 +1,1016 @@ +// McpBuildClient.cpp : 「生成客户端」MCP 工具(build_client)的实现 +// +// 目标:让模型把「给我生成一个连 1.2.3.4:443 的 Linux 客户端」这类需求直接落成 +// 服务端本机上的一个客户端文件。生成逻辑与「生成服务端」对话框 +// (BuildDlg.cpp::CBuildDlg::OnBnClickedOk)保持同一套字节搬运路径,差别只在参数 +// 来源与错误返回: +// - 对话框:UI 参数 → 读资源 → CONNECT_ADDRESS 原地覆盖 → 锚 → 落盘 → 压缩/增肥 +// - 本工具:JSON 参数 → 同上;不碰 ShellCode AES / 载荷伪装(那需要额外的载荷 +// 文件与图片容器流程,属于对话框专属)。 +// +// 与对话框一致的几个关键点(改动时两边必须同步): +// 1. 模板发布日期比主控新 → 拒绝生成(compareDates)。 +// 2. 内嵌 TLS 锚写在 UPX / 增肥之前,跟 CONNECT_ADDRESS 走同一条搬运路径。 +// 3. 只有 ghost / ghost 服务 / ghost SYSTEM / ServerDll.dll 模板里有锚块; +// TestRun 的锚要生成进 ServerDll.dll,Linux/macOS/Android 模板没有锚块。 +// 4. TinyRun / TestRun 注入模式不加密 CONNECT_ADDRESS(与对话框一致)。 +// +// 并发:生成过程串行化。ReleaseUPX() 会把 upx.exe 释放到服务端目录这个固定文件名, +// 两个并发生成会互相踩;串行化同时也避免了同一输出文件的写竞争。 + +#include "stdafx.h" +#include "McpBuildClient.h" +#include "McpInternal.h" +#include "McpServer.h" // McpServer().IsBuildEnabled() +#include "BuildDlg.h" // ReadResource / ResFileName +#include "EmbeddedAnchor.h" // EmbedTlsAnchorInto / TlsAnchorSummary +#include "ServerTlsSession.h" // ServerTlsIdentity::IsReady +#include "2015RemoteDlg.h" // CMy2015RemoteDlg::GetEffectiveMasterAddress +#include "2015Remote.h" // THIS_CFG / GetMasterHash +#include "resource.h" // IDR_* 客户端模板资源 + +#include +#include +#include +#include + +#ifndef _WIN64 +#ifdef _DEBUG +#pragma comment(lib, "jsoncpp/jsoncppd.lib") +#else +#pragma comment(lib, "jsoncpp/jsoncpp.lib") +#endif +#else +#ifdef _DEBUG +#pragma comment(lib, "jsoncpp/jsoncpp_x64d.lib") +#else +#pragma comment(lib, "jsoncpp/jsoncpp_x64.lib") +#endif +#endif + +// BuildDlg.cpp / 2015RemoteDlg.cpp 里既有的全局助手(没有公共头声明,按对话框同款方式 +// 前置声明;定义所在的编译单元与本文件一起链接)。 +int run_upx(const std::string& upx, const std::string& file, bool isCompress); +BOOL WriteBinaryToFile(const char* path, const char* data, ULONGLONG size, LONGLONG offset = 0); +std::string GetMasterId(); +std::string GetPwdHash(); + +namespace { + +using namespace McpInternal; + +// 生成过程串行化(见文件头「并发」)。 +std::mutex g_buildMutex; + +// 客户端目标定义。资源/类型/启动方式与 BuildDlg.cpp 的 Index* 分支逐项对应; +// 这里刻意不复用对话框的 Index 枚举(它定义在 .cpp 内部,且顺序只是 UI 下拉框顺序)。 +struct TargetDef { + const char* name; // MCP 参数值 + const char* label; // 返回/错误信息里的中文名 + const char* defaultFile; // 默认输出文件名 + int clientType; // CLIENT_TYPE_* + int startup; // Startup_* + int resX64; // 64 位资源 ID + int resX86; // 32 位资源 ID(posix 与 x64 相同) + const char* resNameX64; // res 目录外部文件名(优先于内嵌资源) + const char* resNameX86; + bool archAware; // 是否有 x86/x64 两套模板 + bool windows; // Windows 安装/加壳/增肥语义是否适用 + bool anchorCapable; // 模板里是否有内嵌 TLS 锚块 +}; + +const TargetDef kTargets[] = { + // ---- Windows ---- + { "testrun_dll", u8"TestRun - 磁盘DLL", "TestRun.exe", CLIENT_TYPE_DLL, Startup_DLL, + IDR_TESTRUN_X64, IDR_TESTRUN_X86, ResFileName::TESTRUN_X64, ResFileName::TESTRUN_X86, + true, true, false }, + { "testrun_memdll", u8"TestRun - 内存DLL", "TestRun.exe", CLIENT_TYPE_MEMDLL, Startup_MEMDLL, + IDR_TESTRUN_X64, IDR_TESTRUN_X86, ResFileName::TESTRUN_X64, ResFileName::TESTRUN_X86, + true, true, false }, + { "testrun_injsc", u8"TestRun - 注入任务管理器", "TestRun.exe", CLIENT_TYPE_MEMDLL, Startup_InjSC, + IDR_TESTRUN_X64, IDR_TESTRUN_X86, ResFileName::TESTRUN_X64, ResFileName::TESTRUN_X86, + true, true, false }, + { "testrun_service", u8"TestRun - Windows 服务", "TestRun.exe", CLIENT_TYPE_MEMDLL, Startup_TestRunMsc, + IDR_TESTRUN_X64, IDR_TESTRUN_X86, ResFileName::TESTRUN_X64, ResFileName::TESTRUN_X86, + true, true, false }, + { "testrun_system", "TestRun - SYSTEM", "TestRun.exe", CLIENT_TYPE_MEMDLL, Startup_TestRunSystem, + IDR_TESTRUN_X64, IDR_TESTRUN_X86, ResFileName::TESTRUN_X64, ResFileName::TESTRUN_X86, + true, true, false }, + { "ghost", "ghost.exe", "ghost.exe", CLIENT_TYPE_ONE, Startup_DLL, + IDR_GHOST_X64, IDR_GHOST_X86, ResFileName::GHOST_X64, ResFileName::GHOST_X86, + true, true, true }, + { "ghost_service", u8"ghost.exe - Windows 服务", "ghost.exe", CLIENT_TYPE_ONE, Startup_GhostMsc, + IDR_GHOST_X64, IDR_GHOST_X86, ResFileName::GHOST_X64, ResFileName::GHOST_X86, + true, true, true }, + { "ghost_system", "ghost.exe - SYSTEM", "ghost.exe", CLIENT_TYPE_ONE, Startup_GhostSystem, + IDR_GHOST_X64, IDR_GHOST_X86, ResFileName::GHOST_X64, ResFileName::GHOST_X86, + true, true, true }, + { "serverdll", "ServerDll.dll", "ServerDll.dll", CLIENT_TYPE_DLL, Startup_DLL, + IDR_SERVERDLL_X64, IDR_SERVERDLL_X86, ResFileName::SERVERDLL_X64, ResFileName::SERVERDLL_X86, + true, true, true }, + { "tinyrun", "TinyRun.dll", "TinyRun.dll", CLIENT_TYPE_SHELLCODE, Startup_DLL, + IDR_TINYRUN_X64, IDR_TINYRUN_X86, ResFileName::TINYRUN_X64, ResFileName::TINYRUN_X86, + true, true, false }, + // ---- posix ---- + { "linux", "ghost - Linux x64", "ghost", CLIENT_TYPE_LINUX, Startup_DLL, + IDR_LINUX_GHOST, IDR_LINUX_GHOST, ResFileName::GHOST_LINUX, ResFileName::GHOST_LINUX, + false, false, false }, + { "macos", "ghost - Apple MacOS", "ghost", CLIENT_TYPE_MACOS, Startup_DLL, + IDR_MACOS_GHOST, IDR_MACOS_GHOST, ResFileName::GHOST_MACOS, ResFileName::GHOST_MACOS, + false, false, false }, + { "android", "ghost - Google Android", "ghost.apk", CLIENT_TYPE_ANDROID, Startup_DLL, + IDR_ANDROID_GHOST, IDR_ANDROID_GHOST, ResFileName::GHOST_ANDROID, ResFileName::GHOST_ANDROID, + false, false, false }, +}; + +const TargetDef* FindTarget(const std::string& name) { + for (const TargetDef& t : kTargets) + if (name == t.name) return &t; + return nullptr; +} + +std::string Trim(const std::string& s) { + const size_t b = s.find_first_not_of(" \t\r\n"); + if (b == std::string::npos) return ""; + const size_t e = s.find_last_not_of(" \t\r\n"); + return s.substr(b, e - b + 1); +} + +struct ProtoDef { const char* name; int value; }; +const ProtoDef kProtos[] = { + { "tcp", PROTO_TCP }, { "udp", PROTO_UDP }, { "http", PROTO_HTTP }, + { "random", PROTO_RANDOM }, { "kcp", PROTO_KCP }, { "ws", PROTO_WS }, + { "wss", PROTO_WSS }, +}; + +// 协议名/数字 → protoType;-1 = 不认识。 +int ParseProto(const std::string& raw) { + const std::string s = ToLowerAscii(Trim(raw)); + for (const ProtoDef& p : kProtos) + if (s == p.name) return p.value; + if (IsDigits(s)) { + const int v = atoi(s.c_str()); + for (const ProtoDef& p : kProtos) + if (v == p.value) return v; + return -1; + } + return -1; +} + +const char* ProtoName(int proto) { + for (const ProtoDef& p : kProtos) + if (proto == p.value) return p.name; + return "tcp"; +} + +// install_location → installFlag(顺序与对话框 IDC_COMBO_INSTALL_LOC 的 InsertString 一致)。 +struct LocDef { const char* name; int flag; }; +const LocDef kLocations[] = { + { "programdata", 0 }, { "programfiles", 1 }, { "systemroot", 2 }, + { "appdata", 3 }, { "localappdata", 4 }, +}; + +int ParseLocation(const std::string& raw) { + const std::string s = ToLowerAscii(Trim(raw)); + for (const LocDef& l : kLocations) + if (s == l.name) return l.flag; + if (IsDigits(s)) { + const int v = atoi(s.c_str()); + if (v >= 0 && v <= 4) return v; + } + return -1; +} + +bool GetBoolArg(const Json::Value& args, const char* key, bool defVal) { + if (!args.isMember(key)) return defVal; + const Json::Value& v = args[key]; + if (v.isBool()) return v.asBool(); + if (v.isNumeric()) return v.asInt() != 0; + if (v.isString()) { + const std::string s = ToLowerAscii(Trim(v.asString())); + if (s == "true" || s == "1" || s == "yes") return true; + if (s == "false" || s == "0" || s == "no") return false; + } + return defVal; +} + +// UTF-8 → 服务端 ANSI(CP_ACP)。生成端接下来全用 ANSI 路径/结构体,无法表示的字符 +// 必须显式拒绝,不能用 '?' 顶替(会写出一个路径或分组名都不对的客户端)。 +bool ToAnsiStrict(const std::string& utf8, const char* field, std::string& out, std::string& err) { + if (!Utf8ToCpExact(utf8, CP_ACP, out)) { + err = std::string(field) + " contains characters that cannot be represented in the " + "server ANSI code page"; + return false; + } + return true; +} + +// Windows 文件名合法性:非法字符、保留名、不能以空格/点结尾(与 BuildDlg 的 +// IsValidFileName 同口径,输出文件名与安装名共用)。 +bool IsValidWinName(const std::string& name) { + if (name.empty()) return false; + if (name.find_first_of("\\/:*?\"<>|") != std::string::npos) return false; + for (unsigned char c : name) + if (c < 0x20) return false; // 控制字符(含制表/换行)不能进文件名 + + std::string upper = name; + for (char& c : upper) if (c >= 'a' && c <= 'z') c = (char)(c - 'a' + 'A'); + const std::string base = upper.substr(0, upper.find('.')); + static const char* kReserved[] = { + "CON", "PRN", "AUX", "NUL", + "COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9", + "LPT1", "LPT2", "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9", + }; + for (const char* r : kReserved) + if (base == r) return false; + + const char last = name.back(); + return last != ' ' && last != '.'; +} + +// 递归建目录;已存在视为成功。 +bool EnsureDirectory(const std::string& path) { + if (path.empty()) return false; + const DWORD attr = GetFileAttributesA(path.c_str()); + if (attr != INVALID_FILE_ATTRIBUTES) + return (attr & FILE_ATTRIBUTE_DIRECTORY) != 0; + + std::string parent = path; + while (!parent.empty() && parent.back() != '\\' && parent.back() != '/') + parent.pop_back(); + while (!parent.empty() && (parent.back() == '\\' || parent.back() == '/')) + parent.pop_back(); + if (!parent.empty() && !EnsureDirectory(parent)) + return false; + + if (CreateDirectoryA(path.c_str(), NULL)) return true; + return GetLastError() == ERROR_ALREADY_EXISTS; +} + +std::string ExeDirectory() { + char exe[MAX_PATH] = { 0 }; + GetModuleFileNameA(NULL, exe, MAX_PATH); + std::string dir(exe); + const size_t pos = dir.find_last_of("\\/"); + return pos == std::string::npos ? std::string(".") : dir.substr(0, pos); +} + +std::string AbsolutePath(const std::string& path) { + char full[MAX_PATH * 2] = { 0 }; + DWORD n = GetFullPathNameA(path.c_str(), _countof(full), full, NULL); + return (n > 0 && n < _countof(full)) ? std::string(full) : path; +} + +bool SamePathCI(const std::string& a, const std::string& b) { + return _stricmp(a.c_str(), b.c_str()) == 0; +} + +// 把 upx.exe 释放成一次性文件名:对话框的 ReleaseUPX() 固定写 upx.exe,用户同时从 +// 界面生成时两边会抢同一个文件;这里用 PID+tick 避开(MCP 调用之间由 g_buildMutex 串行)。 +std::string ReleaseUpxUnique() { + char name[64] = { 0 }; + _snprintf_s(name, sizeof(name), _TRUNCATE, "upx_mcp_%lu_%llu.exe", + GetCurrentProcessId(), (unsigned long long)GetTickCount64()); + return ReleaseEXE(IDR_BINARY_UPX, name, ResFileName::UPX_EXE); +} + +// 拒绝覆盖主控自身的程序/配置:output_name 只排除路径分隔符,挡不住 "Yama_x64d.exe" +// 或 "settings.ini"。误写这两个文件会让主控无法启动或配置丢失,代价远大于一次生成失败。 +bool IsProtectedServerFile(const std::string& path) { + char exe[MAX_PATH] = { 0 }; + if (GetModuleFileNameA(NULL, exe, MAX_PATH) > 0 && SamePathCI(path, exe)) + return true; + + const std::string dir = ExeDirectory(); + const size_t sep = path.find_last_of("\\/"); + const std::string parent = sep == std::string::npos ? std::string(".") : path.substr(0, sep); + if (!SamePathCI(parent, dir)) + return false; + + std::string base = (sep == std::string::npos) ? path : path.substr(sep + 1); + base = ToLowerAscii(base); + if (base == "settings.ini" || base == "upx.exe") + return true; + // 主控的其它构建产物(Yama_x64.exe / Yama_x86d.exe / Yama_x64.exe 等)。 + if (base.size() > 4 && base.compare(0, 4, "yama") == 0 && + base.compare(base.size() - 4, 4, ".exe") == 0) + return true; + return false; +} + +uint64_t FileSizeOf(const std::string& path) { + WIN32_FILE_ATTRIBUTE_DATA fad = { 0 }; + if (!GetFileAttributesExA(path.c_str(), GetFileExInfoStandard, &fad)) return 0; + return ((uint64_t)fad.nFileSizeHigh << 32) | fad.nFileSizeLow; +} + +Json::Value StrProp(const char* desc) { + Json::Value v(Json::objectValue); + v["type"] = "string"; + if (desc && *desc) v["description"] = desc; + return v; +} + +Json::Value IntProp(const char* desc, int minVal, int maxVal) { + Json::Value v(Json::objectValue); + v["type"] = "integer"; + if (desc && *desc) v["description"] = desc; + v["minimum"] = minVal; + v["maximum"] = maxVal; + return v; +} + +Json::Value UIntProp(const char* desc) { + Json::Value v(Json::objectValue); + v["type"] = "integer"; + v["minimum"] = 0; + if (desc && *desc) v["description"] = desc; + return v; +} + +Json::Value BoolProp(const char* desc) { + Json::Value v(Json::objectValue); + v["type"] = "boolean"; + if (desc && *desc) v["description"] = desc; + return v; +} + +Json::Value EnumProp(const char* desc, std::initializer_list values) { + Json::Value v = StrProp(desc); + Json::Value arr(Json::arrayValue); + for (const char* s : values) arr.append(s); + v["enum"] = arr; + return v; +} + +// target 枚举按表生成,避免手写清单与实现漂移。 +Json::Value BuildBuildClientInputSchema() { + Json::Value props(Json::objectValue); + + Json::Value targets(Json::arrayValue); + for (const TargetDef& t : kTargets) targets.append(t.name); + Json::Value targetProp = StrProp( + u8"生成目标:ghost(Windows 单文件 EXE)、ghost_service(Windows 服务)、" + u8"ghost_system(SYSTEM 权限)、testrun_dll / testrun_memdll / testrun_injsc / " + u8"testrun_service / testrun_system(TestRun 加载器)、serverdll、tinyrun、" + u8"linux、macos、android。前十个是 Windows 目标;linux/macos/android 为固定架构的" + u8"预编译 template,arch=x86 与 Windows 专属的 compress/padding 会被拒绝," + u8"安装目录相关参数不参与生成。"); + targetProp["enum"] = targets; + props["target"] = targetProp; + + props["arch"] = EnumProp(u8"Windows 目标架构,默认 x64;x86 对 testrun_injsc 与 " + u8"linux/macos/android 无效(会被拒绝)。", { "x64", "x86" }); + props["host"] = StrProp( + u8"主控地址,可写分号分隔的多个地址(客户端随机选择)。省略时使用服务端当前" + u8"有效主控地址(含上级 FRP 配置);两者都为空则报错。最长 99 字符。"); + props["port"] = IntProp(u8"主控端口,省略时使用服务端当前有效端口。", 1, 65535); + props["protocol"] = EnumProp( + u8"传输协议,默认 tcp。ws/wss 需反向代理(如 nginx 443)转发到主控端口;" + u8"kcp 需要主控 UDP 协议参数为 1。", { "tcp", "udp", "http", "random", "kcp", "ws", "wss" }); + props["header_enc"] = EnumProp(u8"包头加密方式,默认 hell。", { "shine", "hell" }); + props["running"] = EnumProp(u8"上线方式,默认 random(随机上线)。", { "random", "parallel" }); + props["group"] = StrProp(u8"分组名称,最长 23 字节(ANSI)。省略时与对话框一致使用 default。"); + props["install_location"] = EnumProp( + u8"Windows 安装位置,默认 programdata。仅 Windows 目标有效。", + { "programdata", "programfiles", "systemroot", "appdata", "localappdata" }); + props["install_dir"] = StrProp(u8"Windows 安装子目录名,最长 31 字节,不能含 \\ / : * ? \" < > |。"); + props["install_name"] = StrProp(u8"Windows 安装程序名,最长 31 字节,不能含 \\ / : * ? \" < > |。"); + props["run_as_admin"] = BoolProp( + u8"生成的 Windows 客户端是否请求管理员权限运行,默认 false;安装 Windows 服务时通常需要 true。"); + props["encrypt_address"] = BoolProp( + u8"是否加密写进客户端的 CONNECT_ADDRESS(地址/端口),默认 true。" + u8"testrun_injsc 与 tinyrun 与对话框一致,不加密。"); + props["compress"] = EnumProp( + u8"压缩方式,默认 none;upx 仅 Windows 目标支持。ShellCode AES / PE→ShellCode 等" + u8"需要载荷文件,只能在生成对话框里操作。", { "none", "upx" }); + props["tls_anchor"] = BoolProp( + u8"是否把服务端当前 TLS 证书作为信任锚写进客户端(首连即 TLS),默认 true。" + u8"仅 ghost / ghost_service / ghost_system / serverdll 模板有锚块,且协议为 tcp/http;" + u8"其余目标会如实标注为未内嵌,不视为失败。"); + props["padding_mb"] = IntProp(u8"程序增肥的追加字节数(MB),默认 0;仅 Windows 目标支持。", 0, 256); + props["output_dir"] = StrProp( + u8"输出目录(服务端本机路径),默认主控程序所在目录;不存在会自动创建。"); + props["output_name"] = StrProp( + u8"输出文件名(仅文件名,不含目录),默认按 target 取 ghost.exe / TestRun.exe / " + u8"ServerDll.dll / TinyRun.dll / ghost / ghost.apk。"); + props["overwrite"] = BoolProp( + u8"目标文件已存在时是否覆盖,默认 false。为 false 时返回 -32012," + u8"确认覆盖后再传 true 重试。"); + + Json::Value schema(Json::objectValue); + schema["type"] = "object"; + schema["properties"] = props; + Json::Value required(Json::arrayValue); + required.append("target"); + schema["required"] = required; + return schema; +} + +Json::Value BuildBuildClientOutputSchema() { + Json::Value props(Json::objectValue); + props["ok"] = BoolProp(u8"是否成功;失败时本工具返回 JSON-RPC error。"); + props["path"] = StrProp(u8"生成文件的绝对路径(服务端本机)。"); + props["name"] = StrProp(u8"输出文件名。"); + props["bytes"] = UIntProp(u8"最终文件字节数。"); + props["target"] = StrProp(u8"生成目标(与入参 target 一致)。"); + props["targetLabel"] = StrProp(u8"生成目标的中文名,如「ghost.exe - Windows 服务」。"); + props["arch"] = StrProp(u8"实际架构:x64 / x86;posix 目标为 native。"); + props["clientType"] = StrProp(u8"客户端类型:EXE / DLL / MDLL / SC / LNX / MAC / APK。"); + props["host"] = StrProp(u8"写入客户端的主控地址。"); + props["port"] = IntProp(u8"写入客户端的主控端口。", 1, 65535); + props["protocol"] = StrProp(u8"写入客户端的传输协议。"); + props["tlsAnchor"] = EnumProp( + u8"内嵌 TLS 信任锚状态:embedded(已内嵌)/ disabled(未请求)/ not_applicable" + u8"(该目标模板不含客户端代码)/ unsupported_platform(Linux/macOS/Android 模板" + u8"没有锚块)/ skipped_protocol(该协议不走设备端口 TLS)/ unavailable(服务端未启用" + u8"TLS)/ no_block(模板里没有锚块,已按普通客户端生成)。", + { "embedded", "disabled", "not_applicable", "unsupported_platform", + "skipped_protocol", "unavailable", "no_block" }); + props["tlsAnchorSummary"] = StrProp(u8"内嵌成功时的证书摘要(如 builtin 2036-11-01 sha1:...)。"); + props["overwritten"] = BoolProp(u8"是否覆盖了已存在的同名文件。"); + Json::Value tips(Json::objectValue); + tips["type"] = "array"; + tips["description"] = u8"生成后需要注意的事项(KCP/WS 端口、macOS/Android 重签、锚未内嵌等)。"; + Json::Value tipItem(Json::objectValue); + tipItem["type"] = "string"; + tips["items"] = tipItem; + props["tips"] = tips; + + Json::Value schema(Json::objectValue); + schema["type"] = "object"; + schema["properties"] = props; + return schema; +} + +// 从 JSON 参数读字符串;没有该键时返回空串。 +std::string ArgStr(const Json::Value& args, const char* key) { + return GetStringArg(args, key); +} + +// 枚举类参数:模型偶尔会把协议写成数字(如 5 表示 ws),这里一并接受; +// 其他非字符串/非数字类型返回空串,由调用方的默认值或校验处理。 +std::string ArgStrOrNum(const Json::Value& args, const char* key) { + if (!args.isMember(key)) return ""; + const Json::Value& v = args[key]; + if (v.isString()) return v.asString(); + if (v.isNumeric()) return v.asString(); + return ""; +} + +// 生成客户端主流程。成功返回 true 并填 out;失败返回 false 并填 err/errCode。 +bool GenerateClient(const Json::Value& args, Json::Value& out, + int& errCode, std::string& err) { + // ---- target ---- + if (args.isMember("target") && !args["target"].isString()) { + errCode = -32602; + err = "target must be a string"; + return false; + } + const std::string targetName = ToLowerAscii(Trim(ArgStr(args, "target"))); + if (targetName.empty()) { + errCode = -32602; + err = "Missing required parameter: target"; + return false; + } + const TargetDef* def = FindTarget(targetName); + if (!def) { + errCode = -32602; + err = "Unknown target: " + targetName + ". Valid values: "; + for (const TargetDef& t : kTargets) err += std::string(t.name) + " "; + if (!err.empty() && err.back() == ' ') err.pop_back(); + return false; + } + + // ---- arch ---- + std::string arch = ToLowerAscii(Trim(ArgStrOrNum(args, "arch"))); + if (arch.empty()) arch = "x64"; + if (arch != "x64" && arch != "x86") { + errCode = -32602; + err = "arch must be x64 or x86"; + return false; + } + if (!def->archAware && arch == "x86") { + errCode = -32602; + err = std::string(def->name) + " has a fixed-architecture template; arch=x86 is not supported"; + return false; + } + if (def->name == std::string("testrun_injsc") && arch == "x86") { + errCode = -32602; + err = "testrun_injsc injects shellcode into 64-bit processes; arch=x86 is not supported"; + return false; + } + const bool is64 = (arch != "x86"); + + // ---- host / port ---- + if (args.isMember("host") && !args["host"].isString()) { + errCode = -32602; + err = "host must be a string"; + return false; + } + std::string host = Trim(ArgStr(args, "host")); + int port = 0; + bool hasPort = GetIntArg(args, "port", port); + // 显式给了 port 但解析不出来("443 " / "443/tcp" 之类)时不能静默回落到默认端口: + // 那会生成一个连错端口的客户端,而结果里报的又是回落值,调用方无从发现。 + if (args.isMember("port") && !hasPort) { + errCode = -32602; + err = "port must be an integer"; + return false; + } + if (host.empty() || !hasPort) { + std::string effIp; + int effPort = 0; + CMy2015RemoteDlg::GetEffectiveMasterAddress(effIp, effPort); + if (host.empty()) host = effIp; + if (!hasPort) port = effPort; + } + if (host.empty()) { + errCode = -32602; + err = "host is required (the server has no effective master address configured)"; + return false; + } + if (port <= 0 || port > 65535) { + errCode = -32602; + err = "port must be 1-65535"; + return false; + } + if (host.size() > 99) { + errCode = -32602; + err = "host is too long (max 99 bytes)"; + return false; + } + + // ---- protocol / header enc / running ---- + int proto = PROTO_TCP; + const std::string protoRaw = ArgStrOrNum(args, "protocol"); + if (!protoRaw.empty()) { + proto = ParseProto(protoRaw); + if (proto < 0) { + errCode = -32602; + err = "Unknown protocol: " + protoRaw + ". Valid values: tcp udp http random kcp ws wss"; + return false; + } + } + + std::string encName = ToLowerAscii(Trim(ArgStrOrNum(args, "header_enc"))); + if (encName.empty()) encName = "hell"; + int headerEnc = PROTOCOL_HELL; + if (encName == "shine") headerEnc = PROTOCOL_SHINE; + else if (encName != "hell") { + errCode = -32602; + err = "header_enc must be shine or hell"; + return false; + } + + std::string runName = ToLowerAscii(Trim(ArgStrOrNum(args, "running"))); + if (runName.empty()) runName = "random"; + int running = RUNNING_RANDOM; + if (runName == "parallel") running = RUNNING_PARALLEL; + else if (runName != "random") { + errCode = -32602; + err = "running must be random or parallel"; + return false; + } + + // ---- Windows-only 参数在非 Windows 目标上的处理 ---- + const std::string compressRaw = ToLowerAscii(Trim(ArgStrOrNum(args, "compress"))); + const std::string compress = compressRaw.empty() ? "none" : compressRaw; + if (compress != "none" && compress != "upx") { + errCode = -32602; + err = "compress must be none or upx (other modes need a payload file and are only " + "available in the build dialog)"; + return false; + } + if (!def->windows && compress != "none") { + errCode = -32602; + err = std::string("compress is not supported for ") + def->name; + return false; + } + int paddingMb = 0; + if (args.isMember("padding_mb") && !GetIntArg(args, "padding_mb", paddingMb)) { + errCode = -32602; + err = "padding_mb must be an integer"; + return false; + } + if (paddingMb < 0 || paddingMb > 256) { + errCode = -32602; + err = "padding_mb must be 0-256"; + return false; + } + if (!def->windows && paddingMb > 0) { + errCode = -32602; + err = std::string("padding_mb is not supported for ") + def->name; + return false; + } + + int installFlag = 0; + const std::string locRaw = ArgStrOrNum(args, "install_location"); + if (!locRaw.empty()) { + installFlag = ParseLocation(locRaw); + if (installFlag < 0) { + errCode = -32602; + err = "Unknown install_location: " + locRaw + + ". Valid values: programdata programfiles systemroot appdata localappdata"; + return false; + } + } + + // ---- 字符串字段:UTF-8 → ANSI,并做长度/合法性校验 ---- + std::string groupAnsi, dirAnsi, nameAnsi, hostAnsi; + if (!ToAnsiStrict(host, "host", hostAnsi, err)) { errCode = -32602; return false; } + if (hostAnsi.size() > 99) { + errCode = -32602; + err = "host is too long (max 99 bytes in ANSI)"; + return false; + } + + // 与对话框一致:分组默认 "default"(对话框里该编辑框就是预填的 default)。 + std::string group = ArgStr(args, "group"); + if (group.empty()) group = "default"; + if (!ToAnsiStrict(group, "group", groupAnsi, err)) { errCode = -32602; return false; } + if (groupAnsi.size() > 23) { + errCode = -32602; + err = "group is too long (max 23 bytes in ANSI)"; + return false; + } + + const std::string installDir = Trim(ArgStr(args, "install_dir")); + if (!installDir.empty()) { + if (!ToAnsiStrict(installDir, "install_dir", dirAnsi, err)) { errCode = -32602; return false; } + if (dirAnsi.size() > 31) { + errCode = -32602; + err = "install_dir is too long (max 31 bytes in ANSI)"; + return false; + } + if (!IsValidWinName(dirAnsi)) { + errCode = -32602; + err = "install_dir is not a valid Windows file name"; + return false; + } + } + + const std::string installName = Trim(ArgStr(args, "install_name")); + if (!installName.empty()) { + if (!ToAnsiStrict(installName, "install_name", nameAnsi, err)) { errCode = -32602; return false; } + if (nameAnsi.size() > 31) { + errCode = -32602; + err = "install_name is too long (max 31 bytes in ANSI)"; + return false; + } + if (!IsValidWinName(nameAnsi)) { + errCode = -32602; + err = "install_name is not a valid Windows file name"; + return false; + } + } + + // ---- 输出路径 ---- + std::string outDir = Trim(ArgStr(args, "output_dir")); + if (outDir.empty()) outDir = ExeDirectory(); + else { + std::string ansiDir; + if (!ToAnsiStrict(outDir, "output_dir", ansiDir, err)) { errCode = -32602; return false; } + outDir = ansiDir; + } + outDir = AbsolutePath(outDir); + + std::string outName = Trim(ArgStr(args, "output_name")); + if (outName.empty()) outName = def->defaultFile; + else { + std::string ansiName; + if (!ToAnsiStrict(outName, "output_name", ansiName, err)) { errCode = -32602; return false; } + outName = ansiName; + if (!IsValidWinName(outName)) { + errCode = -32602; + err = "output_name is not a valid file name (no directory separators)"; + return false; + } + } + + std::string outPath = outDir; + if (!outPath.empty() && outPath.back() != '\\' && outPath.back() != '/') + outPath += "\\"; + outPath += outName; + + if (IsProtectedServerFile(outPath)) { + errCode = -32012; + err = "Refusing to overwrite a server program/config file: " + outPath; + return false; + } + + const bool overwrite = GetBoolArg(args, "overwrite", false); + const DWORD existing = GetFileAttributesA(outPath.c_str()); + if (existing != INVALID_FILE_ATTRIBUTES) { + if (existing & FILE_ATTRIBUTE_DIRECTORY) { + errCode = -32012; + err = "Output path is a directory: " + outPath; + return false; + } + if (!overwrite) { + errCode = -32012; + err = "File already exists: " + outPath + ". Pass overwrite=true to replace it."; + return false; + } + } + + // ---- 读模板 ---- + DWORD dwSize = 0; + LPBYTE buf = ReadResource(is64 ? def->resX64 : def->resX86, dwSize, + is64 ? def->resNameX64 : def->resNameX86); + if (!buf || dwSize == 0) { + errCode = -32001; + err = "Client template is missing from res directory and embedded resources: "; + err += is64 ? def->resNameX64 : def->resNameX86; + return false; + } + struct BufferGuard { + LPBYTE p; + ~BufferGuard() { SAFE_DELETE_ARRAY(p); } + } guard{ buf }; + + // ---- CONNECT_ADDRESS ---- + CONNECT_ADDRESS addr = {}; + strcpy_s(addr.szFlag, FLAG_FINDEN); + if (!addr.SetServer(hostAnsi.c_str(), port)) { + errCode = -32602; + err = "Invalid host/port"; + return false; + } + addr.iType = def->clientType; + addr.iStartup = def->startup; + addr.iHeaderEnc = headerEnc; + addr.protoType = (char)proto; + addr.runningType = (char)running; + addr.installFlag = installFlag; + addr.runasAdmin = GetBoolArg(args, "run_as_admin", false) ? 1 : 0; + strcpy_s(addr.szBuildDate, DLL_VERSION); + addr.SetAdminId(GetMasterHash().c_str()); + + const std::string pwd = GetPwdHash(); + memcpy(addr.pwdHash, pwd.data(), pwd.size() < sizeof(addr.pwdHash) ? pwd.size() : sizeof(addr.pwdHash)); + if (!groupAnsi.empty()) memcpy(addr.szGroupName, groupAnsi.data(), groupAnsi.size()); + if (!dirAnsi.empty()) memcpy(addr.installDir, dirAnsi.data(), dirAnsi.size()); + if (!nameAnsi.empty()) memcpy(addr.installName, nameAnsi.data(), nameAnsi.size()); + + // 与对话框一致:注入类与 TinyRun 不加密 CONNECT_ADDRESS。 + const bool encryptAddr = GetBoolArg(args, "encrypt_address", true); + if (encryptAddr && def->startup != Startup_InjSC && def->clientType != CLIENT_TYPE_SHELLCODE) + addr.Encrypt(); + + // ---- 扫描并原地覆盖 ---- + const CONNECT_ADDRESS patched = addr.ModifyFlag(GetMasterId().c_str()); + const int flagLen = addr.FlagLen(); + char* ptr = (char*)buf; + int remain = (int)dwSize; + bool found = false; + while (remain > 0) { + const int off = MemoryFind(ptr, (char*)addr.Flag(), remain, flagLen); + if (off < 0) break; + if (remain - off < (int)sizeof(CONNECT_ADDRESS)) break; + + CONNECT_ADDRESS* dst = (CONNECT_ADDRESS*)(ptr + off); + // 模板发布日期比主控新 → 与对话框一样直接拒绝(否则新客户端会被老配置覆盖)。 + const int cmp = strlen(dst->szBuildDate) ? compareDates(dst->szBuildDate, addr.szBuildDate) : -1; + if (cmp > 0) { + errCode = -32001; + err = "Client template is newer than this server (" + std::string(dst->szBuildDate) + + " > " + DLL_VERSION + "): " + outName; + return false; + } + if (cmp != -2) { + *dst = patched; + found = true; + } + ptr += off + sizeof(CONNECT_ADDRESS); + remain -= off + sizeof(CONNECT_ADDRESS); + } + if (!found) { + errCode = -32001; + err = "CONNECT_ADDRESS not found in client template: " + outName; + return false; + } + + // ---- 内嵌 TLS 信任锚(必须在 UPX / 增肥之前,见文件头)---- + std::string anchorStatus = "disabled"; + std::string anchorSummary; + if (GetBoolArg(args, "tls_anchor", true)) { + if (!def->anchorCapable) { + anchorStatus = def->windows ? "not_applicable" : "unsupported_platform"; + } else if (proto != PROTO_TCP && proto != PROTO_HTTP) { + anchorStatus = "skipped_protocol"; + } else if (!ServerTlsIdentity::IsReady()) { + anchorStatus = "unavailable"; + } else { + DWORD pemLen = 0; + std::string anchorErr; + const EmbedResult embed = EmbedTlsAnchorInto(buf, dwSize, hostAnsi, pemLen, anchorErr); + if (embed == EmbedResult::Ok) { + anchorStatus = "embedded"; + TlsAnchorSummary(anchorSummary); + } else if (embed == EmbedResult::NoBlock) { + // 模板没有锚块(例如资源没重编):与对话框一样按普通客户端生成。 + anchorStatus = "no_block"; + } else { + errCode = -32001; + err = "Failed to embed TLS trust anchor: " + anchorErr; + return false; + } + } + } + + // ---- 落盘(目录到这一步才创建:参数/模板/锚都过了再产生副作用)---- + if (!EnsureDirectory(outDir)) { + errCode = -32602; + err = "Cannot create output_dir: " + outDir; + return false; + } + if (!WriteBinaryToFile(outPath.c_str(), (const char*)buf, dwSize)) { + errCode = -32001; + err = "Failed to write output file: " + outPath; + return false; + } + + // ---- 可选 UPX ---- + if (compress == "upx") { + const std::string upx = ReleaseUpxUnique(); + if (upx.empty()) { + errCode = -32001; + err = "Failed to release upx.exe"; + return false; + } + const int rc = run_upx(upx, outPath, true); + DeleteFileA(upx.c_str()); + // UPX 返回码:0=成功,2=警告(如文件已压缩)。 + if (rc != 0 && rc != 2) { + errCode = -32001; + err = "UPX failed with exit code " + std::to_string(rc) + + "; the uncompressed client was written and left at: " + outPath; + return false; + } + } + + // ---- 可选增肥(追加到文件尾部,与对话框同款做法)---- + if (paddingMb > 0) { + const uint64_t total = (uint64_t)paddingMb * 1024 * 1024; + std::vector chunk(1024 * 1024, (char)(time(0) % 256)); + uint64_t left = total; + while (left > 0) { + const size_t n = (size_t)(left < chunk.size() ? left : chunk.size()); + if (!WriteBinaryToFile(outPath.c_str(), chunk.data(), n, -1)) { + errCode = -32001; + err = "Failed to append padding; the client without padding was written and left at: " + + outPath; + return false; + } + left -= n; + } + } + + // ---- 结果 ---- + Json::Value result(Json::objectValue); + result["ok"] = true; + result["path"] = ToUtf8(outPath.c_str(), CP_ACP); + result["name"] = ToUtf8(outName.c_str(), CP_ACP); + result["bytes"] = (Json::UInt64)FileSizeOf(outPath); + result["target"] = def->name; + result["targetLabel"] = def->label; + result["arch"] = def->archAware ? arch : std::string("native"); + result["clientType"] = GetClientType(def->clientType); + result["host"] = host; + result["port"] = port; + result["protocol"] = ProtoName(proto); + result["tlsAnchor"] = anchorStatus; + if (!anchorSummary.empty()) + result["tlsAnchorSummary"] = ToUtf8(anchorSummary.c_str(), CP_ACP); + result["overwritten"] = (existing != INVALID_FILE_ATTRIBUTES); + + Json::Value tips(Json::arrayValue); + if (std::string(def->name) == "testrun_dll") + tips.append(u8"TestRun 需要同一目录下的 ServerDll.dll 才能正常工作;请另行生成 serverdll。"); + if (proto == PROTO_KCP) + tips.append(u8"使用 KCP 协议生成的服务,必须把主控的 UDP 协议参数设为 1。"); + if (proto == PROTO_WS || proto == PROTO_WSS) + tips.append(u8"WebSocket 协议需经反向代理(如 nginx 443)转发到主控端口,客户端地址可填域名。"); + if (def->clientType == CLIENT_TYPE_MACOS) + tips.append(u8"macOS binary 被修改后签名失效,直接运行会被系统强杀;请拷贝到 macOS 后运行 " + u8"install.sh(会自动 ad-hoc 重签),或执行 codesign --force --sign - ghost。"); + if (def->clientType == CLIENT_TYPE_ANDROID) + tips.append(u8"APK 被修改后原签名失效,必须用 apksigner 重新签名后才能安装到设备。"); + if (anchorStatus == "no_block") + tips.append(u8"客户端模板里没有内嵌锚块,本次按普通客户端生成;重编 ghost/ServerDll 资源后可再次启用。"); + if (anchorStatus == "unavailable") + tips.append(u8"服务端当前未启用可用 TLS 身份,客户端未内嵌信任锚;首次连接为明文,需主控在线下发锚。"); + if (anchorStatus == "not_applicable") + tips.append(u8"该目标是加载器/壳,模板本身不含客户端锚块;需要首连即 TLS 时请对 serverdll 生成并启用 tls_anchor。"); + if (def->anchorCapable && anchorStatus != "embedded" && anchorStatus != "disabled" && + anchorStatus != "no_block") + tips.append(u8"未内嵌 TLS 信任锚,本批客户端首次连接为明文,需主控在线下发锚。"); + if (def->clientType == CLIENT_TYPE_LINUX || def->clientType == CLIENT_TYPE_MACOS || + def->clientType == CLIENT_TYPE_ANDROID) + tips.append(u8"该模板不含内嵌锚块;Linux/macOS 客户端的信任锚由主控在线下发(TLS 指令)。"); + if (!tips.empty()) result["tips"] = tips; + + out = result; + return true; +} + +} // namespace + +namespace McpBuildClient { + +bool Handles(const std::string& toolName) { + return toolName == "build_client"; +} + +void AppendTools(Json::Value& tools) { + if (!McpServer().IsBuildEnabled()) return; + + Json::Value tool(Json::objectValue); + tool["name"] = "build_client"; + tool["description"] = u8"在服务端本机生成一个客户端文件(按本主控的上线配置 patch 客户端模板后落盘)。" + u8"这不会修改任何在线主机,也不依赖在线主机;生成目标是模板类型而不是某台设备。" + u8"支持 Windows(ghost 单文件/服务/SYSTEM、TestRun 加载器、ServerDll.dll、TinyRun.dll)、" + u8"Linux、macOS 与 Android。生成地址默认取服务端当前有效主控地址(含上级 FRP 配置)," + u8"也可显式传 host/port。默认会在客户端模板存在内嵌 TLS 锚块且协议为 tcp/http 时写入" + u8"服务端当前证书(首连即 TLS),其余目标如实标注 tlsAnchor 状态。" + u8"输出目录默认主控程序目录,已存在同名文件时默认拒绝(传 overwrite=true 才覆盖)。" + u8"Windows 目标可选 upx 压缩与 padding_mb 增肥;ShellCode AES / PE→ShellCode 等需要" + u8"载荷文件的模式只能用生成对话框。需服务端开启 McpBuild 且关闭只读模式。" + u8"生成后可把 path 交给用户;Windows/Linux/macOS 主机可用 upload_file 送达" + u8"(文件格式需与目标平台匹配),Android 需用户自行安装。"; + tool["inputSchema"] = BuildBuildClientInputSchema(); + tool["outputSchema"] = BuildBuildClientOutputSchema(); + tools.append(tool); +} + +std::string Call(const Json::Value& id, const std::string& toolName, + const Json::Value& args, CMy2015RemoteDlg* parent) { + (void)parent; + if (!Handles(toolName)) + return BuildError(id, -32602, "Unknown tool: " + toolName); + + if (!McpServer().IsBuildEnabled()) + return BuildError(id, -32006, + "Client build tools are disabled (set McpBuild=1 to enable)"); + if (McpServer().IsReadonly()) + return BuildError(id, -32006, + "build_client writes a client binary on the server; set McpReadonly=0 " + "to enable"); + + std::lock_guard lock(g_buildMutex); + + Json::Value output; + int errCode = -32001; + std::string err; + bool ok = false; + try { + ok = GenerateClient(args, output, errCode, err); + } catch (const std::exception& e) { + ok = false; + errCode = -32001; + err = std::string("Internal error while generating client: ") + e.what(); + } catch (...) { + ok = false; + errCode = -32001; + err = "Internal error while generating client"; + } + if (!ok) { + Mprintf("[MCP] build_client failed: %s\n", err.c_str()); + return BuildError(id, errCode, err); + } + + Mprintf("[MCP] build_client: target=%s arch=%s bytes=%llu path=%s\n", + JsonStrField(output, "target").c_str(), JsonStrField(output, "arch").c_str(), + (unsigned long long)output["bytes"].asUInt64(), + JsonStrField(output, "path").c_str()); + + Json::Value result(Json::objectValue); + result["structuredContent"] = output; + + std::string text = std::string(u8"已生成 ") + JsonStrField(output, "targetLabel") + + std::string(u8"(") + JsonStrField(output, "target") + + std::string(u8",") + JsonStrField(output, "arch") + + std::string(u8",") + JsonStrField(output, "clientType") + + std::string(u8"):") + JsonStrField(output, "path") + + std::string(u8",") + std::to_string(output["bytes"].asUInt64()) + + std::string(u8" 字节;主控 ") + JsonStrField(output, "host") + + std::string(":") + std::to_string(output["port"].asInt()) + + std::string(u8",协议 ") + JsonStrField(output, "protocol") + + std::string(u8",TLS 锚: ") + JsonStrField(output, "tlsAnchor") + u8"。"; + if (output.isMember("tips")) { + for (const Json::Value& tip : output["tips"]) + text += std::string("\n- ") + tip.asString(); + } + Json::Value content(Json::arrayValue); + Json::Value item(Json::objectValue); + item["type"] = "text"; + item["text"] = text; + content.append(item); + result["content"] = content; + result["isError"] = false; + + return BuildResult(id, result); +} + +} // namespace McpBuildClient diff --git a/server/2015Remote/McpBuildClient.h b/server/2015Remote/McpBuildClient.h new file mode 100644 index 0000000..ed4ed99 --- /dev/null +++ b/server/2015Remote/McpBuildClient.h @@ -0,0 +1,34 @@ +#pragma once + +// MCP「生成客户端」工具族:build_client。 +// +// 这是服务端本地工具,不针对任何在线主机:把 res 目录里的客户端模板(ghost / TestRun / +// ServerDll / Linux / macOS / Android)patch 成本主控的上线信息并落盘。生成结果与 +// 「生成服务端」对话框(BuildDlg.cpp)走同一套字节搬运路径: +// 资源读取 → CONNECT_ADDRESS 原地覆盖 → 版本日期校验 → 内嵌 TLS 信任锚 → 落盘 +// 对话框专属的 ShellCode AES / PE→ShellCode / 载荷伪装流程不在 MCP 范围内。 +// +// 独立开关 McpBuild(默认关):生成客户端会用主控的 pwdHash / 主控 ID 写出可分发的 +// 二进制,属于会留下持久产物的高风险写操作,必须由管理员显式打开。 +// +// 见 docs/Mcp_BuildClient_Design.md。 + +#include "jsoncpp/json.h" + +#include + +class CMy2015RemoteDlg; + +namespace McpBuildClient { + +// 是否由本模块处理(AppendTools 与 Call 必须保持一致)。 +bool Handles(const std::string& toolName); + +// 按当前开关(McpBuild)追加可见工具。 +void AppendTools(Json::Value& tools); + +// 执行工具;返回完整 JSON-RPC 响应字符串(成功 = BuildResult,失败 = BuildError)。 +std::string Call(const Json::Value& id, const std::string& toolName, + const Json::Value& args, CMy2015RemoteDlg* parent); + +} // namespace McpBuildClient diff --git a/server/2015Remote/McpInternal.cpp b/server/2015Remote/McpInternal.cpp index 38fa331..5445a3c 100644 --- a/server/2015Remote/McpInternal.cpp +++ b/server/2015Remote/McpInternal.cpp @@ -599,6 +599,9 @@ const ToolHints kToolHints[] = { { "chat_send", false, false, false, true }, { "chat_wait", false, false, false, true }, // 会取走 inbox 消息,不是纯读 { "chat_close", false, false, true, true }, + // --- 生成客户端(McpBuild)--- + // 写服务端本机文件(可覆盖),会留下可分发的客户端二进制;不触达任何外部主机。 + { "build_client", false, true, false, false }, }; } // namespace diff --git a/server/2015Remote/McpServer.cpp b/server/2015Remote/McpServer.cpp index 22ded82..9897bcc 100644 --- a/server/2015Remote/McpServer.cpp +++ b/server/2015Remote/McpServer.cpp @@ -11,6 +11,7 @@ #include "McpInternal.h" // 共享助手(McpMachine.cpp 也使用) #include "McpMachine.h" // 主机管理 / 连接管理工具族 #include "McpChat.h" // 远程交谈工具族 +#include "McpBuildClient.h" // 生成客户端工具族(build_client) #include #include @@ -283,12 +284,12 @@ const char* kServerInstructions = u8"2) 工具的可见性与开关\n" u8"tools/list 只返回当前服务端开关允许的工具:终端(terminal)、远程控制(remote_control)、" u8"文件传输(file_transfer)、文件写入(file_write)、管理动作(manage)、主机管理(machine)、键盘记录(keylog)、" - u8"远程交谈(chat)各有独立开关。工具不在列表里通常就不可用,直接调用会被拒(-32006 或 -32005);" + u8"远程交谈(chat)、生成客户端(build)各有独立开关。工具不在列表里通常就不可用,直接调用会被拒(-32006 或 -32005);" u8"例外是下文提到的降级别名(list_processes / list_windows / list_services、operate_window / " u8"control_service,以及 list_online_hosts / search_hosts / list_all_hosts 等旧名)——" u8"它们不在列表里但仍可调用。" u8"当前开关状态可查 get_server_status 的 switches。只读模式(readonly=true)会挡掉大部分写工具," - u8"但只改服务端本地数据的 host_set_remark / host_set_watch_level 仍会列出,调用时才被拒;" + u8"但只改服务端本地数据的 host_set_remark / host_set_watch_level / build_client 仍会列出,调用时才被拒;" u8"get_keylog 只受 McpKeylog 开关控制(与只读模式无关):开关关闭时它不在列表里;只读模式下" u8"只是它的 clear / set_offline 参数被拒,读取不受影响。\n" u8"同一能力存在两套工具时优先用主机管理族:host_inspect(aspects 选 processes / windows / " @@ -350,6 +351,10 @@ const char* kServerInstructions = u8"HTTP 探测:探主机本机或同网段的接口用 http_probe(只收私网/回环 IP 与 localhost,不给域名," u8"不跟随重定向,响应体上限 64KB),不要为此自己写 Invoke-WebRequest / curl;Windows 与 Linux 可用," u8"macOS 与 Android 不支持。\n" + u8"生成客户端:用户说「生成一个连某地址的 Linux/Windows 客户端」时用 build_client(需开启 build 开关且关闭只读)。" + u8"它把模板 patch 成本主控的上线配置后写到服务端本机,结果里 path 是服务端路径;要送到目标机再用 upload_file" + u8"(Windows/Linux/macOS 可用,Android 需用户自行安装),但 macOS/Android 的产物还需要重签(结果 tips 会给出命令)。" + u8"host/port 省略时取服务端当前有效主控地址。已存在同名文件默认拒绝,需要覆盖时显式传 overwrite=true。\n" u8"\n" u8"5) 客户端平台差异\n" u8"工具能否执行取决于目标主机的平台,这与服务端开关无关,两者是叠加关系。调用前用 " @@ -2410,7 +2415,7 @@ std::string BuildToolsListResult(const Json::Value& id) { { Json::Value tool(Json::objectValue); tool["name"] = "get_server_status"; - tool["description"] = u8"获取 YAMA 服务端自身的状态:程序版本与 exe 构建时间、进程已运行秒数、MCP 监听地址与端口、各功能开关(只读/终端/远程控制/文件传输/管理/主机管理/高风险操作/键盘记录/远程交谈)、在线与离线主机数、各类在飞会话数、当前被封禁的来源 IP 数。只读、纯内存,不返回 token。"; + tool["description"] = u8"获取 YAMA 服务端自身的状态:程序版本与 exe 构建时间、进程已运行秒数、MCP 监听地址与端口、各功能开关(只读/终端/远程控制/文件传输/文件写入/管理/主机管理/高风险操作/键盘记录/远程交谈/生成客户端)、在线与离线主机数、各类在飞会话数、当前被封禁的来源 IP 数。只读、纯内存,不返回 token。"; Json::Value inputSchema(Json::objectValue); inputSchema["type"] = "object"; @@ -2812,6 +2817,10 @@ std::string BuildToolsListResult(const Json::Value& id) { // 独立开关 McpChat(默认关),与 McpReadonly 无关;关闭时不追加任何工具。 McpChat::AppendTools(tools); + // 20b) 生成客户端(build_client):服务端本地工具,独立开关 McpBuild(默认关), + // 另要求 McpReadonly=0;关闭时不追加任何工具。 + McpBuildClient::AppendTools(tools); + // 21) 统一补 annotations(A3):只读/破坏性/幂等/开放世界四类提示。 // 放在最后一步,三个注册点(本文件内联、McpMachine、McpChat)一视同仁, // 以后新增工具只需在 McpInternal.cpp 的 kToolHints 表里登记一行。 @@ -4580,6 +4589,7 @@ std::string BuildGetServerStatus(const Json::Value& id, CMy2015RemoteDlg* parent switches["machine_dangerous"] = srv.IsMachineDangerousEnabled(); switches["keylog"] = srv.IsKeylogEnabled(); switches["chat"] = srv.IsChatEnabled(); + switches["build"] = srv.IsBuildEnabled(); status["switches"] = switches; int onlineCount = 0, offlineCount = 0; @@ -11991,6 +12001,9 @@ const ToolPlatform kToolPlatforms[] = { { "mcp_cancel_session", kPlatWin|kPlatLnx|kPlatMac|kPlatApk }, { "host_set_remark", kPlatWin|kPlatLnx|kPlatMac|kPlatApk }, { "host_set_watch_level", kPlatWin|kPlatLnx|kPlatMac|kPlatApk }, + // 生成客户端只在服务端本机写文件,不触达任何主机;平台表按「全平台」登记, + // 门禁因入参没有 id 而直接放行(与其它服务端本地工具相同)。 + { "build_client", kPlatWin|kPlatLnx|kPlatMac|kPlatApk }, // ---- win+lnx+mac ---- SYSTEM / LIST_DRIVE / QUERY_LOG / V2 文件传输 { "list_processes", kPlatWin|kPlatLnx|kPlatMac }, { "list_files", kPlatWin|kPlatLnx|kPlatMac }, @@ -12397,6 +12410,9 @@ std::string DispatchSingleHostTool(const Json::Value& id, const std::string& too // P9:远程交谈工具族(独立开关 McpChat;门控在 McpChat::Call 内复核)。 if (McpChat::Handles(toolName)) return McpChat::Call(id, toolName, args, parent); + // 生成客户端(独立开关 McpBuild + !McpReadonly;门控在 Call 内复核)。 + if (McpBuildClient::Handles(toolName)) return McpBuildClient::Call(id, toolName, args, parent); + // P1-1:list_hosts 与三个旧别名共用一个 handler;list_all_hosts 默认为「在线 + 离线」。 if (toolName == "list_hosts") return BuildListHosts(id, args, parent, false); if (toolName == "list_online_hosts") return BuildListHosts(id, args, parent, false); diff --git a/server/2015Remote/McpServer.h b/server/2015Remote/McpServer.h index b6c76d8..3e6873c 100644 --- a/server/2015Remote/McpServer.h +++ b/server/2015Remote/McpServer.h @@ -566,6 +566,13 @@ public: void SetKeylogEnabled(bool enabled) { m_keylogEnabled = enabled; } bool IsKeylogEnabled() const { return m_keylogEnabled; } + // ===== 生成客户端(build_client)===== + // 服务端本地工具:按本主控配置 patch 客户端模板并落盘。不是远程操作,但会写出 + // 可分发的二进制(含 pwdHash / 主控 ID),独立开关 McpBuild(默认关)且要求 + // McpReadonly=0。见 docs/Mcp_BuildClient_Design.md。 + void SetBuildEnabled(bool enabled) { m_buildEnabled = enabled; } + bool IsBuildEnabled() const { return m_buildEnabled; } + // ===== 工具默认等待超时([settings] McpToolTimeoutMs,ini-only 键)===== // 慢主机上 20s 固定的工具超时太紧;调到 60s 更实用。范围 clamp 到 [1000, 600000]。 // 改动需重启服务端生效(与其它 Mcp* 开关一致)。 @@ -999,6 +1006,7 @@ private: bool m_machineEnabled = false; // P8 主机管理族总开关(默认关;16 个 host_* 工具) bool m_machineDangerousEnabled = false; // P8 高风险子集(冻结/解冻进程、停止/重启服务) bool m_keylogEnabled = false; // N3 键盘记录开关(默认关;get_keylog) + bool m_buildEnabled = false; // 生成客户端开关(默认关;build_client) // 平台门禁(默认开):调用前拦掉「该客户端根本没实现」的工具,立刻返回 -32005。 // 关闭后这类调用会照常下发命令,通常表现为白等超时。判据表见 McpServer.cpp 的 // kToolPlatforms,与 mcp/tools.json 的 platforms 字段对应。 diff --git a/server/2015Remote/McpSettingsDlg.cpp b/server/2015Remote/McpSettingsDlg.cpp index 12e58dd..59d7653 100644 --- a/server/2015Remote/McpSettingsDlg.cpp +++ b/server/2015Remote/McpSettingsDlg.cpp @@ -181,6 +181,9 @@ BOOL CMcpSettingsDlg::OnInitDialog() m_btnKeylog.Create(_TR("启用键盘记录(AI 采集击键)"), WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_AUTOCHECKBOX, r0, this, IDC_MCP_KEYLOG); + m_btnBuild.Create(_TR("启用客户端生成(AI 生成客户端文件,要求只读关)"), + WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_AUTOCHECKBOX, + r0, this, IDC_MCP_BUILD); m_lblWhitelist.Create(_TR("命令白名单"), WS_CHILD | WS_VISIBLE, r0, this, (UINT)-1); m_editWhitelist.Create(WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP | ES_MULTILINE | ES_AUTOVSCROLL | ES_WANTRETURN | WS_VSCROLL, @@ -217,6 +220,7 @@ BOOL CMcpSettingsDlg::OnInitDialog() m_btnMachineDangerous.SendMessage(WM_SETFONT, (WPARAM)hFont, MAKELPARAM(TRUE, 0)); m_btnChat.SendMessage(WM_SETFONT, (WPARAM)hFont, MAKELPARAM(TRUE, 0)); m_btnKeylog.SendMessage(WM_SETFONT, (WPARAM)hFont, MAKELPARAM(TRUE, 0)); + m_btnBuild.SendMessage(WM_SETFONT, (WPARAM)hFont, MAKELPARAM(TRUE, 0)); m_lblWhitelist.SendMessage(WM_SETFONT, (WPARAM)hFont, MAKELPARAM(TRUE, 0)); m_editWhitelist.SendMessage(WM_SETFONT, (WPARAM)hFont, MAKELPARAM(TRUE, 0)); m_btnOK.SendMessage(WM_SETFONT, (WPARAM)hFont, MAKELPARAM(TRUE, 0)); @@ -239,6 +243,7 @@ BOOL CMcpSettingsDlg::OnInitDialog() int machineDangerous = THIS_CFG.GetInt("settings", "McpMachineDangerous", 0); int chat = THIS_CFG.GetInt("settings", "McpChat", 0); int keylog = THIS_CFG.GetInt("settings", "McpKeylog", 0); + int build = THIS_CFG.GetInt("settings", "McpBuild", 0); std::string whitelist = THIS_CFG.GetStr("settings", "McpCmdWhitelist", ""); int https = THIS_CFG.GetInt("settings", "McpHttps", 0); std::string certPath = THIS_CFG.GetStr("settings", "McpCertPath", ""); @@ -265,6 +270,7 @@ BOOL CMcpSettingsDlg::OnInitDialog() m_btnMachineDangerous.SetCheck(machineDangerous ? BST_CHECKED : BST_UNCHECKED); m_btnChat.SetCheck(chat ? BST_CHECKED : BST_UNCHECKED); m_btnKeylog.SetCheck(keylog ? BST_CHECKED : BST_UNCHECKED); + m_btnBuild.SetCheck(build ? BST_CHECKED : BST_UNCHECKED); // 白名单存储为逗号分隔,展示为每行一条。 m_editWhitelist.SetWindowText(CString(WhitelistForDisplay(whitelist).c_str())); @@ -339,6 +345,7 @@ void CMcpSettingsDlg::OnOK() bool machineDangerous = (m_btnMachineDangerous.GetCheck() == BST_CHECKED); bool chat = (m_btnChat.GetCheck() == BST_CHECKED); bool keylog = (m_btnKeylog.GetCheck() == BST_CHECKED); + bool build = (m_btnBuild.GetCheck() == BST_CHECKED); bool https = (m_btnHttps.GetCheck() == BST_CHECKED); // 危险子集依附于主机管理总开关:没开主机管理就没有工具可放开,直接清除并提示。 @@ -401,6 +408,7 @@ void CMcpSettingsDlg::OnOK() THIS_CFG.SetInt("settings", "McpMachineDangerous", machineDangerous ? 1 : 0); THIS_CFG.SetInt("settings", "McpChat", chat ? 1 : 0); THIS_CFG.SetInt("settings", "McpKeylog", keylog ? 1 : 0); + THIS_CFG.SetInt("settings", "McpBuild", build ? 1 : 0); std::string whitelist = CT2A(sWhitelist); whitelist = NormalizeWhitelist(whitelist); THIS_CFG.SetStr("settings", "McpCmdWhitelist", whitelist); @@ -416,6 +424,7 @@ void CMcpSettingsDlg::OnOK() _TR("主机管理的写操作需只读模式关闭;冻结/解冻进程、停止/重启服务还需启用危险主机操作。") + _T("\r\n") + _TR("远程交谈开关的改动需重启程序生效。") + _T("\r\n") + _TR("键盘记录开关的改动需重启程序生效。") + _T("\r\n") + + _TR("客户端生成开关的改动需重启程序生效;它还会写出带主控凭据的客户端文件,请谨慎开启。") + _T("\r\n") + _TR("HTTPS 开关与证书路径的改动需重启程序生效。") + _T("\r\n") + _TR("证书须为 PEM 格式,私钥须为 PKCS#8 格式。"), _TR("提示"), MB_ICONINFORMATION); @@ -494,6 +503,9 @@ void CMcpSettingsDlg::LayoutControls(int cx, int cy) m_btnKeylog.MoveWindow(margin, y, cx - margin * 2, 22); y += 30; + m_btnBuild.MoveWindow(margin, y, cx - margin * 2, 22); + y += 30; + const int whitelistH = 90; m_lblWhitelist.MoveWindow(margin, y, labelW, rowH); m_editWhitelist.MoveWindow(margin + labelW, y - 2, cx - margin * 2 - labelW, whitelistH); diff --git a/server/2015Remote/McpSettingsDlg.h b/server/2015Remote/McpSettingsDlg.h index 4599533..8ee3aa9 100644 --- a/server/2015Remote/McpSettingsDlg.h +++ b/server/2015Remote/McpSettingsDlg.h @@ -46,6 +46,7 @@ private: IDC_MCP_CERT_BROWSE = 1018, // 证书路径「浏览」按钮 IDC_MCP_KEY_BROWSE = 1019, // 私钥路径「浏览」按钮 IDC_MCP_FILEWRITE = 1020, // 「启用文件写入」复选框(删除/改名/建目录,要求只读关) + IDC_MCP_BUILD = 1021, // 「启用客户端生成」复选框(build_client,要求只读关) }; CButton m_btnEnable; @@ -61,6 +62,7 @@ private: CButton m_btnMachineDangerous; CButton m_btnChat; CButton m_btnKeylog; + CButton m_btnBuild; CStatic m_lblWhitelist; CEdit m_editWhitelist; CButton m_btnHttps; diff --git a/server/2015Remote/lang/de_DE.ini b/server/2015Remote/lang/de_DE.ini index 237cf42..0cdb0ba 100644 --- a/server/2015Remote/lang/de_DE.ini +++ b/server/2015Remote/lang/de_DE.ini @@ -2058,6 +2058,8 @@ MCPԶ Զ³̽»̸¿ª¹صĸ͝ÐèÖØÆô³ÌÐòÉúЧ¡£=Aenderungen am Fernchat-Schalter werden nach einem Neustart wirksam. ÆôÓüüÅ̼Ǽ£¨AI ²ɼ¯»÷¼ü£©=Keylogger aktivieren (KI-Tastenaufzeichnung) ¼üÅ̼Ǽ¿ª¹صĸ͝ÐèÖØÆô³ÌÐòÉúЧ¡£=Aenderungen am Keylogger-Schalter werden erst nach einem Neustart wirksam. +ÆôÓÿͻ§¶ËÉú³ɣ¨AI Éú³ɿͻ§¶ËÎļþ£¬ҪÇóֻ¶Á¹أ©=Client-Erstellung aktivieren (KI erzeugt Clientdateien; Nur-Lesen aus) +¿ͻ§¶ËÉú³ɿª¹صĸ͝ÐèÖØÆô³ÌÐòÉúЧ£»Ëü»¹»áд³ö´øÖ÷¿Øƾ¾ݵĿͻ§¶ËÎļþ£¬Çë½÷É÷¿ªÆô¡£=Aenderungen am Client-Erstellungs-Schalter werden nach einem Neustart wirksam; er schreibt Clientdateien mit Master-Anmeldedaten, daher bitte vorsichtig aktivieren. Ö÷»ú¹ÜÀíµÄд²Ù×÷Ðèֻ¶Áģʽ¹رգ»¶³½á/½ⶳ½ø³̡¢ֹͣ/ÖØÆô·þÎñ»¹ÐèÆôÓÃΣÏÕÖ÷»ú²Ù×÷¡£=Schreiboperationen der Maschinenverwaltung erfordern deaktivierten Nur-Lesen-Modus; Einfrieren/Auftauen von Prozessen und Stoppen/Neustarten von Diensten erfordern zusaetzlich gefaehrliche Maschinenoperationen. µÚ %d ¸öǮ°üµØַ²»ºϷ¨!=Wallet-Adresse #%d ist ungueltig! %d ÐÂÁ¬½Ó\r\n=%d Neue Verbindung\r\n @@ -2225,6 +2227,7 @@ HTTPS ÄÚǶTLSÐÅÈÎê(Ê×Á¬¼´¼ÓÃÜ)=TLS-Vertrauensanker einbetten (TLS von Anfang an) ÄÚǶTLSÐÅÈÎê(êÔÚServerDll.dllÀï)=TLS-Vertrauensanker einbetten (in ServerDll.dll) ÄÚǶTLSÐÅÈÎê(¸ÃĿ±겻º¬¿ͻ§¶Ë)=TLS-Vertrauensanker einbetten (Ziel ohne Client) +ÄÚǶTLSÐÅÈÎê(½öWindows¿ͻ§¶Ëģ°å֧³Ö)=TLS-Vertrauensanker einbetten (nur Windows-Clientvorlagen) ÄÚǶTLSÐÅÈÎê(¸ÃЭÒ鲻×ßTLS)=TLS-Vertrauensanker einbetten (Protokoll ohne TLS) ÄÚǶTLSÐÅÈÎê(·þÎñ¶ËδÆôÓÃTLS)=TLS-Vertrauensanker einbetten (Server-TLS aus) ÄÚǶ TLS ÐÅÈÎêʧ°ܣ¬ÒÑȡÏûÉú³É:=TLS-Vertrauensanker konnte nicht eingebettet werden, Generierung abgebrochen: diff --git a/server/2015Remote/lang/en_US.ini b/server/2015Remote/lang/en_US.ini index b22a536..1959684 100644 --- a/server/2015Remote/lang/en_US.ini +++ b/server/2015Remote/lang/en_US.ini @@ -2059,6 +2059,8 @@ MCPԶ Զ³̽»̸¿ª¹صĸ͝ÐèÖØÆô³ÌÐòÉúЧ¡£=Changes to the remote chat switch take effect after restart. ÆôÓüüÅ̼Ǽ£¨AI ²ɼ¯»÷¼ü£©=Enable keylogger (AI keystroke capture) ¼üÅ̼Ǽ¿ª¹صĸ͝ÐèÖØÆô³ÌÐòÉúЧ¡£=Changes to the keylogger switch take effect after restart. +ÆôÓÿͻ§¶ËÉú³ɣ¨AI Éú³ɿͻ§¶ËÎļþ£¬ҪÇóֻ¶Á¹أ©=Enable client build (AI generates client files; requires read-only mode off) +¿ͻ§¶ËÉú³ɿª¹صĸ͝ÐèÖØÆô³ÌÐòÉúЧ£»Ëü»¹»áд³ö´øÖ÷¿Øƾ¾ݵĿͻ§¶ËÎļþ£¬Çë½÷É÷¿ªÆô¡£=Changes to the client build switch take effect after restart; it also writes client files containing master credentials, so enable it with care. ÆôÓà HTTPS£¨±¾¶˿Úͬʱ½ÓÊÜ TLS Á¬½ӣ©=Enable HTTPS (this port also accepts TLS connections) HTTPS ¿ª¹ØÓë֤Êé·¾¶µĸ͝ÐèÖØÆô³ÌÐòÉúЧ¡£=Changes to the HTTPS switch and certificate paths take effect after restart. ֤Êé»ò˽ԿÎļþ²»´æÔڣ¬Çë¼ì²é·¾¶¡£=Certificate or private key file not found; check the path. @@ -2237,6 +2239,7 @@ MCP: ÄÚǶTLSÐÅÈÎê(Ê×Á¬¼´¼ÓÃÜ)=Embed TLS trust anchor (TLS on first connect) ÄÚǶTLSÐÅÈÎê(êÔÚServerDll.dllÀï)=Embed TLS trust anchor (use ServerDll.dll) ÄÚǶTLSÐÅÈÎê(¸ÃĿ±겻º¬¿ͻ§¶Ë)=Embed TLS trust anchor (no client code here) +ÄÚǶTLSÐÅÈÎê(½öWindows¿ͻ§¶Ëģ°å֧³Ö)=Embed TLS trust anchor (Windows client templates only) ÄÚǶTLSÐÅÈÎê(¸ÃЭÒ鲻×ßTLS)=Embed TLS trust anchor (protocol is not TLS) ÄÚǶTLSÐÅÈÎê(·þÎñ¶ËδÆôÓÃTLS)=Embed TLS trust anchor (server TLS is off) ÄÚǶ TLS ÐÅÈÎêʧ°ܣ¬ÒÑȡÏûÉú³É:=Failed to embed the TLS trust anchor, generation cancelled: diff --git a/server/2015Remote/lang/zh_TW.ini b/server/2015Remote/lang/zh_TW.ini index 876ae35..54159eb 100644 --- a/server/2015Remote/lang/zh_TW.ini +++ b/server/2015Remote/lang/zh_TW.ini @@ -2052,6 +2052,8 @@ MCPԶ Զ³̽»̸¿ª¹صĸ͝ÐèÖØÆô³ÌÐòÉúЧ¡£=ßh¶˽»Մé_êPµÄ׃¸üÐèÖØÐ†¢„ӳÌʽááÉúЧ¡£ ÆôÓüüÅ̼Ǽ£¨AI ²ɼ¯»÷¼ü£©=†¢ÓÃæI±Pӛ䛣¨AI ”Xȡ°´æI£© ¼üÅ̼Ǽ¿ª¹صĸ͝ÐèÖØÆô³ÌÐòÉúЧ¡£=æI±Pӛä›é_êPµĸĄÓÐèÖØÐ†¢„ӳÌʽ·½¿ÉÉúЧ¡£ +ÆôÓÿͻ§¶ËÉú³ɣ¨AI Éú³ɿͻ§¶ËÎļþ£¬ҪÇóֻ¶Á¹أ©=†¢Óÿ͑ô¶ËÉú³ɣ¨AI Éú³ɿ͑ô¶˙n°¸£¬ҪÇóΨ×xêPé]£© +¿ͻ§¶ËÉú³ɿª¹صĸ͝ÐèÖØÆô³ÌÐòÉúЧ£»Ëü»¹»áд³ö´øÖ÷¿Øƾ¾ݵĿͻ§¶ËÎļþ£¬Çë½÷É÷¿ªÆô¡£=¿͑ô¶ËÉú³Éé_êPµÄ׃¸üÐèÖØÐ†¢„ӳÌʽÉúЧ£»Ëü߀•þŒ‘³öާÖ÷¿ؑ{×CµĿ͑ô¶˙n°¸£¬Ո֔É÷é_†¢¡£ ÆôÓà HTTPS£¨±¾¶˿Úͬʱ½ÓÊÜ TLS Á¬½ӣ©=†¢Óà HTTPS£¨±¾ßB½Ӳºͬ•r½ÓÊÜ TLS ßB¾€£© HTTPS ¿ª¹ØÓë֤Êé·¾¶µĸ͝ÐèÖØÆô³ÌÐòÉúЧ¡£=HTTPS é_êPÅc‘{×C·�½µĸĄÓÐèÖ؆¢³ÌʽÉúЧ¡£ ֤Êé»ò˽ԿÎļþ²»´æÔڣ¬Çë¼ì²é·¾¶¡£=‘{×C»ò˽耙n°¸²»´æÔڣ¬Ո™z²é·�½¡£ @@ -2230,6 +2232,7 @@ MCP: ÄÚǶTLSÐÅÈÎê(Ê×Á¬¼´¼ÓÃÜ)=ƒÈǶTLSÐÅÈÎå^(Ê×ßB¼´¼ÓÃÜ) ÄÚǶTLSÐÅÈÎê(êÔÚServerDll.dllÀï)=ƒÈǶTLSÐÅÈÎå^(å^ÔÚServerDll.dllÑe) ÄÚǶTLSÐÅÈÎê(¸ÃĿ±겻º¬¿ͻ§¶Ë)=ƒÈǶTLSÐÅÈÎå^(ԓĿ˜˲»º¬¿͑ô¶Ë) +ÄÚǶTLSÐÅÈÎê(½öWindows¿ͻ§¶Ëģ°å֧³Ö)=ƒÈǶTLSÐÅÈÎå^(ƒHWindows¿͑ô¶Ëģ°å֧Ԯ) ÄÚǶTLSÐÅÈÎê(¸ÃЭÒ鲻×ßTLS)=ƒÈǶTLSÐÅÈÎå^(ԓ…f×h²»×ßTLS) ÄÚǶTLSÐÅÈÎê(·þÎñ¶ËδÆôÓÃTLS)=ƒÈǶTLSÐÅÈÎå^(·þ„նËδ†¢ÓÃTLS) ÄÚǶ TLS ÐÅÈÎêʧ°ܣ¬ÒÑȡÏûÉú³É:=ƒÈǶ TLS ÐÅÈÎå^ʧ”¡£¬ÒÑȡÏûÉú³É: diff --git a/tools/mcp_tools/README.md b/tools/mcp_tools/README.md index e0623cd..c9665a8 100644 --- a/tools/mcp_tools/README.md +++ b/tools/mcp_tools/README.md @@ -1,6 +1,6 @@ # MCP 工具清单维护 -`mcp/tools.json` 是 MCP 全部 61 个工具的**单一来源候选**:工具名、描述、 +`mcp/tools.json` 是 MCP 全部 55 个工具的**单一来源候选**:工具名、描述、 inputSchema、outputSchema,以及运行时不可见的开关元信息(`gate` / `write` / `manage`)。 它的用途不限于给 Go 服务端复用。当前 26KB 的工具描述埋在 11k 行 C++ 里, @@ -20,23 +20,28 @@ inputSchema、outputSchema,以及运行时不可见的开关元信息(`gate` ## 更新流程 -改动 C++ 里的工具定义(`McpServer.cpp` / `McpMachine.cpp` / `McpChat.cpp`)之后: +改动 C++ 里的工具定义(`McpServer.cpp` / `McpMachine.cpp` / `McpChat.cpp` / +`McpBuildClient.cpp`)之后: ```bash # 0. 先重编并启动主控端,确保服务端跑的是新代码 cd C:/github/YAMA # 1. 抓取(token 自动从注册表读;端口自动探测 6545/6544) -python tools/mcp_tools/dump_tools.py "" /tmp/tools_raw.json +# 清单是「McpMachine=1」与「McpMachine=0」两份抓取的并集,需在两次抓取之间 +# 改配置并重启服务端(关闭态那份包含 5 个降级工具)。 +python tools/mcp_tools/dump_tools.py "" /tmp/tools_raw_on.json +# ...把 McpMachine 改成 0、重启服务端... +python tools/mcp_tools/dump_tools.py "" /tmp/tools_raw_off.json -# 2. 生成 -python tools/mcp_tools/make_tools_json.py /tmp/tools_raw.json mcp/tools.json +# 2. 生成(第三参数是关闭主机管理时的抓取) +python tools/mcp_tools/make_tools_json.py /tmp/tools_raw_on.json mcp/tools.json /tmp/tools_raw_off.json # 3. 校验 python tools/mcp_tools/verify_tools.py --live mcp/tools.json ``` -第 3 步输出 `PASS: 61 个工具完全一致` 才算成功。 +第 3 步输出 `PASS: 55 个工具完全一致` 才算成功。 ### 如果工具数量变了 @@ -53,6 +58,7 @@ python tools/mcp_tools/verify_tools.py --live mcp/tools.json - `McpServer.cpp:BuildToolsListResult` —— 内联的 41 个 - `McpMachine.cpp:AppendTools` —— 16 个(总开关 `IsMachineEnabled` 用 early return) - `McpChat.cpp:AppendTools` —— 4 个(总开关 `IsChatEnabled` 用 early return) +- `McpBuildClient.cpp:AppendTools` —— 1 个(开关 `McpBuild` 用 early return) `PLATFORMS` 还要额外核对各平台客户端有没有实现对应命令,见下节。 @@ -60,8 +66,8 @@ python tools/mcp_tools/verify_tools.py --live mcp/tools.json | 字段 | 含义 | |---|---| -| `gate` | 该工具出现所需的开关(`null` = 无条件)。取值:`machine` / `chat` / `terminal` / `remote_control` / `file_transfer` / `file_write` / `keylog` / `manage` | -| `write` | 需要 `!McpReadonly` | +| `gate` | 该工具出现所需的开关(`null` = 无条件)。取值:`machine` / `chat` / `terminal` / `remote_control` / `file_transfer` / `file_write` / `keylog` / `manage` / `build` | +| `write` | 执行需要 `!McpReadonly`(只影响调用,不影响可见性;只改服务端本地数据的工具在只读下仍会列出) | | `manage` | 额外需要 `McpManage`(仅 `kill_network_connection` 用到) | | `platforms` | 该工具涉及的**任一主机**都必须落在此集合内:`win` / `lnx` / `mac` / `apk` | | `roles` | 仅多主机工具才有。按参数名细分平台,表达 `platforms` 说不清的方向性能力 | @@ -88,7 +94,7 @@ python tools/mcp_tools/verify_tools.py --live mcp/tools.json | 命令分支 | `client/`、`linux/main.cpp`、`macos/main.mm`、`android/app/src/main/cpp/main.cpp` | | 能力位 | `common/commands.h` 的 `LOGIN_INFOR::DefaultCaps()`;Linux 另在 `linux/main.cpp:RefreshLoginCaps` 追加 `SCREEN_PREVIEW` | -当前分布(54 个工具): +当前分布(55 个工具): | platforms | 数量 | 典型工具 | |---|---|---| @@ -191,7 +197,7 @@ macOS 客户端其实有对应实现(`macos/main.mm:753` 的 `ShellworkingThre ```bash python tools/mcp_tools/check_platform_table.py -# PASS: 61 个工具的 platforms 两边完全一致,且门禁都能拿到主机 id +# PASS: 55 个工具的 platforms 两边完全一致,且门禁都能拿到主机 id ``` ## 与 Go 服务端的关系 diff --git a/tools/mcp_tools/make_tools_json.py b/tools/mcp_tools/make_tools_json.py index ef937d6..8a94eeb 100644 --- a/tools/mcp_tools/make_tools_json.py +++ b/tools/mcp_tools/make_tools_json.py @@ -114,6 +114,9 @@ GATE = { "chat_send": ("chat", False, False), "chat_wait": ("chat", False, False), "chat_close": ("chat", False, False), + + # ---- 生成客户端(McpBuild,写服务端本机文件;另需 readonly 关)---- + "build_client": ("build", True, False), } # platforms: 该工具涉及的任一主机都必须落在此集合内。 @@ -160,6 +163,8 @@ PLATFORMS = { "mcp_cancel_session": _APK, "host_set_remark": _APK, "host_set_watch_level": _APK, + # 生成客户端只写服务端本机文件,不触达任何主机;与客户端平台无关。 + "build_client": _APK, # SYSTEM / LIST_DRIVE / QUERY_LOG:三个桌面平台都实现了;APK 也实现了 QUERY_LOG # (android/.../main.cpp ClientLogThread → TOKEN_REPORT_LOG)