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
This commit is contained in:
yuanyuanxianganddeepseek-flash committed 2026-11-15 20:43:28 +01:00
1 parent 1401ff0a4c
commit 7172ab376d
20 files changed
+1619 -36

No files matched your search

+135
View File
@@ -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_<pid>_<tick>.exe` 释放,测后无残留,也不会与对话框的固定 `upx.exe` 抢文件。
- `mcp/tools.json` 已用 Debug 实例的 `McpMachine=1` / `McpMachine=0` 两份抓取重新生成
(55 个工具),`check_platform_table.py` PASS。
+20
View File
@@ -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`)。
+230 -2
View File
@@ -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 过滤)。",
+2
View File
@@ -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(
@@ -330,6 +330,7 @@
<ClInclude Include="McpServer.h" />
<ClInclude Include="McpTlsProxy.h" />
<ClInclude Include="McpChat.h" />
<ClInclude Include="McpBuildClient.h" />
<ClInclude Include="McpInternal.h" />
<ClInclude Include="McpMachine.h" />
<ClInclude Include="McpSettingsDlg.h" />
@@ -403,6 +404,7 @@
<ClCompile Include="McpServer.cpp" />
<ClCompile Include="McpTlsProxy.cpp" />
<ClCompile Include="McpChat.cpp" />
<ClCompile Include="McpBuildClient.cpp" />
<ClCompile Include="McpInternal.cpp" />
<ClCompile Include="McpMachine.cpp" />
<ClCompile Include="McpSettingsDlg.cpp" />
@@ -92,6 +92,7 @@
<ClCompile Include="HostJson.cpp" />
<ClCompile Include="McpServer.cpp" />
<ClCompile Include="McpChat.cpp" />
<ClCompile Include="McpBuildClient.cpp" />
<ClCompile Include="McpInternal.cpp" />
<ClCompile Include="McpMachine.cpp" />
<ClCompile Include="McpSettingsDlg.cpp" />
@@ -210,6 +211,7 @@
<ClInclude Include="TriggerSettingsDlg.h" />
<ClInclude Include="McpServer.h" />
<ClInclude Include="McpChat.h" />
<ClInclude Include="McpBuildClient.h" />
<ClInclude Include="McpInternal.h" />
<ClInclude Include="McpMachine.h" />
<ClInclude Include="McpSettingsDlg.h" />
+94 -20
View File
@@ -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<Old> + 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();
}
+10 -1
View File
@@ -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;
File diff suppressed because it is too large. Load diff
+34
View File
@@ -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 <string>
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
+3
View File
@@ -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
+19 -3
View File
@@ -11,6 +11,7 @@
#include "McpInternal.h" // 共享助手(McpMachine.cpp 也使用)
#include "McpMachine.h" // 主机管理 / 连接管理工具族
#include "McpChat.h" // 远程交谈工具族
#include "McpBuildClient.h" // 生成客户端工具族(build_client)
#include <sstream>
#include <fstream>
@@ -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);
+8
View File
@@ -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 字段对应。
+12
View File
@@ -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);
+2
View File
@@ -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;
+3
View File
@@ -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:
+3
View File
@@ -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:
+3
View File
@@ -2052,6 +2052,8 @@ MCPԶ
远程交谈开关的改动需重启程序生效。=遠端交談開關的變更需重新啟動程式後生效。
启用键盘记录(AI 采集击键)=啟用鍵盤記錄(AI 擷取按鍵)
键盘记录开关的改动需重启程序生效。=鍵盤記錄開關的改動需重新啟動程式方可生效。
启用客户端生成(AI 生成客户端文件,要求只读关)=啟用客戶端生成(AI 生成客戶端檔案,要求唯讀關閉)
客户端生成开关的改动需重启程序生效;它还会写出带主控凭据的客户端文件,请谨慎开启。=客戶端生成開關的變更需重新啟動程式生效;它還會寫出帶主控憑證的客戶端檔案,請謹慎開啟。
启用 HTTPS(本端口同时接受 TLS 连接)=啟用 HTTPS(本連接埠同時接受 TLS 連線)
HTTPS 开关与证书路径的改动需重启程序生效。=HTTPS 開關與憑證路徑的改動需重啟程式生效。
证书或私钥文件不存在,请检查路径。=憑證或私鑰檔案不存在,請檢查路徑。
@@ -2230,6 +2232,7 @@ MCP:
内嵌TLS信任锚(首连即加密)=內嵌TLS信任錨(首連即加密)
内嵌TLS信任锚(锚在ServerDll.dll里)=內嵌TLS信任錨(錨在ServerDll.dll裡)
内嵌TLS信任锚(该目标不含客户端)=內嵌TLS信任錨(該目標不含客戶端)
内嵌TLS信任锚(仅Windows客户端模板支持)=內嵌TLS信任錨(僅Windows客戶端模板支援)
内嵌TLS信任锚(该协议不走TLS)=內嵌TLS信任錨(該協議不走TLS)
内嵌TLS信任锚(服务端未启用TLS)=內嵌TLS信任錨(服務端未啟用TLS)
内嵌 TLS 信任锚失败,已取消生成:=內嵌 TLS 信任錨失敗,已取消生成:
+16 -10
View File
@@ -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 服务端的关系
+5
View File
@@ -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)