DeepScan-Security/dscan

GitHub: DeepScan-Security/dscan

dscan 是面向 AI Agent 的开源安全套件,提供运行时拦截、静态扫描、MCP 供应链审计、多步攻击序列分析和主动对抗测试,帮助开发者在上线前发现并修复 Agent 安全漏洞。

Stars: 2 | Forks: 0

# dscan [![CI](https://static.pigsec.cn/wp-content/uploads/repos/2026/06/193dc53d2a172501.svg)](https://github.com/DeepScan-Security/dscan/actions/workflows/ci.yml) ![覆盖率](https://img.shields.io/badge/coverage-96%25-brightgreen) [![PyPI](https://img.shields.io/pypi/v/dscan-security)](https://pypi.org/project/dscan-security/) [![Python](https://img.shields.io/pypi/pyversions/dscan-security)](https://pypi.org/project/dscan-security/) ![许可证](https://img.shields.io/badge/license-MIT-green) 面向 AI agent 的安全套件。 ``` pip install dscan-security ``` ## 快速开始 ``` from dscan import watch @watch async def my_agent(task: str): # your agent code unchanged ... ``` ``` dscan dashboard # localhost:4321 — see every tool call dscan scan . # check before you ship dscan audit . # check your MCP servers dscan attack agent.py # test like an attacker would ``` ## dscan 能检测到什么 | 模块 | 检测内容 | 方式 | |--------|----------------|-----| | `dscan watch` | 每次 MCP 工具调用 — 包括参数、结果、时序、参数中的机密信息 | Runtime 装饰器 | | `dscan secrets` | trace 在被记录之前的 API key、PII、凭据 | 正则表达式 + 熵 | | `dscan scan` | system prompt 和 MCP 配置中的危险模式 | 静态分析 | | `dscan shield` | 实时的 prompt 注入和越狱尝试 | LlamaFirewall + 正则表达式 | | `dscan trail` | 在单次调用级别不可见的多步攻击 | 序列分析 | | `dscan attack` | 您线上 agent 中的漏洞 — 61 种对抗性 payload | 主动测试 | | `dscan audit` | 被投毒的、权限过高的或受 CVE 影响的 MCP 服务器 | 供应链扫描 | ## 命令 ### dscan watch ``` from dscan import watch, TrailAnalyzer, ShieldMiddleware @watch # minimal — just intercept and log async def my_agent(task: str): ... @watch(trail=TrailAnalyzer(), shield=ShieldMiddleware()) async def my_agent(task: str): ... # full protection ``` ### dscan scan ``` dscan scan . # scan current directory dscan scan ./agent.py # scan one file dscan scan --prompt system_prompt.txt # scan a system prompt ``` 查找:过宽的权限、注入向量、硬编码的 机密信息、危险的 MCP 配置模式。 如果存在 HIGH 级别的发现则退出码为 1。 ### dscan audit ``` dscan audit # auto-discovers mcp.json dscan audit .cursor/mcp.json # explicit config dscan audit . --fail-on critical # CI mode dscan audit . --server filesystem # one server only ``` 检查:工具投毒、权限过高、未锁定的版本、 已知的 CVE (CVE-2025-6514, CVE-2025-53967)、影子工具。 如果发现的问题达到或高于 --fail-on 阈值则退出码为 1。 ### dscan trail ``` dscan trail ~/.dscan/traces/ # analyse existing traces dscan trail traces/ --min-severity high dscan trail traces/ --json # machine-readable output ``` 检测:EXFIL_SEQUENCE、RECON_WALK、INJECTION_RELAY、 DATA_STAGING、GOAL_DRIFT。 ### dscan shield ``` dscan shield --setup # download models dscan shield check "some input text" # test a string dscan shield check "text" --offline # regex only, no model dscan shield status # show configuration ``` 需要:pip install dscan-security[shield] ### dscan attack ``` dscan attack agent.py # auto-discovers tools dscan attack --url http://localhost:8080/chat dscan attack agent.py --categories prompt_injection,jailbreak dscan attack agent.py --max-payloads 10 --ci ``` **pytest 集成:** ``` from dscan.attack import attack_suite def test_agent_security(): report = attack_suite(target=my_agent) assert report.critical_count == 0 assert report.high_count == 0 ``` 攻击类别:prompt_injection、jailbreak、tool_misuse、 indirect_injection、goal_hijacking、privilege_escalation。 如果发现的问题达到或高于 --fail-on(默认:high)则退出码为 1。 ### dscan dashboard ``` dscan dashboard # opens localhost:4321 dscan dashboard --port 4322 # custom port dscan dashboard --no-open # don't open browser ``` 三个标签页:Traces(实时工具调用)、Attack Reports、 Audit Reports。 ## CI/CD 集成 ``` # .github/workflows/security.yml - name: Install dscan run: pip install dscan-security - name: Audit MCP servers run: dscan audit . --fail-on high --ci - name: Attack test agent run: | python agent.py & sleep 2 dscan attack --url http://localhost:8080 \ --categories prompt_injection,jailbreak \ --fail-on high \ --ci ``` ## 工作原理 dscan 在装饰器层拦截 MCP 工具调用, 分析它们的安全模式,并将 trace 本地存储在 ~/.dscan/。除非您 选择加入云端 trace(Team 版本),否则任何数据都不会离开您的机器。 ## 安装 ``` pip install dscan-security # core (all 7 modules) pip install dscan-security[shield] # + LlamaFirewall models ``` 需要 Python 3.11+。 ## 贡献 请参阅 CONTRIBUTING.md。运行测试:pytest tests/ -v ## 许可证 MIT — 由 DeepScan (deepscan.security) 构建
标签:AI安全, Chat Copilot, CISA项目, LNA, Python, StruQ, 动态运行防护, 大模型应用安全, 安全测试, 安全规则引擎, 攻击性安全, 无后门, 逆向工具, 静态代码扫描