EXP09/SAM-Enterprise-Demo

GitHub: EXP09/SAM-Enterprise-Demo

自托管的 Windows 端点 SOC/XDR 平台,整合 EDR、DLP、威胁情报、事件响应与合规治理,为安全分析师提供端到端的检测、调查与处置闭环。

Stars: 0 | Forks: 0

# SAM — 企业安全平台 ![Python](https://img.shields.io/badge/Python-3.x-3776AB?logo=python&logoColor=white) ![FastAPI](https://img.shields.io/badge/FastAPI-009688?logo=fastapi&logoColor=white) ![PostgreSQL](https://img.shields.io/badge/PostgreSQL-4169E1?logo=postgresql&logoColor=white) ![License](https://img.shields.io/badge/License-MIT-34d399) **SAM** 是一个自托管的 **SOC / XDR 平台** —— 这是一个单一的安全控制台, 它从 Windows 端点收集遥测数据,将其关联为检测结果和 事件,并为分析师提供调查和响应的工具。可以将其 视为 Defender XDR / CrowdStrike Falcon / SentinelOne 的内部替代品, 采用端到端构建:**端点 agent → 摄取 API → 事件 pipeline → 检测 引擎 → 运营控制台。** ## 工作原理 每个 Windows 端点上的轻量级 agent 通过 HTTPS 将安全信号流式传输到 服务器,并使用**每 agent 专属 token** 进行身份验证。服务器将 所有内容持久化到 PostgreSQL,并将每个事件发送到内部的 **事件 pipeline**。 后台的**事件总线**将这些事件分发给独立的检测引擎 (EDR、IOC 匹配、风险评分、DLP、事件响应),这些引擎并行运行并 将其发现写回。分析师完全通过 Web 控制台进行工作 —— 对 事件进行分类、狩猎,并触发响应操作(隔离主机、终止进程、阻止 USB),这些操作将被推送回 agent。 ``` flowchart LR subgraph EP["Windows Endpoints"] A1["PowerShell agent
w.ps1 · sam_telemetry.ps1"] A2[".NET agent
SAMAgentSvc + Tray"] end A1 & A2 -->|per-agent token · HTTPS| ING["Ingestion API
FastAPI"] ING --> DB[(PostgreSQL)] ING --> PIPE["Event pipeline
core_events + pg_notify"] PIPE --> BUS["Event bus
dispatcher"] BUS --> DET["Detection engines
EDR · IOC · Risk · DLP · IR"] DET --> DB DB --> UI["SOC Console
Jinja2 + ⌘K palette"] UI --> AN(("Analyst")) AN -->|isolate · kill · hunt| RESP["Response actions"] RESP -.-> A1 ``` **数据流:** `agent → 摄取 → PostgreSQL + 事件 pipeline → 总线 → 检测器 → 控制台 → 响应 → agent` ## 功能 | 领域 | 功能描述 | |------|--------------| | **检测与响应** | 映射 MITRE 的 EDR 检测器、事件响应引擎(检测 → 事件 → 一键 playbook)、调查工作区,以及用于主机隔离 / 终止进程 / 提取证据的响应中心。 | | **数据防泄漏 (DLP)** | 端点(USB + 文件复制)和网络 DLP(通过 mitmproxy 拦截 addon)、内容分类器 + 文档指纹、具有基于域策略的上传监控,以及证据保管库。 | | **威胁情报** | IOC 中心(带有针对实时遥测数据的匹配引擎)、威胁情报富化,以及 provider 集成(VirusTotal / MalwareBazaar),在未配置时会优雅降级。 | | **风险与内部威胁** | 以用户为中心的风险评分(具有行为基线和内部威胁指标),外加一个统一、可解释的风险引擎,该引擎聚合 EDR / IOC / DLP / PAM 信号。 | | **威胁狩猎** | 基于事件存储库的安全、参数化(防注入)查询层,带有可将数据馈送到 IR pipeline 的已保存检测规则。 | | **治理与合规** | 基于真实系统信号评级的 SAMA CSF / NCA ECC / PDPL 实时合规状态、证据保管库、保留 / 同意 / RoPA / DSAR 模块,以及可打印的审计报告。 | | **端点管理** | 具有健康状态(在线/过期/离线)的设备清单、端点健康监控器、资产清单、PAM 设备视图,以及一键 agent 部署生成器。 | | **AI 助手** | 通过 Claude 或兼容 OpenRouter 的模型进行自然语言威胁狩猎和事件摘要(阿拉伯语 / 英语)—— 可选功能,支持优雅降级。 | | **平台** | 事件 pipeline + 总线、基于 agent 的身份/token 颁发、RBAC + TOTP 2FA、hash 链接的防篡改审计日志、结构化日志、健康与指标 endpoint。 | ## 截图 ### 主页 — 概览与分析 SOC 概览汇总了会话、DLP 事件、风险分布和实时 活动;高管视图为领导层进行了汇总。 | SOC 概览 | 高管视图 | 近期活动 | |:---:|:---:|:---:| | [![SOC Overview](https://static.pigsec.cn/wp-content/uploads/repos/cas/20/2040502cdf7da8971bdff4c42525232ca119d05385d88a96b9783a22d6f7be3c.png)](screenshots/01-soc-overview.png) | [![Executive](https://static.pigsec.cn/wp-content/uploads/repos/cas/b6/b6036d9d3da038d89ea6e807603b3d7f1c7c2b22cf1af509bd92d5f04f35c0a5.png)](screenshots/02-executive.png) | [![Recent Activity](https://static.pigsec.cn/wp-content/uploads/repos/cas/76/76f051712ef4fb70809779ebd48b4f33ab5c97fb58c66ce964dff3e246a010fb.png)](screenshots/03-recent-activity.png) | ### 运营 — 检测、调查、响应 事件队列、调查工作区、响应中心(遏制 操作),以及用于收集 artifacts 的证据中心。 | 事件 | 调查 | 响应中心 | 证据中心 | |:---:|:---:|:---:|:---:| | [![Incidents](https://static.pigsec.cn/wp-content/uploads/repos/cas/62/62be9a0a225886bc8359541b2cd93c60b63f40f7df42fd5aef99d0ad976e61ea.png)](screenshots/04-incidents.png) | [![Investigation](https://static.pigsec.cn/wp-content/uploads/repos/cas/9f/9fdb2df8083fdd1d97565a5c1208961c073cc93d672574d21a2453e10eed19ec.png)](screenshots/05-investigation.png) | [![Response Center](https://static.pigsec.cn/wp-content/uploads/repos/cas/8d/8d47b5fcd4e429876f7107c8c7bc004aad2ff78657bbf108cabfb8f5ece1f63f.png)](screenshots/06-response-center.png) | [![Evidence Center](https://static.pigsec.cn/wp-content/uploads/repos/cas/5f/5fd8fd62f8fbe043a1294c290bf6da00351c1b56b1baad22b65e77f45cdd45e0.png)](screenshots/07-evidence-center.png) | ### 风险与情报 高风险用户评分、威胁情报、IOC 中心、威胁狩猎、MITRE EDR 覆盖视图和沙箱。 | 高风险用户 | 威胁情报 | IOC 中心 | |:---:|:---:|:---:| | [![Risky Users](https://static.pigsec.cn/wp-content/uploads/repos/cas/5e/5e396a22acd1305a7ed2f0001f4decf9389001fb69c44de4e0f60388c3b817e1.png)](screenshots/08-risky-users.png) | [![Threat Intel](https://static.pigsec.cn/wp-content/uploads/repos/cas/28/284be28b9679eb8f22a59c299be4a09acce3ebf845f011ad6521deb31bb68445.png)](screenshots/09-threat-intel.png) | [![IOC Center](https://static.pigsec.cn/wp-content/uploads/repos/cas/c6/c606ebf4b66d838dd220c38e779d4bfec879bb024f921e19158a049fb0cf4b66.png)](screenshots/10-ioc-center.png) | | 威胁狩猎 | 高级 EDR | 沙箱 | |:---:|:---:|:---:| | [![Threat Hunting](https://static.pigsec.cn/wp-content/uploads/repos/cas/70/7067f291ffb72707e922ec6bd098252eaebba0805e7400bc5cbcc264886c5d6a.png)](screenshots/11-threat-hunting.png) | [![Advanced EDR](https://static.pigsec.cn/wp-content/uploads/repos/cas/a9/a9e75c4d8c71244acc11e0fe5af3da0d6a2fb10016b649d4c1835ded8c4247d7.png)](screenshots/12-advanced-edr.png) | [![Sandbox](https://static.pigsec.cn/wp-content/uploads/repos/cas/e9/e9e532cd7e9e358e0d47b3c1151e1203d31a4a5811d531d4c8f6005bb9d20fe0.png)](screenshots/13-sandbox.png) | ### 端点 个人设备访问 (PAM)、设备清单、端点健康和资产。 | PAM — 我的设备 | 设备清单 | 端点健康 | 资产 | |:---:|:---:|:---:|:---:| | [![PAM](https://static.pigsec.cn/wp-content/uploads/repos/cas/38/3843e827b864c32dae8c5549f024df062ea6615156a1c9dc48486f069c6062e0.png)](screenshots/14-pam-my-devices.png) | [![Fleet](https://static.pigsec.cn/wp-content/uploads/repos/cas/4d/4dfeb9e7c62526924ded2ba698c67dff918f63ac5c29d7a0c6827dab916839cb.png)](screenshots/15-fleet.png) | [![Endpoint Health](https://static.pigsec.cn/wp-content/uploads/repos/cas/ac/acbd526e51137ae5043fcce27e397791099e5f947540a5b27ebd2760fedcd888.png)](screenshots/16-endpoint-health.png) | [![Assets](https://static.pigsec.cn/wp-content/uploads/repos/cas/9e/9efccbdaff37d39fd6ffa57a8723603145e77a022ec55821610a7f453ea3a274.png)](screenshots/17-assets.png) | ### 数据保护与治理 统一的 DLP 控制台、合规中心(SAMA / NCA / PDPL 就绪状态)、 计划报告和防篡改审计日志。 | DLP | 合规 | 报告 | 审计 | |:---:|:---:|:---:|:---:| | [![DLP](https://static.pigsec.cn/wp-content/uploads/repos/cas/be/be1a693966f613845754fe41b0bc93352a90194a3f3338657a64aa522ec84ecd.png)](screenshots/18-dlp.png) | [![Compliance](https://static.pigsec.cn/wp-content/uploads/repos/cas/e9/e9062ba23789ff19381a813068c35a8fac16dfd94370b4cbdf172be7b9a65993.png)](screenshots/19-compliance.png) | [![Reports](https://static.pigsec.cn/wp-content/uploads/repos/cas/07/071b31d9cc45f6ea7a9ce8dab47c3e61adedd389b2794aec0609b96bfee054b9.png)](screenshots/20-reports.png) | [![Audit](https://static.pigsec.cn/wp-content/uploads/repos/cas/d7/d79c813679d1ff01971d8dc50af8601ee7b1e29ca87d3f2e11ad280b993861dd.png)](screenshots/21-audit.png) | ### 管理 策略中心、用户管理、细粒度访问控制、agent 部署 生成器、AI 助手和设计系统参考。 | 策略中心 | 用户管理 | 访问控制 | |:---:|:---:|:---:| | [![Policy Center](https://static.pigsec.cn/wp-content/uploads/repos/cas/1c/1cea077277ef8ab0ca46bd415ca2cdf79fdf3e8ae54c0b597053c4855c67ca89.png)](screenshots/22-policy-center.png) | [![User Management](https://static.pigsec.cn/wp-content/uploads/repos/cas/ac/ac557d6ce603b9a3eaf167705691800fa9645ed088e94d4eb76e1736848b1882.png)](screenshots/23-user-management.png) | [![Access Control](https://static.pigsec.cn/wp-content/uploads/repos/cas/31/3105b785079c784c2a35c7ea76454cf40dcf18d2a11b972190d214c109c5e4b2.png)](screenshots/24-access-control.png) | | 部署 Agent | AI 助手 | 设计系统 | |:---:|:---:|:---:| | [![Deploy Agent](https://static.pigsec.cn/wp-content/uploads/repos/cas/64/640e1d5ebb83ac6f89a67f0a5f73c87514d7edf8348c3c68228c6fbf137a1337.png)](screenshots/25-deploy-agent.png) | [![AI Assistant](https://static.pigsec.cn/wp-content/uploads/repos/cas/ab/ab8b14afeefdb2c0f6282263a7b3a2320e249170ff51d18ce20a6a99d60d775a.png)](screenshots/26-ai-assistant.png) | [![Design System](https://static.pigsec.cn/wp-content/uploads/repos/cas/2b/2bd246ee8842a65a44bacd4680df0370382a6a75753107bff610cf7103802ba8.png)](screenshots/27-design-system.png) | ## 技术栈 - **后端** — FastAPI (Python 3)、Jinja2 服务端渲染 UI、WebSockets(实时 shell / RDP) - **数据库** — PostgreSQL(事件存储 + 领域表) - **平台** — 定制事件 pipeline + 基于轮询的事件总线、基于 agent 的身份、RBAC、TOTP 2FA、hash 链审计 - **端点 agent** — PowerShell (`w.ps1`, `sam_telemetry.ps1`) 和原生 **.NET 8** 服务 + 托盘程序 (`agent-native/`);C# 中的 DXGI 屏幕捕获和 ETW 文件监控 - **DLP** — mitmproxy 拦截 addon + 内容分类器 / 指纹 - **媒体与分析** — imageio + Pillow + numpy(来自屏幕帧的视频)、OCR 关键词/DLP 检测 - **交付** — Cloudflare Tunnel 背后的 systemd 服务 ## 仓库结构 | 路径 | 描述 | |------|-------------| | `app/main.py` | FastAPI 入口点 —— 连接 router,启动总线,注册检测引擎 | | `app/routes/` | 36 个路由模块(SOC 页面 + agent/摄取 + WebSocket endpoint) | | `app/platform/` | 跨切面基础设施:`events/` (pipeline + 总线), `identity/`, `edr/`, `risk_engine/`, `threatintel/`, `dlp/`, `response/`, `pam/`, `assets/`, `observability/` | | `app/agents/` | 领域 agent:`risk/`, `ir/` (事件响应), `hunting/`, `reporting/`, `sandbox/`, `assistant/` | | `app/compliance/` | SAMA / NCA / PDPL 就绪引擎 + 保留 / 同意 / RoPA / DSAR | | `app/services/` | 身份验证、会话、OCR、风险、视频、威胁情报服务 | | `app/templates/` | 50 个基于共享 `base.html` 外壳构建的 Jinja2 页面(左侧边栏 + ⌘K 面板) | | `app/static/` | 设计系统 (`style.css`)、主题 + 终端资产 | | `tools/` | DLP 引擎、mitmproxy addon、频道助手 | | `agent-native/` | .NET 8 端点 agent(服务 + 托盘)—— **仅源码** | | `kernel/` | 用于内核级 DLP 的文件系统 Minifilter 概念验证 (`SamMon`) | | `migrations/` | Alembic schema 迁移(仅结构 —— 无数据) | | `w.ps1`, `w-external.ps1`, `sam_telemetry.ps1`, `sam_posture.ps1` | PowerShell 端点 agent | | `capture_dxgi.cs`, `etw_file.cs`, `session_launch.cs` | 原生捕获 / ETW / 会话启动助手 | ## 本地运行 ``` # 配置 — 复制模板并填入你自己的值 cp .env.example .env # 至少设置 PG_PASS 和 API_KEY(没有它们,app 将拒绝启动) # 安装依赖项 pip install -r requirements.txt # 创建 .env 中引用的 PostgreSQL 数据库,然后运行 uvicorn app.main:app --host 0.0.0.0 --port 8000 ``` 如果强制要求的密钥(`PG_PASS`, `API_KEY`)未设置,应用将会**抛出明显错误** — 这是故意的,以确保它永远不会静默回退到默认凭据。 ## 安全说明 - 没有提交任何真实的密钥。密钥来自环境变量 / `.env` (被 git 忽略);`.env.example` 仅包含占位符。 - 密码哈希使用 **bcrypt**,会话基于 cookie,并且特权 角色受 **TOTP 2FA** 保护。 - 审计日志是 **hash 链接的**(每个条目都链接到前一个),以便 能够检测到篡改。 ## 许可证 基于 [MIT License](LICENSE) 发布。
标签:AI合规, AV绕过, DLP, DNS 反向解析, EDR, FastAPI, HTTP工具, PostgreSQL, SOC平台, 子域名变形, 无线安全, 测试用例, 知识库安全, 终端安全, 脆弱性评估, 逆向工具