joemunene-by/ghostsiem

GitHub: joemunene-by/ghostsiem

一款基于 Python 的轻量级 SIEM,提供日志采集、检测与告警,专注蓝队自动化安全监控。

Stars: 0 | Forks: 0

# GhostSIEM 适用于 Linux 系统的轻量级安全信息与事件管理(SIEM)。 ![Python 3.10+](https://img.shields.io/badge/python-3.10%2B-blue) ![License: MIT](https://img.shields.io/badge/license-MIT-green) ![CI](https://github.com/ghostsiem/ghostsiem/actions/workflows/ci.yml/badge.svg) ## 架构 ``` +------------------+ +---------------+ +------------------+ | Collectors | | Normalizer | | Detection | | +---->+ +---->+ Engine | | syslog | | IP extract | | | | auth.log | | severity | | SIGMA rules | | JSON files | | GeoIP stub | | threshold | +------------------+ +---------------+ | field matching | +--------+---------+ | +-------------------------+ | +---------v---------+ +------------------+ | Alert Manager | | Storage | | | | | | dedup / rate | | SQLite + WAL | | console | | events table | | file (JSONL) | | alerts table | | webhook | +------------------+ +-------------------+ | +------v-----------+ | REST API | | | | GET /events | | GET /alerts | | GET /stats | | GET /health | +------------------+ ``` ## 快速开始 ``` # 安装 pip install ghostsiem # 列出内置检测规则 ghostsiem rules list --builtin # 启动所有内容(收集器 + 检测 + API) ghostsiem run --config examples/config.yaml ``` ## 安装 ### 从 PyPI 安装 ``` pip install ghostsiem ``` ### 从源码安装 ``` git clone https://github.com/ghostsiem/ghostsiem.git cd ghostsiem pip install -e ".[dev]" ``` ## CLI 命令 | 命令 | 描述 | |------|------| | `ghostsiem collect --config config.yaml` | 启动日志收集器 | | `ghostsiem detect --rules rules/` | 在存储的事件上运行检测 | | `ghostsiem serve --port 8080` | 启动 REST API 服务器 | | `ghostsiem run --config config.yaml` | 一次性启动所有组件 | | `ghostsiem rules list --builtin` | 显示已加载的检测规则 | | `ghostsiem status` | 显示事件/告警计数 | ## 库用法 ``` from ghostsiem import Collector, DetectionEngine, AlertManager, Event # 加载检测规则 engine = DetectionEngine() engine.load_rules_from_directory("rules/") # 评估事件 alerts = engine.evaluate(event) ``` ## SIGMA 规则格式 GhostSIEM 使用与 SIGMA 兼容的 YAML 规则。每个规则通过选择器(selections)、条件(conditions)和可选过滤器(filters)定义检测逻辑。 ``` title: Failed SSH Login id: gs-001 status: stable description: Detects failed SSH login attempts. author: GhostSIEM logsource: product: linux service: auth level: high detection: selection: message|contains: "Failed password" condition: selection tags: - attack.initial_access - attack.t1078 ``` ### 支持的修饰符 | 修饰符 | 描述 | 示例 | |--------|------|------| | (默认) | 子字符串匹配 | `message: "error"` | | `\|contains` | 子字符串匹配 | `message\|contains: "Failed"` | | `\|startswith` | 前缀匹配 | `process\|startswith: "ssh"` | | `\|endswith` | 后缀匹配 | `hostname\|endswith: ".internal"` | | `\|re` | 正则匹配 | `message\|re: "port \d{4,5}"` | ### 条件操作符 - `selection` — 单个选择器匹配 - `selection1 and selection2` — 必须同时匹配 - `selection1 or selection2` — 任意匹配即可 - `selection and not filter` — 匹配选择器,排除过滤器 - `1 of selection*` — 任意匹配前缀的选择器 - `all of selection*` — 全部匹配前缀的选择器 ### 暴力破解阈值规则 ``` detection: selection: message|contains: "Failed password" threshold: field: src_ip value: 5 timeframe: "60s" condition: selection ``` ## 内置规则 | ID | 规则 | 严重性 | 描述 | |----|------|--------|------| | gs-001 | 失败的 SSH 登录 | HIGH | 单次失败的 SSH 登录尝试 | | gs-002 | SSH 暴力破解 | CRITICAL | 60 秒内来自同一 IP 的 5 次以上失败 | | gs-003 | 异常的 SSH 源 | MEDIUM | 任意来源的成功登录 | | gs-004 | sudo 命令 | MEDIUM | 执行 sudo(过滤 pam_unix) | | gs-005 | 新建用户 | HIGH | 检测到 useradd/adduser | | gs-006 | 服务状态变更 | LOW | 服务启动或停止 | | gs-007 | 防火墙规则变更 | HIGH | 修改 iptables/ufw | | gs-008 | 大规模 outbound 传输 | HIGH | 使用 scp/rsync/curl/wget | ## API 参考 REST API 默认运行在 8080 端口。 ### 端点 **GET /api/v1/health** ``` {"status": "healthy", "service": "ghostsiem", "timestamp": "..."} ``` **GET /api/v1/events** 查询参数:`severity`、`source`、`hostname`、`start_time`、`end_time`、`limit`、`offset` ``` { "count": 50, "limit": 100, "offset": 0, "events": [...] } ``` **GET /api/v1/alerts** 查询参数:`severity`、`rule_id`、`start_time`、`end_time`、`limit`、`offset` **GET /api/v1/stats** ``` { "total_events": 1234, "total_alerts": 56, "events_by_severity": {"high": 100, "medium": 200}, "top_rules": [{"rule": "Failed SSH Login", "count": 30}], "events_per_hour": [{"hour": "2026-04-15 10:00", "count": 42}] } ``` ## 配置参考 ``` log_level: INFO collectors: - type: syslog # syslog, auth, json path: /var/log/syslog poll_interval: 1.0 - type: auth path: /var/log/auth.log - type: json path: /var/log/app/events.json field_map: # Custom field mapping ts: timestamp host: hostname lvl: severity msg: message detection: rules_dir: rules/ alerts: dedup_window: 300 # Suppress duplicates within 5 min handlers: - type: console - type: file path: alerts.jsonl - type: webhook url: https://hooks.slack.com/services/XXX storage: path: ghostsiem.db api: host: 0.0.0.0 port: 8080 ``` 环境变量使用 `GHOSTSIEM_` 前缀覆盖配置: - `GHOSTSIEM_DB_PATH` - `GHOSTSIEM_API_PORT` - `GHOSTSIEM_LOG_LEVEL` ## 集成 GhostSIEM 设计为与 **SentinelPulse** 协同工作,构建完整的安全监控栈。可将 GhostSIEM 告警通过 Webhook 处理器发送至 SentinelPulse 仪表板,实现统一的事件管理。 ## 开发 ``` # 安装开发依赖 make dev # 运行测试 make test # Lint make lint # 格式化 make format ``` ## 许可证 MIT 许可证。Copyright (c) 2026 Joe Munene.
标签:AMSI绕过, CI, GeoIP, IP提取, JSONL, LangChain, Python, Python 3.10, REST API, SEO: GhostSIEM, SIGMA规则, SOC自动化, SQLite, WAL, Webhook, 事件存储, 力导向图, 去重, 告警管理, 威胁检测, 安全信息与事件管理, 开源日志分析, 搜索引擎爬取, 无后门, 日志字段匹配, 日志归一化, 日志收集, 日志采集, 时间线生成, 混合加密, 网络测绘, 自动化响应, 蓝队防御, 轻量级, 轻量级安全工具, 逆向工具