Speed-boo3/soc-project

GitHub: Speed-boo3/soc-project

一个用 Python 从零构建的安全运营中心教学项目,涵盖日志解析、规则检测、MITRE ATT&CK 映射、威胁情报查询和应急响应全流程,帮助学生理解 SOC 的实际工作方式。

Stars: 0 | Forks: 0


![Python](https://img.shields.io/badge/Python-3.8+-0d1117?style=flat-square&logo=python&logoColor=00ff41) ![Tests](https://img.shields.io/badge/tests-11%20passing-0d1117?style=flat-square&logo=pytest&logoColor=00ff41) ![License](https://img.shields.io/badge/license-MIT-0d1117?style=flat-square) ![MITRE](https://img.shields.io/badge/MITRE-ATT%26CK-0d1117?style=flat-square&logoColor=ff4444) ![Rules](https://img.shields.io/badge/detection%20rules-10-0d1117?style=flat-square&logoColor=ff4444)
## 交互式学习站点
[![打开交互式指南](https://img.shields.io/badge/Interactive%20Guide-Learn%20SOC%20from%20scratch-ff4444?style=for-the-badge&labelColor=0d1117)](https://speed-boo3.github.io/soc-project/explain/)
六个模块涵盖了从 SOC 是什么到 MITRE ATT&CK、实时威胁情报查询以及分析师技能清单的所有内容。包含矩阵雨动画和实时警报滚动条。 ## 这是什么 一个使用 Python 从零开始构建的安全运营中心 (SOC) 项目。它专为希望了解 SOC 实际工作流程(而不仅仅是理论)的学生而设计。 这里的每个工具都解决了一个实际问题。日志解析器、警报引擎、威胁情报查询、暴力破解检测器——这些都是真实分析师每天使用的工具的简化版本。你可以运行它们、阅读代码并准确了解每一步发生了什么。 ## 什么是 SOC 安全运营中心是一个全天候监控组织系统以寻找攻击迹象的团队。当日志中出现可疑情况时,SOC 会对其进行调查,判断其是否为真实威胁,并采取相应的响应措施。 SOC 分析师的核心工作可分解为四件事: **收集** — 将来自服务器、防火墙、端点和应用程序的日志集中到一个地方 **检测** — 通过检测规则运行这些日志,标记出可疑模式 **调查** — 弄清楚警报是真实的攻击还是误报 **响应** — 如果是真实的,则对其进行遏制、清除并恢复 本项目涵盖了以上全部四个方面。 ## 工具是如何连接的 ``` flowchart TD A[Raw log file] --> B[Log Parser] B --> C[Parsed JSON] C --> D[Alert Engine] C --> E[Brute Force Detector] D --> F{Rule matches?} F -->|Yes| G[Alert fired] F -->|No| H[Skipped] E --> G G --> I[MITRE ATT&CK tag] G --> J[Threat Intel lookup] J --> K[AbuseIPDB score] I & K --> L[Terminal Dashboard] G --> M[alerts.log] style A fill:#cc2200,stroke:#ff0000,color:#ffffff style G fill:#cc2200,stroke:#ff0000,color:#ffffff style C fill:#007722,stroke:#00ff41,color:#ffffff style L fill:#1a3a8a,stroke:#4488ff,color:#ffffff style M fill:#1a3a8a,stroke:#4488ff,color:#ffffff ``` ## 工具 ### 日志解析器 `soc/log-parser/parser.py` 逐行读取日志文件,判断每一行的类型——SSH 认证、Apache 访问日志或 syslog——并标记任何可疑内容。输出一个结构化的 JSON 文件,供其他工具使用。 ``` python soc/log-parser/parser.py --file soc/log-parser/sample.log --output parsed.json ``` 输出: ``` Total log entries : 19 Suspicious events : 11 --- Suspicious entries --- [syslog] Failed password for root from 45.33.32.156 port 55018 ssh2 [syslog] Invalid user ftpuser from 45.33.32.156 [syslog] pam_unix(sudo:auth): authentication failure ``` ### 警报引擎 `soc/alert-rules/alert_engine.py` 将解析后的日志条目与用 YAML 编写的检测规则进行匹配。每条规则都映射到一个 MITRE ATT&CK 技术,因此每个警报不仅告诉你发生了什么,还告诉你它属于哪种攻击类型。 ``` python soc/alert-rules/alert_engine.py \ --logs parsed.json \ --rules soc/alert-rules/rules.yaml \ --output alerts.log ``` 输出: ``` 3 alert(s) triggered: [HIGH] Brute Force Detected (RULE-BF) MITRE ATT&CK : T1110 - Brute Force (Credential Access) Action : alert Log entry : Source IP 45.33.32.156 had 9 failed login attempts [MEDIUM] Sudo Authentication Failure (RULE-003) MITRE ATT&CK : T1078 - Valid Accounts (Privilege Escalation) Action : log Log entry : pam_unix(sudo:auth): authentication failure [MEDIUM] Segfault Detected (RULE-006) MITRE ATT&CK : T1203 - Exploitation for Client Execution (Execution) Action : alert Log entry : program[9708]: segfault at 0 ip 00007f ``` ### 暴力破解检测器 `soc/brute-force-detector/detector.py` 读取认证日志,并标记在可配置的时间窗口内登录失败次数过多的 IP。它使用实际的滑动窗口——而不仅仅是总计数——因此它可以捕捉到那些在长时间间隔之外迅速发生的攻击。 ``` python soc/brute-force-detector/detector.py \ --file soc/log-parser/sample.log \ --threshold 5 \ --window 300 ``` 输出: ``` Brute Force Detection Report ============================================================ Threshold : 5 attempts within 300 seconds FLAGGED IPs: 45.33.32.156 9 in window / 9 total BLOCK RECOMMENDED ``` ### 威胁情报 `soc/alert-rules/threat_intel.py` 从解析后的日志文件中提取所有唯一的 IP,并依次在 AbuseIPDB 中进行查询。返回滥用置信度评分、报告总数以及滥用类别。 ``` export ABUSEIPDB_KEY=your_key_here python soc/alert-rules/threat_intel.py --logs parsed.json ``` 在 [abuseipdb.com/register](https://www.abuseipdb.com/register) 获取免费密钥。 ### 仪表盘 `soc/dashboard/dashboard.py` 在终端中一站式总览所有信息——按类型统计的日志量、主要源 IP、HTTP 状态码以及最近的可疑事件。 ``` python soc/dashboard/dashboard.py --logs parsed.json ``` ### 应急响应剧本 `soc/incident-response/playbook.md` 针对每种警报类型的逐步响应程序,基于 NIST SP 800-61 标准。涵盖了每条规则触发时的应对措施、如何升级以及事后报告应包含的内容。 ### 哈希检查器 `soc/hash-checker/hash_checker.py` 识别哈希算法类型,并根据已知恶意软件哈希的本地数据库检查哈希值。在应急响应期间需要快速评估可疑文件时非常有用。 ``` python soc/hash-checker/hash_checker.py --hash d41d8cd98f00b204e9800998ecf8427e ``` ### 日志生成器 `soc/log-parser/generate_logs.py` 生成具有随机 IP、用户名、端口和攻击模式的真实日志文件,用于测试。每日 GitHub Actions 工作流每天早晨使用此工具生成一个新的日志文件,并针对它运行完整的处理流程。 ``` python soc/log-parser/generate_logs.py ``` ## MITRE ATT&CK 覆盖范围 每条检测规则都映射到一项技术。当警报触发时,你可以立即知道你正在面对的是哪种类型的攻击。 ``` flowchart LR subgraph CA[Credential Access] T1110[T1110 Brute Force] T1110b[T1110.004 Credential Stuffing] end subgraph IA[Initial Access] T1078[T1078 Valid Accounts] T1190[T1190 Exploit Public App] end subgraph PE[Privilege Escalation] T1078b[T1078 Valid Accounts] end subgraph EX[Execution] T1203[T1203 Client Exploitation] end R1[RULE-001] --> T1110 R4[RULE-004] --> T1110b R2[RULE-002] --> T1078 R5[RULE-005] --> T1190 R3[RULE-003] --> T1078b R6[RULE-006] --> T1203 style CA fill:#cc2200,stroke:#ff4444,color:#ffffff style IA fill:#bb7700,stroke:#ffaa00,color:#ffffff style PE fill:#007722,stroke:#00ff41,color:#ffffff style EX fill:#1a3a8a,stroke:#4488ff,color:#ffffff ``` ## 应急响应 当警报触发时,响应遵循 NIST SP 800-61 生命周期。 ``` flowchart LR A[Alert fires] --> B[Triage] B --> C{Real threat?} C -->|No| D[Close as false positive] C -->|Yes| E[Contain] E --> F[Eradicate] F --> G[Recover] G --> H[Post-incident report] H --> I[Improve rules] style A fill:#cc2200,stroke:#ff0000,color:#ffffff style D fill:#007722,stroke:#00ff41,color:#ffffff style H fill:#1a3a8a,stroke:#4488ff,color:#ffffff style I fill:#007722,stroke:#00ff41,color:#ffffff ``` 包含每个场景逐步程序的完整剧本位于 `soc/incident-response/playbook.md`。 ## 每日自动扫描 GitHub Actions 在每天早上 UTC 07:00 运行。它会生成一个新的日志文件,运行完整的处理流程并提交结果。这使项目保持活跃,并随着时间的推移将检测结果累积记录在 `alerts.log` 中。 工作流文件位于 `.github/workflows/daily-scan.yml`。 ## 项目结构 ``` soc-project/ ├── soc/ │ ├── log-parser/ │ │ ├── parser.py ← reads and classifies log lines │ │ ├── generate_logs.py ← generates realistic test logs │ │ └── sample.log ← latest generated log file │ ├── alert-rules/ │ │ ├── rules.yaml ← detection rules with MITRE mapping │ │ ├── alert_engine.py ← runs logs against the rules │ │ └── threat_intel.py ← AbuseIPDB IP reputation lookup │ ├── dashboard/ │ │ └── dashboard.py ← terminal overview │ ├── incident-response/ │ │ └── playbook.md ← IR playbook per incident type │ ├── hash-checker/ │ │ └── hash_checker.py ← hash type detection and malware check │ └── brute-force-detector/ │ └── detector.py ← sliding window brute force detection ├── tests/ │ ├── test_parser.py │ └── test_alert_engine.py ├── .github/workflows/ │ ├── tests.yml ← runs on every push │ └── daily-scan.yml ← runs every morning at 07:00 UTC ├── alerts.log ← cumulative alert history ├── requirements.txt ├── CONTRIBUTING.md └── CHANGELOG.md ``` ## 快速开始 ``` git clone https://github.com/Speed-boo3/soc-project.git cd soc-project pip install -r requirements.txt ``` 运行完整的处理流程: ``` python soc/log-parser/generate_logs.py python soc/log-parser/parser.py --file soc/log-parser/sample.log --output parsed.json python soc/alert-rules/alert_engine.py --logs parsed.json --rules soc/alert-rules/rules.yaml python soc/dashboard/dashboard.py --logs parsed.json ``` 运行测试: ``` pytest tests/ -v ``` ## 测试你的知识 20道涵盖 SOC 基础知识的问题——什么是 SOC、日志分析、MITRE ATT&CK、威胁情报、应急响应、检测工程、网络安全和数字取证。
[![参加 SOC 测验](https://img.shields.io/badge/Take%20the%20SOC%20Quiz-→-ff4444?style=for-the-badge&labelColor=0d1117)](https://speed-boo3.github.io/soc-project/quiz/)
## 了解更多 - [MITRE ATT&CK](https://attack.mitre.org) — 完整的战术和技术库 - [NIST SP 800-61](https://csrc.nist.gov/publications/detail/sp/800-61/rev-2/final) — 应急处理指南 - [AbuseIPDB](https://www.abuseipdb.com) — IP 信誉数据库 - [Sigma HQ](https://github.com/SigmaHQ/sigma) — 社区检测规则 - [LetsDefend](https://letsdefend.io) — SOC 分析师培训平台 - [Blue Team Notes](https://github.com/Purp1eW0lf/Blue-Team-Notes) — 实用蓝队参考 本项目的 GRC 相关部分位于 [grc-project](https://github.com/Speed-boo3/grc-project)。SOC 负责检测正在发生的事件。GRC 则负责跟踪那些本应阻止这些事件的控制措施是否真正落实到位。
标签:AbuseIPDB, Cloudflare, MITRE ATT&CK, MIT开源协议, pytest, Python, 免杀技术, 初学者指南, 后端开发, 告警检测, 威胁情报, 学生项目, 安全教育, 安全规则引擎, 安全运营中心, 实战项目, 密码管理, 库, 应急响应, 开发者工具, 无后门, 日志解析, 暴力破解检测, 网络安全, 网络映射, 证书伪造, 逆向工具, 隐私保护