AI Security AI安全 1d ago Updated 1d ago 更新于 1天前 46

Rust Supply Chain Attack Puts Build-Time Malware in Crates with 245 Million Downloads Rust 供应链攻击:构建时恶意软件植入下载量达 2.45 亿的 Crates

A compromised Rust maintainer account published malicious versions of three widely used crates (arrayref, internment, append-only-vec) that injected a typosquatted dependency (proc-macro1) with a build-time malware payload The attack exploited Cargo's build script execution model, requiring no direct usage of the compromised crate—simply building a dependent project was sufficient to trigger the payload The malicious build script disabled TLS validation, installed a stage-2 implant that beaconed Rust生态遭遇供应链攻击,三个高下载量crate(arrayref、internment、append-only-vec)被植入构建时恶意代码,总下载量达2.45亿 攻击者通过typosquat依赖(proc-macro1伪装proc-macro2)在构建脚本中注入恶意载荷,利用yank操作绕过Cargo版本警告 恶意代码在编译时执行,跨平台(Windows/macOS/Linux)窃取浏览器凭据并建立持久化后门,无实际使用证据 Rust安全响应团队在86-107分钟内删除恶意版本,建议开发者锁定旧版本并清理本地缓存

75
Hot 热度
65
Quality 质量
55
Impact 影响力

Analysis 深度分析

TL;DR

  • A compromised Rust maintainer account published malicious versions of three widely used crates (arrayref, internment, append-only-vec) that injected a typosquatted dependency (proc-macro1) with a build-time malware payload
  • The attack exploited Cargo's build script execution model, requiring no direct usage of the compromised crate—simply building a dependent project was sufficient to trigger the payload
  • The malicious build script disabled TLS validation, installed a stage-2 implant that beaconed to a C2 server, persisted across platforms, and stole browser credentials from Chrome, Brave, and Edge
  • The compromised arrayref crate had accumulated over 245 million downloads with 403 dependent crates, making this one of the most impactful supply chain attacks in the Rust ecosystem
  • The Rust Security Response Team removed the malicious versions within 86-107 minutes, but no patched versions or CVE identifiers have been assigned

Why It Matters

This incident demonstrates the critical vulnerability of package manager build systems to supply chain attacks, where malicious code can be injected through seemingly innocuous dependency resolution rather than direct code execution. For AI practitioners and developers working with Rust-based tooling, this highlights the importance of monitoring build-time dependencies and understanding that compile-time code execution represents a significant attack surface that extends far beyond runtime vulnerabilities.

Technical Details

  • The attack used proc-macro1, a typosquat of the legitimate proc-macro2 crate, with identical library source but a malicious build script that reassembled C2 addresses from base64 fragments at build time
  • The build script installed a custom certificate verifier that unconditionally accepted all TLS certificates, then deployed platform-specific payloads: Unix/macOS wrote to /tmp/rust-setup and spawned it detached, while Windows used a PowerShell script launched through VBScript to escape Cargo's job object
  • The stage-2 implant established persistence through Registry Run keys (Windows), LaunchAgents (macOS), and systemd user services (Linux), supporting commands for termination, C2 reconfiguration, persistence management, and script execution
  • Attackers yanked versions 0.3.5-0.3.9 of arrayref simultaneously with publishing the malicious 0.3.10, making it the only non-yanked version and bypassing Cargo's update warnings
  • The dependency chain winit → sctk-adwaita → tiny-skia → arrayref demonstrated how transitive dependencies with caret version ranges (^0.3.x) could resolve to the compromised version without explicit developer knowledge

Industry Insight

  • Organizations using Rust should implement strict dependency pinning policies and regularly audit build scripts in their dependency trees, particularly for widely-used crates with millions of downloads that serve as critical infrastructure
  • Package maintainers should enable two-factor authentication and consider implementing signed releases or attestation mechanisms to detect unauthorized version publishes, as credential compromise remains the primary attack vector
  • The Rust ecosystem would benefit from enhanced build script scrutiny mechanisms, such as mandatory build script signing or sandboxed execution environments, to reduce the blast radius of similar supply chain attacks in the future

TL;DR

  • Rust生态遭遇供应链攻击,三个高下载量crate(arrayref、internment、append-only-vec)被植入构建时恶意代码,总下载量达2.45亿
  • 攻击者通过typosquat依赖(proc-macro1伪装proc-macro2)在构建脚本中注入恶意载荷,利用yank操作绕过Cargo版本警告
  • 恶意代码在编译时执行,跨平台(Windows/macOS/Linux)窃取浏览器凭据并建立持久化后门,无实际使用证据
  • Rust安全响应团队在86-107分钟内删除恶意版本,建议开发者锁定旧版本并清理本地缓存

为什么值得看

此次攻击揭示了开源生态供应链安全的脆弱性,构建时恶意代码的隐蔽执行方式对依赖管理提出严峻挑战。事件凸显了typosquat攻击和依赖链传播风险,为AI开发者提供了供应链防御的实战案例。

技术解析

  • Typosquat依赖注入:攻击者创建proc-macro1(模仿主流proc-macro2),其构建脚本在编译时重组base64编码的C2地址,禁用TLS验证并下载恶意载荷
  • 跨平台载荷执行:Unix/macOS写入/tmp/rust-setup执行,Windows通过PowerShell+VBScript隐藏进程,均绕过Cargo作业对象控制
  • 依赖链传播:通过winit→sctk-adwaita→tiny-skia→arrayref的依赖链,403个crate受影响,caret版本范围(^0.3.x)自动接受恶意版本
  • 防御规避技术:攻击者同步yankarrayref 0.3.5-0.3.9,使Cargo的"考虑更新"警告成为诱导下载恶意版本的诱饵
  • 持久化与数据窃取:Stage-2后门通过Registry Run/LaunchAgent/systemd服务持久化,窃取Chrome/Brave/Edge的SQLite登录数据库

行业启示

  • 依赖管理策略升级:关键项目需实施依赖版本锁定(如Cargo.lock严格提交),对高频更新crate建立变更监控机制
  • 构建环境安全加固:CI/CD流水线应启用构建脚本沙箱执行和出站流量监控,检测异常C2通信模式
  • 开源生态防御协作:建立crate下载量阈值预警(如>1000万下载自动审计),推动注册表平台增强yank操作的可追溯性

Disclaimer: The above content is generated by AI and is for reference only. 免责声明:以上内容由 AI 生成,仅供参考。

Security 安全 Open Source 开源