Gorakhnath-R-Patil/Lynx
GitHub: Gorakhnath-R-Patil/Lynx
Lynx 是一款服务端实时 AI Agent 攻击检测平台,通过事件驱动架构和多模块协同,识别 API 行为异常、AI Agent 指纹、认证滥用和 CI/CD 恶意注入,填补传统 WAF 无法检测 AI 编程 Agent 攻击的空白。
Stars: 1 | Forks: 0
# Lynx — 实时 AI Agent 攻击检测平台
[](https://github.com/Gorakhnath-R-Patil/Lynx/actions/workflows/ci.yml)
[](LICENSE)
[](https://openjdk.org/projects/jdk/17/)
[](https://spring.io/projects/spring-boot)
[](#running-tests)
## 问题背景
AI 编程 Agent(LangGraph, CrewAI, AutoGen, GPT-4 function calling)可以自主探测 API、暴力破解 OAuth 流程,并将恶意代码注入 Pull Request —— 全天候 24/7 以机器速度运行。它们看起来不像机器人,也不像人类。标准的 WAF 和 SIEM 会完全漏掉它们。
**现有工具无法填补这一空白:**
| 工具 | 功能 | 缺失点 |
|------|-------------|----------------|
| CrowdStrike / SentinelOne | Endpoint + SIEM | 非 AI 攻击专用;昂贵 |
| Fingerprint.com | 浏览器指纹识别 | 无法看到服务端 API 模式 |
| PentestGPT / CAI | 进攻型 AI | 它们是攻击方 —— 不负责防御 |
| 速率限制器 | 减缓请求速度 | 无法检测 *Agent 身份* 或攻击战役模式 |
**Lynx 填补了这一空白:服务端、Kafka 原生、事件驱动的 AI 攻击检测。**
## Lynx 的功能
- **识别 AI Agent 指纹**,通过分析请求时序、Header 模式和 Payload 结构(模块 2)
- **检测异常 API 行为**,在 8 维特征向量上使用 Isolation Forest 算法(模块 1)
- **捕获认证滥用** —— OAuth 速率、撞库、不可能的移动、Token 突发(模块 3a)
- **扫描 CI/CD 提交**,实时检测注入的漏洞和供应链攻击(模块 3b)
- **关联多模块攻击**,将其归纳为攻击战役并进行 MITRE ATT&CK 映射(模块 4)
- **自动响应** —— WAF 规则注入、PagerDuty/Slack 告警、会话失效
## 架构
```
┌─────────────────────────────────────────────────────────────┐
│ INGESTION LAYER │
│ API Gateway Logs │ Auth Events │ CI/CD Hooks │ Git Commits │
└──────────┬────────┴──────┬──────┴──────┬──────┴────┬─────────┘
│ │ │ │
▼ ▼ ▼ ▼
┌─────────────────────────────────────────────────────────────┐
│ KAFKA EVENT BUS │
│ api.requests auth.events git.commits threat.scores │
│ agent.classifications threat.campaigns (+ DLQ topics) │
└──────────┬──────────┬────────┬──────────┬──────────┬─────────┘
│ │ │ │ │
▼ ▼ ▼ ▼ ▼
┌──────────┐ ┌──────────┐ ┌──────┐ ┌──────┐ ┌──────────────┐
│ Module 1 │ │ Module 2 │ │Mod 3a│ │Mod 3b│ │ Module 4 │
│ API │ │ Agent │ │ Auth │ │CI/CD │ │ Lateral │
│Behavioral│ │Fingerprint│ │Anom. │ │ Scan │ │ Correlator │
│Detector │ │ Engine │ │ │ │ │ │ │
└──────────┘ └──────────┘ └──────┘ └──────┘ └──────────────┘
│ │ │
▼ ▼ ▼
┌─────────────────────────────────────────────────────────────┐
│ RESPONSE + OBSERVABILITY │
│ WAF Rule Injection │ PagerDuty/Slack Alerts │ Forensic Reports│
│ Grafana Dashboard │ WebSocket Live Feed │ Prometheus Metrics │
└─────────────────────────────────────────────────────────────┘
│ │ │
▼ ▼ ▼
┌──────────────┐ ┌──────────────┐ ┌───────┐
│ PostgreSQL │ │Elasticsearch │ │ Redis │
│ + pgvector │ │ (threats) │ │(cache)│
└──────────────┘ └──────────────┘ └───────┘
```
## 模块
| # | 模块 | 端口 | 检测内容 | 消费来源 | 生产输出 |
|---|--------|------|---------|----------|----------|
| 1 | `lynx-api-detector` | 8081 | 异常 API 请求模式 | `api.requests` | `threat.scores` |
| 2 | `lynx-agent-fingerprint` | 8082 | AI Agent 身份 (15 维特征, XGBoost) | `api.requests` | `agent.classifications` |
| 3a | `lynx-auth-anomaly` | 8083 | OAuth 滥用, 撞库, 不可能的移动 | `auth.events` | `threat.scores` |
| 3b | `lynx-cicd-scanner` | 8084 | 恶意代码注入, 供应链投毒 | `git.commits` | `threat.scores` |
| 4 | `lynx-lateral-correlator` | 8085 | 多模块攻击战役, MITRE ATT&CK 映射 | `threat.scores`, `agent.classifications` | `threat.campaigns` |
| — | `lynx-dashboard` | 8080 | 实时 WebSocket 威胁源 | `threat.scores`, `threat.campaigns` | — |
## 技术栈
| 层级 | 技术 |
|-------|-----------|
| 语言 | Java 17 |
| 框架 | Spring Boot 3.2.5 |
| 流处理 | Apache Kafka 3.7 + Kafka Streams |
| 机器学习 (ML) | Tribuo 4.3.1 (Isolation Forest + XGBoost) |
| 缓存 | Redis 7 (通过 Spring Data 使用 Lettuce) |
| 搜索 | Elasticsearch 8.13 |
| 向量数据库 | pgvector (战役向量搜索) |
| 数据库 | PostgreSQL 16 + Flyway 迁移 |
| 可观测性 | Prometheus + Grafana 10 |
| 容器 | Docker Compose (开发) + Helm 3 (k8s) |
| CI | GitHub Actions |
## 快速开始
### 前置条件
- Docker + Docker Compose
- Java 17
- Maven 3.9+
### 1. 启动基础设施
```
cd infrastructure/docker
docker-compose up -d
```
这将启动:Kafka + Zookeeper, Redis, PostgreSQL (pgvector), Elasticsearch, Prometheus, Grafana。
等待约 30 秒,让 `kafka-init` 创建所有 Topic。
### 2. 构建所有模块
```
./mvnw clean install -DskipTests
```
### 3. 运行服务
```
# 终端 1 — API Detector (阶段 1)
cd lynx-api-detector && ../mvnw spring-boot:run
# 终端 2 — Agent Fingerprint (阶段 2)
cd lynx-agent-fingerprint && ../mvnw spring-boot:run
# 终端 3 — Auth Anomaly (阶段 3a)
cd lynx-auth-anomaly && ../mvnw spring-boot:run
# 终端 4 — CI/CD Scanner (阶段 3b)
cd lynx-cicd-scanner && ../mvnw spring-boot:run
# 终端 5 — Lateral Correlator (阶段 4)
cd lynx-lateral-correlator && ../mvnw spring-boot:run
# 终端 6 — Dashboard (WebSocket feed)
cd lynx-dashboard && ../mvnw spring-boot:run
```
### 4. 访问服务
| 服务 | URL |
|---------|-----|
| Dashboard WebSocket | `ws://localhost:8080/ws` (STOMP) |
| Grafana | http://localhost:3000 (admin / sentinel) |
| Prometheus | http://localhost:9090 |
| API Detector REST | http://localhost:8081/api/v1/threats |
| CI/CD Webhooks | `POST http://localhost:8084/api/v1/webhooks/github` |
### 5. 连接实时威胁源
```
const socket = new SockJS('http://localhost:8080/ws');
const stompClient = Stomp.over(socket);
stompClient.connect({}, () => {
// Live threat scores
stompClient.subscribe('/topic/threats', msg => console.log(JSON.parse(msg.body)));
// Attack campaigns
stompClient.subscribe('/topic/campaigns', msg => console.log(JSON.parse(msg.body)));
});
```
## Kubernetes (Helm)
```
# 使用默认值安装
helm install lynx helm/lynx/
# 使用自定义 Registry
helm install lynx helm/lynx/ \
--set global.imageRegistry=your-registry.io/ \
--set postgres.password=your-secure-password
```
## 运行测试
```
# 所有单元测试
./mvnw test -pl lynx-common,lynx-agent-fingerprint,lynx-auth-anomaly,lynx-cicd-scanner,lynx-lateral-correlator
# 单个模块
./mvnw test -pl lynx-cicd-scanner
```
**测试摘要**:129+ 单元测试,0 失败。
## 检测能力
### 模块 1 — API 行为检测器
- 使用 8 维特征向量隔离具有异常请求模式的会话
- 特征包括:请求间隔、Endpoint 熵、Payload 相似度、Header 稳定性、遍历线性度、速率、Payload 大小方差、User-Agent 一致性
### 模块 2 — Agent 指纹识别
- 将会话分类为 HUMAN / AGENT_CLAUDE / AGENT_GPT / AGENT_GEMINI / AGENT_LANGCHAIN / AGENT_UNKNOWN
- 15 维特征向量:语言学 (5) + 结构 (5) + 时序 (5)
- 置信度阈值:0.7 —— 低于阈值返回 AGENT_UNKNOWN
### 模块 3a — 认证异常检测器
五个带有加权复合评分的检测器:
| 检测器 | 权重 | 捕获内容 |
|----------|--------|----------------|
| OAuth 速率 | 25% | 在 < 1.5s 内完成 OAuth 流程的机器人 |
| 凭证变异 | 25% | 编辑距离聚类 (Levenshtein ≤ 3) |
| 会话并行度 | 20% | 每用户 > 3 个并发会话 |
| Token 复用突发 | 15% | 60s 内 3 次以上 Token 刷新 |
| 不可能的移动 | 15% | 请求间移动速度 > 900 km/h |
### 模块 3b — CI/CD 扫描器
在 git diff 中检测八种漏洞模式:
`WEAKENED_CRYPTO` · `HARDCODED_CREDENTIALS` · `SQL_INJECTION` · `INSECURE_CORS` · `UNSAFE_DESERIALIZATION` · `PATH_TRAVERSAL` · `COMMAND_INJECTION` · `SSRF`
此外:供应链拼写伪造检测 (Levenshtein ≤ 2,对比 18 个流行软件包) 和 AI 生成代码指纹识别。
### 模块 4 — 横向移动关联器
- 按会话、IP(30 分钟窗口)和 Agent 指纹关联所有模块的事件
- 构建具有 MITRE ATT&CK 阶段映射(8 种战术)的攻击战役
- 复合战役风险评分:`maxScore×0.6 + module_diversity×0.3 + mitre_phases×0.2 + event_count×0.1`
- 当评分 ≥ 0.7 时,将 `ForensicReport` 发布到 `threat.campaigns`
## 可观测性
位于 http://localhost:3000 的 Grafana Dashboard 显示:
- 每秒处理事件数
- 异常评分分布 (p50 / p95 / p99)
- 检测延迟
- 按风险级别划分的威胁 (CRITICAL / HIGH / MEDIUM)
- 风险级别环形图
所有服务均暴露 `/actuator/prometheus` 供 Prometheus 抓取。
## 安全
请通过 [GitHub Security Advisories](https://github.com/Gorakhnath-R-Patil/Lynx/security/advisories/new) 私下报告漏洞。参见 [SECURITY.md](SECURITY.md)。
## 许可证
Apache 2.0 —— 参见 [LICENSE](LICENSE)。
标签:AI安全, AI智能体, AMSI绕过, Apex, API安全, API监控, Chat Copilot, CI/CD安全, CISA项目, DevSecOps, DNS 解析, IP 地址批量处理, Isolation Forest, JSON输出, Kafka, Llama, Modbus, OAuth, PE 加载器, SonarQube插件, Spring Boot, WAF替代, 上游代理, 事件驱动架构, 域名枚举, 威胁检测, 子域名突变, 实时攻击检测, 异常检测, 搜索引擎查询, 文档安全, 服务器端安全, 机器人检测, 机器学习, 欺诈检测, 测试用例, 网络安全, 自动化威胁防御, 自定义请求头, 请求拦截, 身份认证安全, 软件成分分析, 隐私保护