code-audit-mcp

code-audit-mcp

Enables automated security code auditing using LLM and MCP, including AST parsing, taint analysis, dataflow tracing, and automated PoC generation for multi-language codebases.

Category
Visit Server

README

Code Audit MCP Server

基于大语言模型(LLM)与模型上下文协议(MCP)的自动化代码审计工具。

功能特性

  • 代码语义解析:AST解析、类型推导、污点标记
  • 调用链追踪:跨文件/跨模块的数据流追踪
  • 漏洞验证:自动生成PoC并执行验证
  • 多语言支持:PHP、Python、Java、JavaScript/TypeScript

快速开始

环境要求

  • Node.js >= 18.0
  • TypeScript >= 5.0
  • Cursor / Windsurf(支持MCP的IDE)

安装

git clone https://github.com/kkk1259/code-audit-mcp.git
cd code-audit-mcp
npm install
npm run build

配置

在Cursor中配置MCP Server:

// .cursor/mcp.json
{
  "mcpServers": {
    "code-audit": {
      "command": "node",
      "args": ["./dist/server.js"],
      "env": {
        "PROJECT_ROOT": "/path/to/your/project"
      }
    }
  }
}

使用示例

SQL注入审计

用户: 请审计这个项目的SQL注入漏洞

AI: 我将使用MCP工具进行系统性审计。
    首先,识别所有用户输入源和SQL执行点...

反序列化漏洞挖掘

用户: 检查是否存在反序列化漏洞

AI: 我将分析项目中的unserialize调用,并追踪POP链...

工具列表

工具名 功能 参数
parse_ast 解析源码AST file: 文件路径
find_callers 查找函数调用者 funcName: 函数名, maxDepth: 最大深度
trace_dataflow 追踪数据流 source: 源, sink: 汇
generate_poc 生成漏洞PoC vulnType: 漏洞类型, params: 参数

项目结构

code-audit-mcp/
├── src/
│   ├── server.ts          # MCP Server入口
│   ├── tools/
│   │   ├── parser.ts      # AST解析
│   │   ├── callgraph.ts   # 调用链追踪
│   │   ├── verifier.ts    # 漏洞验证
│   │   └── poc.ts         # PoC生成
│   ├── rules/
│   │   ├── php.json       # PHP安全规则
│   │   ├── python.json    # Python安全规则
│   │   └── java.json      # Java安全规则
│   └── utils/
│       ├── taint.ts       # 污点分析
│       └── sanitizer.ts   # 过滤函数识别
├── prompts/
│   ├── audit-system.md    # 系统Prompt
│   └── vuln-types/        # 各漏洞类型Prompt
├── tests/
├── package.json
└── README.md

最佳实践

✅ 做

  • 分模块审计,不要一次喂入整个项目
  • 先跑静态工具获取可疑点,再用AI深入分析
  • 为每个漏洞类型准备专用Prompt
  • 审计前先让AI了解项目结构(入口、路由、数据库)
  • 人工复核AI报告,特别是"高危"发现
  • 保存审计历史,用于Prompt迭代优化

❌ 不要做

  • 不要盲目信任AI报告,误报不可避免
  • 不要在Prompt中描述过于复杂的审计逻辑
  • 不要跳过漏洞验证环节
  • 不要在敏感项目中使用云端API(用本地模型)
  • 不要忽略业务逻辑漏洞(AI对此较弱)

效果预期

漏洞类型 召回率 准确率
注入类漏洞 80%+ 75%+
反序列化 POP链发现能力超过人工 -
逻辑漏洞 仍需人工审计为主 -

整体效率:提升3-5倍(含人工复核时间)

开源协议

MIT License

相关文章

贡献

欢迎提交Issue和PR!

联系方式

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured