majiayu000/argus
GitHub: majiayu000/argus
Argus 是一个 Rust 编写的静态包扫描工具,在安装前检测 npm、PyPI 和 crates.io 包中的供应链攻击风险。
Stars: 2 | Forks: 0
# argus
[](https://github.com/majiayu000/argus/actions/workflows/ci.yml)
[](LICENSE)
`argus` 是一个 Rust CLI 工具,它能在任何生命周期脚本、`setup.py` 或 `build.rs` 执行之前,判断一个软件包(npm、PyPI sdist/wheel 或 `.crate` 归档)或 npm 锁定文件是否可以安全安装。它实现了确定性规则层以及可选的密码学来源验证——请参阅下方“状态”部分以了解当前能力快照。
## 决策
- **block** —— 至少一条高风险规则触发。
- **allow-with-approval** —— 仅触发已知的原生构建模式;需要明确批准。
- **allow** —— 没有规则触发。
## 使用方式
```
# Scan one local package directory
cargo run -p argus-cli -- scan corpus/fixtures/lifecycle-curl-sh
# Fetch a real npm package: packument -> tarball -> SHA-512 verify -> safe
# extract -> scan. No lifecycle script ever runs.
cargo run -p argus-cli -- fetch chalk@5.3.0
cargo run -p argus-cli -- fetch '@types/node@20.10.0' --format json
# Fetch a real PyPI package: JSON API -> sdist/wheel -> SHA-256 verify -> safe
# extract -> scan. setup.py never runs.
cargo run -p argus-cli -- pypi-fetch requests@2.31.0 --prefer wheel
cargo run -p argus-cli -- pypi-fetch django@5.0.0 --prefer both --format json
# Fetch a real crates.io crate: JSON API -> .crate -> SHA-256 verify -> safe
# extract -> scan. build.rs never runs.
cargo run -p argus-cli -- crates-fetch serde@1.0.228
cargo run -p argus-cli -- crates-fetch tokio --format json
# Custom registry that serves tarballs from a separate CDN/host:
cargo run -p argus-cli -- fetch internal-tool@1.2.3 \
--registry https://npm.corp.example \
--allow-tarball-host cdn.corp.example \
--allow-tarball-host objects.corp.example
# Run the full regression corpus (10 fixtures + 1 lockfile)
cargo run -p argus-cli -- corpus test
# Machine-readable output
cargo run -p argus-cli -- scan path/to/pkg --format json
```
编译后的二进制文件名为 `argus`,当决策为 `block` 时返回非零退出码。
## 规则覆盖范围(里程碑 0)
| 家族 | 规则 |
|----------|------|
| 生命周期 | `lifecycle-script`, `pre-scan-execution-marker` |
| 内容 | `remote-download`, `shell-pipe-execution`, `credential-access`, `network-exfiltration`, `binary-execution`, `runtime-hook`, `wallet-interception`, `token-harvest`, `github-write-api`, `npm-publish` |
| 二进制 | `binary-file` |
| 名称 | `typosquatting`, `low-reputation`, `dependency-confusion`, `public-registry-internal-name`, `known-native-build-pattern` |
| 锁定文件 | `lockfile-http-resolved`, `untrusted-registry-host` |
| 来源 | `missing-provenance`(信息), `provenance-verified-subject`(信息), `provenance-subject-mismatch`(阻止), `provenance-fetch-blocked` / `provenance-fetch-failed` / `provenance-parse-failed`(操作错误) |
| AI 上下文 | `ai-context-poisoning` — 写入 `.cursorrules`, `CLAUDE.md`, `.claude/*`, `AGENTS.md`, `.aider.conf.yml`, `.continuerules`, `.codexrules`, `.windsurfrules`。此模式由 TrapDoor 攻击活动(Socket.dev 2026-05-24)率先在大规模范围内应用。 |
## PyPI 规则覆盖范围(里程碑 1)
| 家族 | 规则 |
|--------|------|
| sdist 安装时 | `setup-py-execution`, `setup-subprocess`, `setup-remote-download`, `setup-eval` |
| wheel + sdist | `import-time-hook`(在模块加载时重写 `sys.modules` / `__builtins__`) |
| 结构 | `pypi-sdist-no-manifest`(信息) |
| 从 npm 规则移植(文件内容扫描) | `credential-access`, `ai-context-poisoning`, `runtime-hook`, `wallet-interception` |
| 名称 | 针对 60+ 个 Python 包名的 `typosquatting` |
## crates.io 规则覆盖范围(里程碑 1)
| 家族 | 规则 |
|--------|------|
| build.rs 编译时 | `build-rs-subprocess`(仅限 shell / curl / wget / 脚本解释器——纯 `Command::new("rustc")` 被列入白名单),`build-rs-network`,`build-rs-include-bytes`(二进制 blob + XOR 循环),`xor-decryption-loop` |
| 结构 | `build-rs-execution`(信息),`proc-macro-crate`(信息),`embedded-binary-blob`(信息) |
| 从 npm 规则移植(文件内容扫描) | `credential-access`,`ai-context-poisoning`,`runtime-hook` |
| 名称 | 针对 70+ 个 crate 名的 `typosquatting` |
## 项目结构
- `crates/argus-core` — 数据类型(`Decision`, `Finding`, `ScanReport`)。
- `crates/argus-rules` — 静态检测规则。
- `crates/argus-fetch` — npm 注册表客户端。
- `crates/argus-pypi` — PyPI 注册表客户端(sdist + wheel)。
- `crates/argus-crates` — crates.io 注册表客户端(.crate + build.rs)。
- `crates/argus-cli` — `argus` 二进制文件。
## 开发
每次克隆后启用一次 git 钩子,以避免 `cargo fmt` 不一致传递到 CI:
```
uv tool install pre-commit # or: pipx install pre-commit
pre-commit install # pre-commit stage: cargo fmt + file hygiene
pre-commit install -t pre-push # pre-push stage: cargo clippy -D warnings
```
CI 是权威的门控(`cargo fmt --check`、clippy、`cargo test`、`argus corpus test`);钩子仅提供更快的本地反馈。随时使用 `pre-commit run --all-files` 运行完整的本地集合。
## 状态
**预发布。** Argus 尚未作为标记版本发布或发布到任何包注册表。请从源代码针对 `main` 分支构建;我们将 `main` 视为发布分支,并将 [`CHANGELOG`](CHANGELOG.md) 中的 `[Unreleased]` 部分视为当前的发布清单。
能力快照(截至 2026-05-29):
- **M0** — 规则引擎 + 回归语料库 + CI([#4](https://github.com/majiayu000/argus/pull/4),[#5](https://github.com/majiayu000/argus/pull/5))。
- **M1** — npm tarball 获取 + 安全解包 + 扫描([#6](https://github.com/majiayu000/argus/pull/6)),外加 PyPI sdist/wheel([#23](https://github.com/majiayu000/argus/pull/23))和 crates.io `.crate` + `build.rs` 分析([#24](https://github.com/majiayu000/argus/pull/24))。
- **M2** — Sigstore 签名验证(DSSE + Fulcio 链 + Rekor 包含 + OIDC 身份白名单),需通过 `sigstore` Cargo 功能开启。关闭了 [#14](https://github.com/majiayu000/argus/issues/14);关于 M2 仍然不能防范的内容的诚实威胁披露位于 [`docs/design/sstore-verification.md`](docs/design/sigstore-verification.md) 第 10 节。
长尾生态系统覆盖范围(Maven / NuGet / Go 模块 / RubyGems / Packagist)在 [#22](https://github.com/majiayu000/argus/issues/22) 中跟踪;启动就绪度优化在 [#42](https://github.com/majiayu000/argus/issues/42) 中跟踪。
检测覆盖范围**不**会在没有基准证据的情况下以大标题数字宣称——请参阅 [`corpus/`](corpus/) 了解项目依赖的回归数据集,以及 [`docs/supply-chain-attacks.md`](docs/supply-chain-attacks.md) 了解 argus 设计应对的攻击目录。
标签:CLI, crates.io, lockfile扫描, npm, npm安全, PyPI, PyPI安全, Rust, Rust安全工具, WiFi技术, 云安全监控, 依赖扫描, 可视化界面, 恶意包检测, 文档安全, 文档结构分析, 暗色界面, 模型提供商, 网络流量审计, 软件供应链安全, 远程方法调用, 通知系统, 静态分析, 预安装检测