seconize-co/dhi
GitHub: seconize-co/dhi
针对 AI Agent 的运行时安全防护系统,通过 HTTP 代理和 eBPF 技术实现凭证泄露、数据外泄、Prompt 注入等威胁的实时检测与拦截。
Stars: 0 | Forks: 0
# 🛡️ Dhi - AI Agents 运行时安全
**धी** (Sanskrit: *智力* | *感知* | *清晰视野*)
Dhi 是一个针对 AI agents 的**安全优先运行时保护系统**。它能在损害发生之前检测并阻止凭证泄露、PII(个人身份信息)暴露、prompt 注入和失控的成本消耗。
[](https://opensource.org/licenses/MIT)
[](https://www.rust-lang.org/)
[](https://kernel.org/)
## 为什么选择 Dhi?
AI agents 功能强大,但也引入了**严重的安全风险**:
| 威胁 | 影响 | Dhi 保护措施 |
|--------|--------|----------------|
| 🔓 **凭证泄露 (Credential Leakage)** | API keys 在日志/输出中暴露 | 实时检测与拦截 |
| 📤 **数据窃取 (Data Exfiltration)** | PII/机密信息被发送到外部 API | 出站流量扫描与脱敏 |
| 💸 **成本爆炸 (Cost Explosion)** | LLM 支出失控 | 预算限制与自动切断 |
| 🔄 **无限循环 (Infinite Loops)** | 卡住的 agent 持续消耗 tokens | 循环检测与终止 |
| 💉 **Prompt 注入 (Prompt Injection)** | 恶意指令劫持 agent | 攻击模式检测 |
| 🔓 **越狱攻击 (Jailbreaks)** | 通过社会工程学绕过安全限制 | 越狱特征匹配 |
**Dhi 监控 agent 的一举一动,并实时阻止威胁。**
## 安全功能
| 功能 | 描述 |
|---------|-------------|
| 🔐 **机密检测 (Secrets Detection)** | 支持 20 多种 API key 模式(OpenAI, AWS, GitHub, Stripe 等) |
| 🛡️ **PII 保护 (PII Protection)** | 检测并脱敏邮箱、SSN、信用卡、电话号码 |
| 💰 **预算控制 (Budget Control)** | 单 agent 和全局支出限制,具备自动拦截功能 |
| 🔍 **工具监控 (Tool Monitoring)** | 对每次工具调用进行风险评分,拦截危险操作 |
| 💉 **Prompt 安全 (Prompt Security)** | 注入和越狱检测,支持 30 多种攻击模式 |
| 📊 **Prometheus Metrics** | 22 个用于 Grafana dashboard 的安全指标 |
| 🚨 **实时告警 (Real-time Alerts)** | Slack、邮件和 webhook 集成 |
| 🐧 **eBPF 监控 (eBPF Monitoring)** | 内核级 syscall 追踪 (Linux) |
| 🔒 **HTTPS 拦截 (HTTPS Interception)** | 通过 eBPF uprobes 捕获 SSL/TLS 流量 (Linux) |
### 加固功能
| 保护措施 | 描述 |
|------------|-------------|
| 📏 **输入大小限制 (Input Size Limits)** | regex 扫描器最大限制 1MB(防止 ReDoS) |
| 🚦 **告警速率限制 (Alert Rate Limiting)** | 令牌桶算法(全局 30/分钟,单 agent 100/小时) |
| 🔄 **事件轮转 (Event Rotation)** | 最大 1 万事件的环形缓冲区(防止内存 DoS) |
| 🌐 **SSRF 保护 (SSRF Protection)** | 在代理中拦截私有 IP 和云 metadata endpoints |
| ⚡ **无 Panic (Panic-Free)** | 所有锁操作均优雅地处理中毒锁 |
## 快速开始
### 构建
```
cargo build --release
```
### 运行
```
# 开始监控并发送告警
./target/release/dhi --level alert --port 9090
# 通过 Slack 通知
./target/release/dhi --level alert --slack-webhook https://hooks.slack.com/...
# Demo 模式(查看实际功能演示)
./target/release/dhi demo
# Block 模式(主动防御威胁)
./target/release/dhi --level block
```
## 架构
```
┌─────────────────────────────────────────────────────────────────────────────┐
│ EXTERNAL SERVICES │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ OpenAI API │ │ Anthropic API│ │ Tools/MCP │ │
│ └──────▲───────┘ └──────▲───────┘ └──────▲───────┘ │
└────────────┼───────────────────┼───────────────────┼────────────────────────┘
│ │ │
│ HTTPS Traffic │
│ │ │
┌────────────┴───────────────────┴───────────────────┴────────────────────────┐
│ │
│ ╔═══════════════════════════════╗ │
│ ║ DHI SECURITY PROXY ║ │
│ ║ (HTTP Proxy + eBPF SSL) ║ │
│ ╚═══════════════════════════════╝ │
│ │
│ ┌────────────────────────────────────────────────────────────────────┐ │
│ │ SECURITY SCANNING │ │
│ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │ │
│ │ │ Secrets │ │ PII │ │ Prompt │ │ Tool │ │ │
│ │ │ Detection │ │ Detection │ │ Injection │ │ Risk │ │ │
│ │ │ (20+ types)│ │ & Redact │ │ Detection │ │ Assessment │ │ │
│ │ └─────────────┘ └─────────────┘ └─────────────┘ └─────────────┘ │ │
│ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │ │
│ │ │ Budget │ │ SSRF │ │ eBPF SSL │ │ │
│ │ │ Control │ │ Protection │ │ Intercept │ │ │
│ │ └─────────────┘ └─────────────┘ └─────────────┘ │ │
│ └────────────────────────────────────────────────────────────────────┘ │
│ │ │
│ ┌───────────────┼───────────────┐ │
│ │ ✋ BLOCK │ 🚨 ALERT │ 📝 LOG │ │
│ └───────────────┴───────────────┘ │
│ │ │
│ ┌──────────────────────┼──────────────────────┐ │
│ │ Slack │ Prometheus │ Webhook/SIEM │ │
│ └──────────────────────┴──────────────────────┘ │
│ │
└─────────────────────────────────────────▲───────────────────────────────────┘
│
HTTP_PROXY / eBPF Hooks
│
┌─────────────────────────────────────────┴───────────────────────────────────┐
│ AI AGENTS │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ Claude Code │ │ Copilot CLI │ │ LangChain │ │
│ │ │ │ │ │ CrewAI │ │
│ └──────────────┘ └──────────────┘ └──────────────┘ │
└─────────────────────────────────────────────────────────────────────────────┘
```
**工作原理:**
1. **AI Agents** 配置 `HTTP_PROXY=http://127.0.0.1:8080`(或者 Dhi 使用 eBPF hooks)
2. **Dhi 拦截** 所有发往 LLM API 的流量,充当安全代理
3. **安全检查** 扫描机密、PII、注入、高风险工具
4. **执行动作**:Block(拦截请求)、Alert(告警 + 放行)或 Log(仅记录)
5. **告警流转** 至 Slack、Prometheus metrics 或您的 SIEM
## 文档
| 文档 | 描述 |
|----------|-------------|
| [CTO 指南](docs/CTO_GUIDE.md) | 针对安全关切的执行指南 |
| [智能体功能](docs/AGENTIC_FEATURES.md) | 包含示例的完整 API 文档 |
| [对比分析](docs/COMPARISON.md) | Dhi 与其他工具的对比 |
| [品牌规范](docs/BRANDING.md) | 品牌指导方针 |
## 端点
运行时,Dhi 会暴露以下端口:
| 端点 | 描述 |
|----------|-------------|
| `GET /metrics` | Prometheus metrics |
| `GET /health` | 健康检查 |
| `GET /api/stats` | JSON 统计数据 |
| `GET /` | Web dashboard |
## 集成
### 作为库 (Library) 使用
```
use dhi::agentic::AgenticRuntime;
#[tokio::main]
async fn main() {
let runtime = AgenticRuntime::new();
// Register agent
runtime.register_agent("my-agent", "langchain", None).await;
// Track LLM calls
let result = runtime.track_llm_call(
"my-agent", "openai", "gpt-4",
500, 200, // tokens
Some("Hello world".to_string()),
false, vec![],
).await;
println!("Cost: ${:.4}, Risk: {}", result.cost_usd, result.risk_score);
// Track tool calls
let tool_result = runtime.track_tool_call(
"my-agent", "filesystem_read", "mcp",
serde_json::json!({"path": "/etc/passwd"}),
).await;
if !tool_result.allowed {
println!("Blocked: {:?}", tool_result.flags);
}
}
```
### 作为守护进程 (Daemon) 使用
```
# 作为后台服务运行
./dhi --level alert --port 9090 &
# Agents 通过 HTTP API 交互
curl -X POST http://localhost:9090/api/track/llm \
-H "Content-Type: application/json" \
-d '{"agent_id": "my-agent", "provider": "openai", "model": "gpt-4"}'
```
## 环境要求
- **Rust 1.75+** 用于构建
- **Linux** 用于 eBPF 内核监控(可选,kernel 5.4+)
- Agentic 安全功能可在所有平台上运行
## 项目结构
```
dhi/
├── Cargo.toml # Rust project configuration
├── src/
│ ├── main.rs # CLI entry point
│ ├── lib.rs # Library exports
│ ├── server.rs # HTTP/metrics server
│ ├── agentic/ # AI agent security modules
│ │ ├── mod.rs
│ │ ├── llm_monitor.rs
│ │ ├── tool_monitor.rs
│ │ ├── prompt_security.rs
│ │ ├── secrets_detector.rs
│ │ ├── pii_detector.rs
│ │ ├── budget.rs
│ │ ├── alerting.rs
│ │ ├── metrics.rs
│ │ └── ...
│ ├── ebpf/ # Kernel monitoring (Linux)
│ ├── detection/ # Risk scoring engine
│ └── monitor/ # Statistics collection
├── docs/ # Documentation
└── README.md
```
## 许可证
MIT License - 详见 [LICENSE](LICENSE)
## 贡献
欢迎贡献!请阅读行为准则并提交 PRs。
由 [Seconize](https://seconize.co) 使用 Rust 构建
标签:AMSI绕过, API安全, API集成, DLP, DNS 反向解析, Docker镜像, JSONLines, JSON输出, PII检测, Rust, SQLite数据库, 人工智能安全, 人工智能安全, 内核监控, 可观测性, 可视化界面, 合规性, 合规性, 威胁检测, 数据脱敏, 时间线生成, 私有化部署, 系统防护, 网络安全, 网络流量审计, 自定义请求头, 越狱检测, 运行时保护, 通知系统, 防御规避, 隐私保护, 零信任, 预算控制