DgHnG36/ioc-enrich-system

GitHub: DgHnG36/ioc-enrich-system

基于微服务架构的IoC管理与威胁情报富化平台,通过多源情报自动关联赋能安全分析与事件响应。

Stars: 0 | Forks: 0

# IoC 富化系统 一个基于微服务的 **入侵指标 管理与威胁情报富化** 平台。该系统通过 REST API 网关和基于 gRPC 的服务间通信,实现了 IoC 的自动化摄取、多源威胁情报富化以及威胁关联。 ## 架构 ``` ┌──────────┐ REST ┌──────────────────┐ gRPC ┌───────────┐ gRPC ┌────────────────┐ │ Client │ ──────────────> │ ioc-api-gateway │ ──────────────> │ ioc-core │ ──────────────> │ ti-enrichment │ │ │ <────────────── │ (Go / Gin) │ <────────────── │ (Go) │ <────────────── │ (Python) │ └──────────┘ JSON │ :8080 │ Proto │ :50051 │ Proto │ :50052 │ └──────────────────┘ └───────────┘ └────────────────┘ │ │ │ │ │ │ ▼ ▼ ▼ ┌─────────┐ ┌────────────┐ ┌──────────────────┐ │ Redis │ │ PostgreSQL │ │ External TI APIs │ │ :6379 │ │ :5432 │ │ VT, AbuseIPDB, │ └─────────┘ └────────────┘ │ OTX, HybridAnaly │ └──────────────────┘ ``` ### 服务 | Service | Language | Port | Description | | ------------------- | ------------- | ----- | ------------------------------------------------------- | | **ioc-api-gateway** | Go (Gin) | 8080 | REST API, JWT auth, rate limiting, CORS | | **ioc-core** | Go (gRPC) | 50051 | IoC/Threat CRUD, enrichment orchestration, statistics | | **ti-enrichment** | Python (gRPC) | 50052 | Multi-source TI enrichment with caching & rate limiting | ### 技术栈 - **Languages**: Go 1.24, Python 3.12 - **Communication**: gRPC + Protocol Buffers, REST (Gin) - **Database**: PostgreSQL 15 - **Cache**: Redis 7 - **Infrastructure**: Docker, Kubernetes (Kustomize), GitHub Actions CI - **Testing**: Go testing, pytest, k6 (load/stress) ## 功能特性 ### IoC 管理 - 批量 upsert IoC (IP, domain, hash, URL, file path) - 支持分页的搜索与过滤 - 从威胁情报源自动富化 - 过期追踪与检测计数 ### 威胁情报 - 批量 upsert 威胁信息及 TTP 映射 - IoC-威胁关联与链接 - 威胁统计与分析 ### 富化数据源 - **VirusTotal** — 文件 Hash、URL、Domain、IP 分析 - **AbuseIPDB** — IP 信誉与滥用报告 - **AlienVault OTX** — 基于 Pulse 的威胁情报 - **Hybrid Analysis** — 基于沙箱的文件分析 ### 平台 - JWT 认证(支持可配置密钥) - 基于 Redis 的 rate limiting - gRPC 健康检查与 keepalive - 基于 singleflight 模式的内存统计缓存 - 针对高吞吐量的批量数据库操作 ## 快速开始 ### 前置条件 - Docker & Docker Compose - Go 1.24+ - Python 3.12+ - (可选) [k6](https://k6.io/) 用于性能测试 - (可选) [minikube](https://minikube.sigs.k8s.io/) 用于本地 Kubernetes ### 使用 Docker Compose 运行 ``` # 克隆 repository git clone https://github.com/DgHnG36/ioc-enrich-system.git cd ioc-enrich-system # 启动所有 services docker compose up -d --build # 验证健康状态 curl http://localhost:8080/health ``` ### 环境变量 复制并修改 `docker-compose.yaml` 中的 API keys: ``` VIRUSTOTAL_API_KEY: your_key_here ABUSEIPDB_API_KEY: your_key_here OTX_API_KEY: your_key_here HYBRID_ANALYSIS_API_KEY: your_key_here ``` ## API 参考 Base URL: `http://localhost:8080` 所有受保护的端点都需要 `Authorization: Bearer ` 请求头。 ### 健康检查 ``` GET /health # Liveness GET /ready # Readiness (checks downstream services) ``` ### IoC 端点 ``` POST /api/v1/iocs/batch # Batch upsert IoCs GET /api/v1/iocs/:id # Get IoC by ID GET /api/v1/iocs/value/:value # Get IoC by value POST /api/v1/iocs/find # Search/filter IoCs DELETE /api/v1/iocs # Delete IoCs GET /api/v1/iocs/stats # IoC statistics GET /api/v1/iocs/expired # Get expired IoCs POST /api/v1/iocs/enrich # Enrich an IoC ``` ### 威胁端点 ``` POST /api/v1/threats/batch # Batch upsert threats GET /api/v1/threats/:id # Get threat by ID POST /api/v1/threats/find # Search/filter threats DELETE /api/v1/threats # Delete threats GET /api/v1/threats/stats # Threat statistics POST /api/v1/threats/correlate # Correlate threat with IoCs POST /api/v1/threats/link # Link IoCs to threat POST /api/v1/threats/unlink # Unlink IoCs from threat ``` ### 富化端点 ``` POST /api/v1/enrichment/enrich # Enrich indicator POST /api/v1/enrichment/batch # Batch enrichment POST /api/v1/enrichment/health # Check TI source health ``` ## 项目结构 ``` ioc-enrich-system/ ├── services/ │ ├── ioc-api-gateway/ # REST API Gateway (Go/Gin) │ ├── ioc-core/ # Core gRPC service (Go) │ └── ti-enrichment/ # TI Enrichment gRPC service (Python) ├── shared/ │ ├── go/ # Generated Go protobuf code │ └── python/ # Generated Python protobuf code ├── proto/ # Protobuf definitions │ ├── ioc/v1/ # IoC & Threat service protos │ └── enrichment/v1/ # Enrichment service protos ├── infrastructure/ │ └── k8s/ # Kubernetes manifests (Kustomize) │ ├── base/ # Base manifests │ └── overlays/ # Environment-specific (dev, production) ├── init/ │ └── init.sql # Database schema ├── test/ │ ├── unit/ # Unit tests (Go + Python) │ ├── integration/ # Integration tests │ ├── e2e/ # End-to-end workflow tests │ └── performance/ # k6 load & stress tests ├── .github/workflows/ # CI pipelines ├── docker-compose.yaml # Local development └── Makefile # Root build commands ``` ## 开发 ### 生成 Protobuf 代码 ``` # 生成 Go 和 Python make proto # 仅生成 Go make go # 仅生成 Python make python ``` ### 运行测试 ``` # 单元测试(所有 services) make test # 从 test 目录: cd test # 单元测试 make test-unit # 集成测试(需要运行 services) make test-integration # 性能测试(需要 k6) make test-performance-load make test-performance-stress ``` ## Kubernetes 部署 ### 本地 (minikube) ``` # 启动 minikube minikube start --memory=4096 --cpus=4 # 使用 minikube 的 Docker 构建 images eval $(minikube docker-env) docker build -t ioc-api-gateway:latest -f services/ioc-api-gateway/Dockerfile . docker build -t ioc-core:latest -f services/ioc-core/Dockerfile . docker build -t ti-enrichment:latest -f services/ti-enrichment/Dockerfile . # 更新 infrastructure/k8s/base/secrets.yaml 中的 secrets # 部署 kubectl apply -k infrastructure/k8s/overlays/dev/ # 检查状态 kubectl get pods -n ioc-enrich # 访问 gateway minikube service ioc-api-gateway -n ioc-enrich ``` ### 生产环境 ``` kubectl apply -k infrastructure/k8s/overlays/production/ ``` ## CI 流水线 GitHub Actions CI 流水线 (`.github/workflows/ci.yml`) 在每次 push/PR 时运行: ``` Lint & Quality ──┐ ├──> Build Docker Images ──> Integration Tests Unit Tests ──────┘ │ └──> Push to GHCR (on main/develop) Security Scan ─────────────────────────────── ``` | Stage | Description | | --------------- | -------------------------------------------- | | **Lint** | golangci-lint (Go), flake8 + black (Python) | | **Unit Tests** | Go race detector, pytest with coverage | | **Build** | Multi-stage Docker builds, GHCR push | | **Integration** | Full docker-compose stack with health checks | | **Security** | govulncheck (Go), bandit + safety (Python) | ## 数据库模式 系统使用 5 个主要表: - **iocs** — 入侵指标 (IP, domain, hash, URL, file path) - **threats** — 威胁行为体、攻击活动、恶意软件家族 - **ioc_relations** — IoC 之间的关系 - **threat_ioc_correlation** — IoC-威胁关联 - **enrichment_cache** — 缓存的富化结果 查看 [init/init.sql](init/init.sql) 获取完整模式。 ## 贡献者 - **DgHnG36** — [github.com/DgHnG36](https://github.com/DgHnG36) ## 许可证 本项目仅供教育和研究目的使用。
标签:API 网关, Educational Security, EVTX分析, Gin, Golang, gRPC, IoC, Python, Python工具, Redis, REST API, XML 请求, 失陷指标, 威胁分析, 威胁情报, 子域名突变, 安全实验室, 安全开发, 安全编程, 开发者工具, 情报富化, 情报收集, 搜索引擎查询, 无后门, 日志审计, 测试用例, 漏洞研究, 自动化侦查工具, 请求拦截, 逆向工具