检测MCP服务器
模型上下文协议(MCP)服务器,用于根据SIGMA和YARA输入构建Microsoft Sentinel和Defender XDR检测规则。
🚀 新来的? 看看 VS代码和代码空间快速入门指南 📦 部署到Defender XDR? 请参阅 部署指南
概述
此MCP服务器提供了将安全检测规则从SIGMA和YARA格式转换为KQL(Kusto查询语言)的工具,用于:
- 微软哨兵 -云原生SIEM解决方案
- Microsoft Defender XDR -扩展检测和响应平台
所有生成的KQL都遵循微软的官方编码标准和最佳实践。
特性
- SIGMA到KQL转换:将SIGMA规则(YAML格式)转换为优化的KQL查询
- 支持Azure、Windows、Linux、Office 365、AWS和GCP日志源 - 自动表映射(AuditLogs、SecurityEvent、DeviceEvents等) - 智能字段名称映射 - 正确处理通配符和运算符
- YARA到KQL的转换:将YARA恶意软件检测规则转换为KQL查询
- 跨文件和流程事件搜索 - 命令行和文件路径中的模式匹配 - 支持Sentinel和Defender XDR模式
- Defender XDR部署:将检测规则直接部署到Defender XDR
- 通过Microsoft Graph API进行编程部署 - 生成Azure CLI和PowerShell部署脚本 - 从SIGMA规则中自动提取元数据 - 严重性映射和MITRE ATT&CK标签支持
部署的身份验证和标识
部署到Defender XDR需要Azure AD身份验证:
身份选项:
- 用户身份 (通过Azure CLI):
az login-使用您的Azure AD用户凭据 - 服务主体 (通过应用程序注册):客户端凭据与应用程序ID和密钥一起流动
- 管理身份:用于从Azure资源进行自动化部署
所需权限:
- API权限:
SecurityEvents.ReadWrite.All(微软图形) - Azure角色:安全管理员或全局管理员
身份验证方法:
- Azure命令行界面 (建议交互式使用):
az login
TOKEN=$(az account get-access-token --resource https://graph.microsoft.com --query accessToken -o tsv)- 服务主体 (用于自动化):
curl -X POST https://login.microsoftonline.com/{tenant-id}/oauth2/v2.0/token \
-d "client_id={app-id}" \
-d "client_secret={secret}" \
-d "scope=https://graph.microsoft.com/.default" \
-d "grant_type=client_credentials"- PowerShell与微软。图:
Connect-MgGraph -Scopes "SecurityEvents.ReadWrite.All"请参阅 部署指南 有关详细的设置说明。
- 标准合规:所有生成的KQL都遵循Microsoft指南
- 正确的缩进(4个空格) - 小写运算符(where,and,or not) - PascalCase表名和列名 - 有意义的评论和元数据
安装
npm install
npm run build快速开始
本地测试
运行测试套件查看转换示例:
npm test或者使用交互式转换工具:
# Convert SIGMA to Sentinel KQL
npm run convert sigma sentinel examples/azure-pim-change.yml
# Convert SIGMA to Defender KQL
npm run convert sigma defender examples/powershell-download.yml
# Convert YARA to Sentinel KQL
npm run convert yara sentinel examples/suspicious-powershell.yara
# Convert YARA to Defender KQL
npm run convert yara defender examples/suspicious-powershell.yara这将演示如何将示例SIGMA和YARA规则转换为 examples/ 目录。
使用MCP检查器进行交互式测试
使用MCP检查器以交互方式测试服务器:
npx @modelcontextprotocol/inspector node dist/index.js这将打开一个web界面,您可以在其中:
- 查看所有可用工具
- 使用您自己的SIGMA/YARA规则测试转换
- 实时查看生成的KQL
示例:转换SIGMA规则
一旦配置了MCP客户端(Claude、Cline等),您可以问:
“将此SIGMA规则转换为Sentinel KQL:\[粘贴SIGMA规则\]”
MCP服务器将使用适当的工具并返回格式正确的KQL。
使用GitHub Copilot
配置
将此服务器添加到MCP设置文件中:
适用于克劳德桌面 (~/Library/Application Support/Claude/claude_desktop_config.json 在macOS上):
{
"mcpServers": {
"detection-mcp": {
"command": "node",
"args": ["/path/to/detection-mcp/dist/index.js"]
}
}
}使用GitHub Copilot获取VS代码:
在您的 .vscode/settings.json 或用户设置:
{
"github.copilot.advanced": {
"mcpServers": {
"detection-mcp": {
"command": "node",
"args": ["/path/to/detection-mcp/dist/index.js"]
}
}
}
}可用工具
1. sigma_to_sentinel_kql
将SIGMA规则转换为Microsoft Sentinel的KQL。
参数:
sigma_rule:YAML格式的SIGMA规则(字符串)
例子:
title: Azure PIM Setting Change
id: 123e4567-e89b-12d3-a456-426614174000
description: Detects changes to Azure PIM settings
logsource:
product: azure
service: auditlogs
detection:
selection:
OperationName: Update policy
properties.message: PIM
condition: selection
level: medium2. sigma_to_defender_kql
将SIGMA规则转换为Microsoft Defender XDR的KQL。
参数:
sigma_rule:YAML格式的SIGMA规则(字符串)
3. yara_to_sentinel_kql
将YARA规则转换为Microsoft Sentinel的KQL。
参数:
yara_rule:YARA规则文本(字符串)
例子:
rule Malware_Example {
meta:
description = "Detects example malware"
author = "Security Team"
strings:
$s1 = "malicious_string"
$s2 = "suspicious_pattern"
condition:
any of them
}4. yara_to_defender_kql
将YARA规则转换为Microsoft Defender XDR的KQL。
参数:
yara_rule:YARA规则文本(字符串)
5. deploy_to_defender
将自定义检测规则部署到Microsoft Defender XDR。
身份验证:
- 没有
access_token:返回部署脚本(Azure CLI和PowerShell) - 随着
access_token:尝试通过Microsoft Graph API直接部署
参数:
sigma_rule(可选):YAML格式的SIGMA规则kql_query(可选):Defender XDR的KQL查询rule_name(可选):规则的自定义名称description(可选):自定义描述severity(可选):信息、低、中、高access_token(可选):用于直接部署的Azure AD承载令牌
退货:
- 如果未提供访问令牌,则部署脚本(Azure CLI和PowerShell)
- 如果提供了访问令牌,则显示部署状态
AI使用示例:
Deploy this SIGMA rule to Defender XDR:
[paste SIGMA rule]请参阅 部署指南 用于身份验证设置和详细说明。
6. generate_defender_deployment_script
在不尝试部署的情况下为Defender XDR生成部署脚本。
参数:
- 同
deploy_to_defender(除access_token)
退货:
- Azure CLI部署脚本
- PowerShell部署脚本
SIGMA规则转换示例
输入(SIGMA YAML):
title: Azure PIM Setting Change
id: 9889d909-c229-42c2-b96b-2a6d13cc9ada
description: Detects changes to Azure Privileged Identity Management settings
author: Detection Engineer
date: 2024/01/01
logsource:
product: azure
service: auditlogs
detection:
selection:
OperationName: "Update policy"
ActivityDisplayName: "Update role setting in PIM"
condition: selection
level: high输出(Sentinel的KQL):
// SIGMA Rule Conversion to KQL
// Title: Azure PIM Setting Change
// ID: 9889d909-c229-42c2-b96b-2a6d13cc9ada
// Description: Detects changes to Azure Privileged Identity Management settings
// Author: Detection Engineer
// Severity: high
// Date: 2024/01/01
AuditLogs
| where
(OperationName =~ "Update policy" and ActivityDisplayName =~ "Update role setting in PIM")
| project
TimeGenerated,
OperationName,
Result,
Identity,
TargetResources,
InitiatedBy,
ActivityDisplayName
// Add time filter as needed:
// | where TimeGenerated > ago(24h)KQL编码标准
此MCP遵循微软官方的KQL编码标准:
- 缩进:使用4个空格进行缩进
- 运算符:运算符使用小写(
where,and,or,not,project) - 表/列名:使用PascalCase(
TimeGenerated,OperationName) - 评论:添加有意义的评论
// - 换行符:将长查询拆分为可读行
- 查询结构:
- 第一行上的表名 - 过滤器 | where - 预测与 | project - 附加上下文注释
发展
构建
npm run build观看模式
npm run watch运行服务器
npm start支持的日志源
哨兵表映射
- Azure审核日志→
AuditLogs - Azure活动→
AzureActivity - Azure登录→
SigninLogs - 视窗→
SecurityEvent - Linux→
Syslog - Office 365→
OfficeActivity - AWS →
AWSCloudTrail - GCP→
GCPAuditLogs
Defender XDR表映射
- 流程事件→
DeviceProcessEvents - 网络事件→
DeviceNetworkEvents - 文件事件→
DeviceFileEvents - 注册表事件→
DeviceRegistryEvents - Azure/O365事件→
CloudAppEvents
参考文献
许可证
麻省理工学院
