fix(client): MCP 客户端 session newbind 报 not found pipeline(附 svcgen 插件) - #100
Open
sss12365 wants to merge 2 commits into
Open
fix(client): MCP 客户端 session newbind 报 not found pipeline(附 svcgen 插件)#100sss12365 wants to merge 2 commits into
sss12365 wants to merge 2 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
修复通过 MCP 客户端执行
session newbind --pipeline <bind_pipeline> --target <ip:port>时报rpc error: code = Unknown desc = not found pipeline、bind 会话无法建立的问题。同一操作在 tui / webui 客户端正常。
Root Cause
session newbind是两步 RPC(client/command/sessions/new.go):Register注册会话 →InitBindSession驱动 listener dial 目标。失败发生在第二步:loadPipelineStreamForSession(server/rpc/generic.go:324)查找 listener 流,而
pipelinesCh的写入方(server/rpc/rpc-listener.go:86)只写listenerID/pipelineID复合键,命中查找要求
sess.ListenerID非空且与 listener 注册时一致。sess.ListenerID来自客户端注册时提交的RegisterSession.ListenerId(server/internal/core/session.go:112),但修复前客户端根本没有设置该字段 → 复合键不匹配、退化路径也被跳过 → 返回
ErrNotFoundPipeline。RegisterSession携带ListenerId,所以正常。旁证:失败时
Register成功、session_register事件正常发出,但 listener 从未收到 init 请求、从未发起 dial——与失败点在第二步完全吻合。Fix
唯一改动文件:
client/command/sessions/new.go(+22 / −0)Register时携带ListenerId: resolvePipelineListenerID(con, PipelineID)resolvePipelineListenerID:通过客户端缓存中已有的 pipeline→listener 映射(
common.FindCachedPipeline)自动解析,对用户透明、不改变 CLI 用法client/command/common设计取舍:
RegisterSession.ListenerId在 proto 中本就存在(第 3 字段),服务端原样落库,tui/webui 也依赖它工作——契约早已定义,是 MCP 客户端未履行;
改服务端兼容空值属于放大改动面。
ListenerId的兜底逻辑),不引入新的失败模式。
Test Plan
session newbind --pipeline <p> --target <ip:port>成功建立 bind 会话附:svcgen 插件(Windows 服务版 implant 生成工具)
svcgen 是一个 IoM mal(Lua)插件,作用是生成 Windows 服务版本的 implant(beacon):把「构建一次 → 按 C2 地址批量 patch」的流程固化为一条客户端命令,每个 C2 地址产出一个 exe,换 IP 不用重新编译。
命令用法
示例:
--srcwindows_service、模块等)与固定obf_seed--dst--addrs--wait产物
<dst>/base.exe— docker 全量编译的基础 beacon<dst>/svc_beacon_<ip_port>.exe— 每个地址一个变体(服务端模板 patch,秒级)执行流程(插件内部)
rpc.Build(Source=docker)全量编译 base exe(约 30-60 秒),轮询rpc.ListArtifact直到完成rpc.DownloadArtifact下载 base.exetargets.address与tls.sni→rpc.Build(Source=patch,模板 patch,约 1 秒)→ 下载通过 MCP 触发:
execute_command("svcgen --src ... --dst ... --addrs ... --wait");需要一个 active session(仅借用其 RPC context,对目标无操作)。部署方式
前置条件(一次性)
.malice/bin/malefic-mutant必须支持tool patch -i ... --from-implant(旧版不兼容)。注意 server 重启会还原该二进制,需重新替换<ServerRoot>/templates/下放带固定 obf_seed 的模板 exe,命名malefic-<transport>-<target>[.exe],如malefic-tcp_tls-x86_64-pc-windows-gnu.exe。建议同时放malefic-http_tls-...别名(pulse 段的http:会导致传输类型误判)obf_seed(patch 靠它派生 prefix 定位配置槽;随机 seed 的产物无法 patch),且含windows_service: true安装 / 更新插件
# 插件源为 svcgen/(mal.yaml + main.lua) cp -r svcgen /root/.config/malice/mals/svcgen常见问题
mutant tool failed: unexpected argument '-i'.malice/bin/malefic-mutant(备份旧版)implant.yaml is missing basic.obf_seedbasic:下加obf_seed: <固定整数>,重新构建基础 exetemplate not found for transport=http_tlshttp:导致传输类型误判malefic-http_tls-<target>.exe(可与 tcp_tls 同文件)prefix+seed pattern not found in binaryRoOriginateErrorW.cargo/config.toml的 windows-gnu rustflags 加"--cfg=windows_slim_errors"