Skip to main content
Glama

Purifier - 原型链污染审计 MCP 服务器

Purifier 是一个专注于原型链污染漏洞审计的 MCP工具。它通过识别 Sources、Sinks、Gadgets 和 Pollution Patterns 来分析 JavaScript/TypeScript 项目中的原型链污染风险。

特性

  • 四类检测模式:Sources(污染源)、Sinks(传播点)、Gadgets(利用点)、Pollution(显式污染)

  • 攻击链分析:自动分析 Sources → Sinks → Gadgets 的关联性

  • 严重性评级:CRITICAL、HIGH、MEDIUM、LOW、INFO 五级分类

  • 并行扫描:支持多线程并行扫描大型项目

  • 配置灵活:YAML 配置文件和环境变量支持

Related MCP server: audit-mcp-cli

漏洞检测类别

类别

描述

示例模式

Sources

用户输入入口点

req.body、req.query、location.search

Sinks

危险的合并/赋值操作

Object.assign、lodash.merge、merge()

Gadgets

原型链利用的小工具

outputFunctionName、EJS.compile

Pollution

显式的原型操作

__proto__、constructor.prototype

安装

pip install -r requirements.txt

使用

运行服务器

python server.py

与 Claude Desktop 集成

{
  "mcpServers": {
    "purifier": {
      "command": "python",
      "args": ["D:\\project\\Purifier\\server.py"]
    }
  }
}

工具说明

核心工具

工具

描述

quick_audit(path)

完整原型链污染审计 + 攻击链分析

analyze_pollution_chain(path)

专门分析攻击链(Sources→Sinks→Gadgets)

scan_by_category(path, category)

按类别扫描(source/sink/gadget/pollution)

scan_by_severity(path, min_severity)

按严重性过滤

list_project_files(path)

列出可扫描文件

read_code_context(file_path, line_number, context_lines)

读取代码上下文

兼容性工具

工具

描述

find_sources(path)

扫描用户输入入口点

find_sinks(path)

扫描危险合并函数

find_pollution_patterns(path)

扫描显式污染模式

find_gadgets(path)

扫描可利用的小工具

配置

在项目根目录创建 config.yaml:

# 文件扩展名
extensions:
  - .js
  - .ts
  - .jsx
  - .tsx

# 排除目录
exclude_dirs:
  - node_modules
  - vendor
  - dist
  - build

# 排除文件
exclude_files:
  - "*.min.js"
  - "*.bundle.js"

# 最大文件大小(字节)
max_file_size: 1048576

# 并行扫描
parallel: true
max_workers: 4

# 启用/禁用类别
enabled_categories:
  source: true      # 用户输入
  sink: true        # 危险操作
  gadget: true      # 利用点
  pollution: true   # 显式污染

# 日志级别
log_level: WARNING

# 输出格式(markdown、json)
output_format: markdown

环境变量

变量

描述

PURIFIER_MAX_FILE_SIZE

最大文件大小

PURIFIER_MAX_WORKERS

并行工作线程数

PURIFIER_PARALLEL

是否启用并行扫描

PURIFIER_LOG_LEVEL

日志级别

攻击链分析

Purifier 会自动分析潜在的原型链污染攻击链:

用户输入 (SOURCE)
    ↓
危险的合并操作 (SINK)
    ↓
原型被污染
    ↓
可利用的小工具 (GADGET)
    ↓
远程代码执行 (RCE)

风险评级

  • 🚨 CRITICAL: 完整的攻击链存在(Source + Sink + Gadget)

  • ⚠️ HIGH: 原型污染可能(Source + Sink)或显式污染

  • ℹ️ MEDIUM: 只发现 Sink,需验证输入清理

  • ✅ LOW: 无明显风险

常见漏洞示例

Lodash.merge 污染

// 危险:用户输入直接传入 merge
const _ = require('lodash');
app.post('/merge', (req, res) => {
    const merged = _.merge({}, req.body);  // 原型链污染!
    res.json(merged);
});

Object.assign 污染

// 危险:目标为空对象时
app.post('/assign', (req, res) => {
    const config = Object.assign({}, req.body);  // 可能污染!
    res.json(config);
});

EJS RCE via 原型污染

// 如果原型被污染,EJS 可导致 RCE
const ejs = require('ejs');
// 污染: Object.prototype.outputFunctionName = "_tmp1;global.process.mainModule.require('child_process').exec('calc');//"
app.post('/render', (req, res) => {
    ejs.render('template', req.body);  // RCE!
});

测试

# 安装开发依赖
pip install -r requirements-dev.txt

# 运行测试
pytest tests/

# 带覆盖率报告
pytest tests/ --cov=purifier

项目结构

Purifier/
├── purifier/
│   ├── __init__.py       # 包导出
│   ├── models.py         # 数据模型
│   ├── patterns.py       # 检测模式(原型链污染专用)
│   ├── scanner.py        # 核心扫描器
│   └── config.py         # 配置管理
├── tests/
│   ├── __init__.py
│   └── test_scanner.py   # 单元测试
├── server.py             # MCP 服务器
├── config.yaml           # 配置文件
├── requirements.txt      # 依赖
├── CLAUDE.md            # Claude Code 指南
└── README.md            # 本文件

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers