andresscyber/detection-as-code-pipeline
GitHub: andresscyber/detection-as-code-pipeline
一个基于 Sigma 规则和 GitHub Actions 的 Detection-as-Code 流水线项目,通过自动化 CI/CD 实现安全检测规则的开发、验证和跨平台转换。
Stars: 0 | Forks: 0
# Detection-as-Code 流水线
## 概述
本项目展示了使用 Sigma 检测规则、Git 版本控制、GitHub Actions、YAML linting、mock 遥测数据以及自动化 CI/CD 验证的 Detection-as-Code (DaC) 工作流。
该仓库模拟了现代 Detection Engineering 过程,其中安全检测以代码的形式进行管理,通过版本控制进行跟踪,通过 CI/CD pipeline 自动化验证,并转换为特定平台的检测规则以供安全监控解决方案使用。
通过将检测视为代码,组织可以提高检测质量,减少部署错误,强制执行一致性,并在部署到生产 SIEM 或 EDR 环境之前自动化验证过程。
## 实验目标
- 开发基于 Sigma 的安全检测
- 实施 Detection-as-Code 方法论
- 使用 Git 和 GitHub 进行版本控制
- 使用 GitHub Actions 自动化检测验证
- 使用 yamllint 验证 YAML 格式
- 维护用于检测测试的 mock 遥测数据
- 将 Sigma 检测转换为特定于 SIEM 的查询
- 将检测映射到 MITRE ATT&CK 框架
- 展示用于 Detection Engineering 的 CI/CD 实践
## 架构
```
[ Feature Branch ]
│
▼
[ Local Sigma CLI ]
/ \
(Fail) (Pass)
│ │
▼ ▼
Fix Rule Git Push
│
▼
[ Pull Request ]
│
▼
[ GitHub Actions CI/CD ]
/ \
(Fail) (Pass)
│ │
▼ ▼
Block Merge Merge Detection
│
▼
Detection Deployment
```
## 使用的技术
| 技术 | 用途 |
|------------|----------|
| Sigma | 检测规则开发 |
| Sigma CLI | 规则验证 |
| yamllint | YAML 验证 |
| Git | 版本控制 |
| GitHub | 源代码管理 |
| GitHub Actions | CI/CD 自动化 |
| YAML | 检测规则格式 |
| JSON | 测试遥测数据 |
| Splunk SPL | 检测转换 |
| Microsoft Sentinel KQL | 检测转换 |
| MITRE ATT&CK | 威胁映射 |
## 仓库结构
```
detection-as-code-pipeline
│
├── .github
│ └── workflows
│ └── sigma-validation.yml
│
├── sigma-rules
│ └── suspicious-powershell.yml
│
├── tests
│ └── powershell-test-event.json
│
├── dist
│ ├── splunk-suspicious-powershell.spl
│ └── sentinel-suspicious-powershell.kql
│
├── screenshots
│
└── README.md
```
## Sigma 检测规则
该项目包含一个 Sigma 检测规则,旨在识别可疑的 PowerShell 执行活动。
### 检测逻辑
```
Image|endswith: '\powershell.exe'
CommandLine|contains:
- '-enc'
- 'EncodedCommand'
- 'IEX'
```
### 检测重点
- 编码的 PowerShell 执行
- 混淆的命令执行
- 内存中脚本执行
- MITRE ATT&CK T1059.001
## Mock 测试遥测数据
`tests` 目录包含 mock Windows 进程创建遥测数据,用于表示可疑的编码 PowerShell 执行活动。
```
{
"EventID": 4688,
"Provider": "Microsoft-Windows-Security-Auditing",
"Image": "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
"CommandLine": "powershell.exe -NoProfile -ExecutionPolicy Bypass -enc SQBFAFgA",
"ParentImage": "C:\\Windows\\explorer.exe",
"User": "LAB\\testuser",
"Host": "WIN10-ENDPOINT"
}
```
## 检测可移植性
Sigma 的主要优势之一是能够创建独立于平台的检测规则。
为了展示可移植性,Sigma 规则已被转换为多个 SIEM 平台的等效查询。
### Splunk SPL
```
index=windows sourcetype=XmlWinEventLog:Microsoft-Windows-Sysmon/Operational
Image="*\\powershell.exe"
(CommandLine="*-enc*" OR CommandLine="*EncodedCommand*" OR CommandLine="*IEX*")
```
### Microsoft Sentinel KQL
```
DeviceProcessEvents
| where FileName =~ "powershell.exe"
| where ProcessCommandLine has_any ("-enc", "EncodedCommand", "IEX")
```
### 转换后的查询示例

## GitHub Actions 工作流
当 Sigma 规则、测试遥测数据或工作流文件被修改时,GitHub Actions 工作流会自动执行。
### CI/CD 验证任务
- 检出仓库
- 安装 Python
- 安装 Sigma CLI
- 安装 yamllint
- 验证 YAML 格式
- 验证 Sigma 规则仓库
- 验证测试遥测数据的可用性
### 工作流过程
```
Sigma Rule Modified
│
▼
Git Commit
│
▼
Git Push
│
▼
GitHub Actions Triggered
│
▼
YAML Validation
│
▼
Sigma Validation
│
▼
Workflow Result
```
## 项目截图
### 环境设置
#### 项目文件夹结构

#### Python 和 Sigma 安装

#### Sigma CLI 验证

#### Git 安装

### 检测开发
#### Sigma 检测规则

### 验证测试
#### Sigma 验证测试

#### Mock 测试遥测数据

### GitHub Actions 配置
#### GitHub Actions 工作流

#### YAML Linting 更新

### Pipeline 结果
#### 初始 Git Commit

#### GitHub Push

#### 仓库上传

#### GitHub Actions 工作流检测

#### 成功的工作流执行

#### 工作流详情

## MITRE ATT&CK 映射
| 技术 | 描述 |
|------------|-------------|
| T1059.001 | PowerShell |
| T1027 | 混淆的文件或信息 |
| T1140 | 解混淆/解码文件或信息 |
## 展示的技能
### Detection Engineering
- Sigma 规则开发
- Detection-as-Code
- ATT&CK 映射
- 检测验证
- 检测可移植性
### DevSecOps
- Git
- GitHub
- GitHub Actions
- CI/CD Pipelines
- YAML 验证
### 安全运营
- PowerShell 检测
- 威胁检测
- 进程创建分析
- Mock 遥测数据测试
## 结果
成功开发了一个能够执行以下操作的 Detection-as-Code pipeline:
- 通过版本控制管理安全检测
- 通过 GitHub Actions 自动化验证
- 使用 yamllint 强制执行 YAML 质量标准
- 维护用于验证工作流的测试遥测数据
- 将 Sigma 检测转换为 Splunk 和 Sentinel 查询
- 展示 Detection Engineering 团队使用的 CI/CD 实践
## 未来增强
- 额外的 Sigma 检测
- 自动化的 Sigma linting
- 检测覆盖率报告
- Pull request 审批工作流
- Splunk 部署集成
- Microsoft Sentinel 部署集成
- 自动化检测测试
## 简历要点
标签:GitHub Actions, Homebrew安装, Sigma规则, 安全运营, 扫描框架, 目标导入, 自动笔记, 逆向工具