Hacker News 中文摘要

RSS订阅

恶意Rust crate Arrayref运行构建时载荷 -- Malicious Rust crate Arrayref runs a build-time payload

文章摘要

2026年8月20日,流行Rust crate arrayref的0.3.10版本被植入恶意依赖proc-macro1,该依赖在编译时下载并执行远程二进制文件。恶意版本已被crates.io团队移除。

文章总结

2026年8月20日,知名Rust库arrayref在crates.io上发布了一个被篡改的版本0.3.10。该版本新增了对一个名为proc-macro1的拼写错误库的依赖,其构建脚本会在项目编译时下载并运行远程二进制文件。由于代码在构建时执行,因此只要编译包含该恶意版本的项目就会触发攻击。crates.io团队已移除这些恶意版本。

原始arrayrefappend-only-vec库由droundy维护,其账户疑似被盗。相关GitHub仓库已无法访问,包括github.com/droundy/arrayrefgithub.com/droundy/append-only-vec以及整个github.com/droundy账户均返回404错误。另一个名为dtolney的账户发布了proc-macro1,该用户名与David Tolnay的真实账户dtolnay极为相似,其元数据伪造了作者信息并指向一个不存在的仓库路径。

proc-macro1的构建脚本将服务器地址存储为base64片段,在构建时重新组装。解码后,这些片段产生有效载荷主机hxxps://23[.]254[.]165[.]112:9089/和命令控制地址23[.]254[.]165[.]112:443。脚本通过TLS连接获取特定架构的二进制文件,该连接接受任何证书而不进行验证,然后脱离构建过程运行。在Unix系统上,它会在/tmp/rust-setup位置释放并运行文件;在Windows系统上,它会在%TEMP%目录下写入PowerShell脚本和VBScript启动器,以隐藏方式运行,然后放弃子进程,使编译器无需等待。

攻击者通过撤回arrayref的旧版本(0.3.5至0.3.9),引导开发者使用唯一未被撤回的恶意版本0.3.10。arrayref作为传递性依赖被广泛使用,通过tiny-skiasctk-adwaitawinit等库深入常见的Rust依赖图,影响范围涵盖基于egui、eframe和iced构建的大多数GUI项目。该库历史下载量约2.45亿次,其中干净的0.3.9版本约占1.52亿次。

技术分析显示,arrayref 0.3.10仅在清单文件中添加了一行依赖proc-macro1,其源代码本身并无恶意。proc-macro1的源代码是proc-macro2的复制品,通过查找替换将名称改为proc-macro1,使其在正常构建中不易被察觉。恶意代码位于proc-macro1的构建脚本中,该脚本使用base64解码、TLS栈和HTTP客户端等依赖,在构建时下载并执行远程二进制文件。

评论总结

根据评论内容,总结如下:

主要观点与论据:

  1. 对Rust生态系统的批评(评分:无)

    • 评论指出Rust与JavaScript/Node生态类似,依赖数量庞大,易受供应链攻击。
    • 关键引用:"Rust seems barely better than Node in this regard." (评论5)
    • "Rust suffers from the same faults as the JS ecosystem. Any significant crate imports hundreds if not thousands of dependencies." (评论17)
  2. 呼吁加强安全措施(评分:无)

    • 建议对构建脚本进行沙箱化,限制恶意代码的传播范围。
    • 关键引用:"Cargo desperately needs sandboxing for build.rs scripts." (评论12)
    • "We should be building and testing everything in bubblewrap or some other sandbox." (评论1)
  3. 对包管理机制的质疑(评分:无)

    • 批评crates.io缺乏严格审核,允许未经安全审计的包上传。
    • 关键引用:"Why after many previous supply-chain attacks maintainers of package repositories still allow anyone uploading packages and pushing updates without security audit?" (评论2)
    • "I’m disappointed crates.io doesn’t have a stricter bar for serving a crate that has newly acquired a proc macro or build.rs." (评论9)
  4. 建议减少依赖、增强标准库(评分:无)

    • 主张语言应提供更丰富的标准库,减少对外部依赖的依赖。
    • 关键引用:"We should be taking a more 'batteries included' approach to language and library design." (评论16)
    • "Are there any plans to more seriously develop the standard library in Rust?" (评论13)
  5. 对开发环境的建议(评分:无)

    • 强调使用容器化开发环境,限制恶意代码的破坏范围。
    • 关键引用:"Doing software development outside of strict containerization... looks increasingly prone to disaster." (评论10)
    • "Use containers for development. And reduce the amount of third party deps you import into your projects." (评论14)

平衡性说明: - 评论中既有对Rust生态的批评,也有对改进措施的建议。 - 部分评论认为问题根源在于包管理文化,而非特定语言。 - 也有评论指出AI辅助生成代码可减少依赖,但未获广泛认可。