skishu0413/Securing-the-Software-Supply-Chain
GitHub: skishu0413/Securing-the-Software-Supply-Chain
一款多生态系统软件供应链安全分析工具,为 Python、Node.js 和 Java 项目提供依赖漏洞检测、六维度风险评分及供应链威胁识别。
Stars: 0 | Forks: 0
# 保障软件供应链安全
一款多生态系统安全分析工具,用于检测 Python、Node.js 和 Java 项目中的漏洞与供应链威胁。结合实时漏洞情报与自适应威胁检测,为您提供准确、可操作的风险评估。
[](https://github.com/skishu0413/Securing-the-Software-Supply-Chain/actions/workflows/ci.yml)
[](https://www.python.org)
[](LICENSE)
## 功能简介
- 扫描依赖文件(`requirements.txt`、`package-lock.json`、`pom.xml`)以查找已知漏洞
- 查询 **OSV** 和 **NVD** 数据库,对结果进行去重,并使用 CVSS 分数进行丰富
- 检测供应链威胁 —— 域名抢注、依赖混淆、废弃包、元数据不良
- 采用 6 维度评估方法,按 0–100 的风险等级对每个易受攻击的包进行评分
- 将结果输出到终端、JSON 或 CSV
## 支持的生态系统
| 生态系统 | 输入文件 |
|-----------|-----------|
| Python | `requirements.txt` / 任意 pip requirements 文件 |
| Node.js | `package-lock.json` |
| Java | `pom.xml` |
## 安装说明
**环境要求:** Python 3.9+,网络连接
```
git clone https://github.com/skishu0413/Securing-the-Software-Supply-Chain.git
cd Securing-the-Software-Supply-Chain
python3 -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install -r requirements-dev.txt
```
## 快速开始
```
# Python 项目
python3 src/main.py requirements.txt --type pypi
# Node.js 项目
python3 src/main.py package-lock.json --type npm
# Java Maven 项目
python3 src/main.py pom.xml --type maven
```
### 使用示例测试文件
```
python3 src/main.py test_files/comprehensive_requirements.txt --type pypi
python3 src/main.py test_files/package-lock.json --type npm
python3 src/main.py test_files/pom.xml --type maven
```
## 输出格式
```
# 默认终端输出
python3 src/main.py requirements.txt --type pypi
# JSON 导出
python3 src/main.py requirements.txt --type pypi --format json --output report.json
# CSV 导出
python3 src/main.py requirements.txt --type pypi --format csv --output report
# 每个包的详细风险明细
python3 src/main.py requirements.txt --type pypi --verbose-risk
# 显示风险评分方法
python3 src/main.py --show-methodology
```
## 示例输出
### 漏洞报告

### 可疑包报告

```
--- Vulnerability Report ---
📦 Dependency: cryptography@1.9.0
Overall Severity: CRITICAL | Risk Score: 100/100
📈 Risk Breakdown → Severity:32 | Exploit:20 | Exposure:9 | Volume:9 | Patch:0 | Credibility:4
💡 Recommendation: Upgrade to version 41.0.0 or later
Vulnerabilities:
- ID: CVE-2020-36242 | SOURCE: NVD | Advisory: https://nvd.nist.gov/vuln/detail/CVE-2020-36242
- ID: CVE-2023-0286 | SOURCE: NVD, OSV | Advisory: https://osv.dev/vulnerability/GHSA-3ww4-gg4f-jr7f
📊 Risk Summary:
🔴 Critical : 3 packages (Score ≥ 85)
🟠 High : 5 packages (Score 65–84)
🟡 Medium : 4 packages (Score 35–64)
🟢 Low : 2 packages (Score < 35)
📈 Total vulnerable dependencies: 14
```
```
--- Suspicious Package Report ---
- Typosquatting (2 packages):
📦 requuests: 94% similar to 'requests'
📦 flasks: 91% similar to 'flask'
- Dependency Confusion (1 package):
📦 internal-auth: Package not found on public pypi registry.
- Abnormal Update Frequency (3 packages):
📦 pip-requirements-parser: Not updated since 2022 (abandoned).
Total suspicious dependencies found: 6
```
## 风险评分
每个易受攻击的包都会基于六个加权维度获得一个 0 到 100 的评分:
```
Score = Base Severity (35%) + Exploit Pressure (25%) + Exposure Context (15%)
+ Volume (10%) + Patch Gap (10%) + Credibility (5%)
```
| 维度 | 权重 | 衡量内容 |
|-----------|--------|-----------------|
| 基础严重程度 | 35% | CVSS 分数、严重性分布、CVE 年龄 |
| 漏洞利用压力 | 25% | CISA KEV 状态、EPSS 分数、攻击向量 |
| 暴露上下文 | 15% | 包类型(网络库、解析器、加密库等) |
| 数量 | 10% | 漏洞数量,经过对数缩放处理 |
| 补丁差距 | 10% | 是否有可用的修复方案 |
| 可信度 | 5% | 来源声誉和参考质量 |
权重可以在 `src/config.yaml` 中进行完全配置。
## 供应链威胁检测
扫描器会检查每个包是否存在以下情况:
- **域名抢注** —— 通过模糊名称相似度与已知的流行包进行比对
- **依赖混淆** —— 包在内部存在但公共注册表中不存在
- **废弃包** —— 超过 2 年未更新
- **元数据不良** —— 缺少描述、无主页、无作者
- **异常版本控制** —— 异常过高或不符合 PEP 440 标准的版本字符串
随着扫描器从每次扫描中学习,检测阈值会随时间自适应调整。
## 性能表现
在没有 API key 的情况下,NVD 强制限制速率为每 30 秒 5 次请求。对于庞大的依赖列表,这会显著增加耗时。免费的 API key 可以将限制提升至每 30 秒 50 次请求,从而大幅缩短扫描时间。
```
# 在以下地址获取免费密钥:https://nvd.nist.gov/developers/request-an-api-key
export NVD_API_KEY="your-api-key-here"
```
扫描器还维护着一个持久的磁盘缓存(`cache/`),其 TTL(生存时间)为 24–72 小时,因此在之前扫描中出现过的包不需要再次进行网络请求往返。
大致扫描时间:
| 项目规模 | 无 API key | 有 API key |
|-------------|----------------|--------------|
| < 20 个依赖 | 30–60秒 | 10–20秒 |
| 20–100 个依赖 | 2–5 分钟 | 30–90秒 |
| 100+ 个依赖 | 5–15 分钟 | 1–3 分钟 |
## 配置说明
所有设置均位于 `src/config.yaml` 中。主要选项:
```
# NVD 速率限制
nvd:
request_delay_without_key: 6.0 # seconds between requests (no key)
request_delay_with_key: 0.6 # seconds between requests (with key)
min_cvss_score: 3.0 # ignore CVEs below this threshold
# 风险评分权重(总和必须为 100)
risk_weights:
base_severity: 35
exploit_pressure: 25
exposure_context: 15
volume: 10
patch_gap: 10
credibility: 5
# 漏洞年龄加权
risk_scoring:
very_recent_vuln_days: 30 # CVEs newer than this get a score boost
very_recent_boost: 0.2 # +20%
```
## 运行测试
```
pytest tests/ -v
```
测试涵盖了解析器、风险评分器和 NVD 检查器,结合了基于属性的测试和标准单元测试。CI 会在每次推送和拉取请求时,在 Python 3.9 和 3.11 环境下运行。
## 项目结构
```
.
├── src/
│ ├── main.py # CLI entry point and scan orchestration
│ ├── config.py / config.yaml # Configuration
│ ├── dependency_parser/ # Parsers for requirements.txt, package-lock.json, pom.xml
│ ├── vulnerability_checker/ # OSV and NVD API integration
│ ├── risk_scorer/ # 6-component risk scoring engine
│ ├── suspicious_package_detector/ # Supply chain threat detection
│ └── threat_analysis/ # Adaptive learning and pattern detection
├── tests/ # Unit and property-based tests
├── test_files/ # Sample dependency files for manual testing
├── cache/ # Runtime API cache (not committed to git)
├── requirements-dev.txt # Python dependencies
├── pyproject.toml # Project metadata
└── .github/workflows/ci.yml # CI pipeline
```
## 故障排除
**扫描速度非常慢**
请设置 `NVD_API_KEY` —— 参见上文的[性能表现](#performance)。
**来自 NVD 的速率限制警告**
在没有 API key 的情况下属于正常现象。扫描器会自动退避。设置该 key 即可完全避免此问题。
**出现 `WARNING: Malformed CVSS vector` 消息**
这些是被静默跳过的 CVSS v4.0 向量,`cvss` 库尚不支持。这些 CVE 的分数将改从 NVD 的数字 `baseScore` 字段获取。不会丢失任何数据。
**包显示为可疑,但实际上是合法的**
自适应检测器会随着每次扫描不断改进。如果误报持续存在,请提交一个 issue。
## 许可证
MIT
标签:DevSecOps, Python, WebSocket, 上游代理, 依赖分析, 域名收集, 安全规则引擎, 无后门, 软件供应链安全, 远程方法调用, 逆向工具