Detection Rules as Code
This repository contains tooling to manage CrowdStrike Correlation Rules as code, enabling version control and automated deployment of detection rules.
Overview
The project provides a Python-based solution for managing CrowdStrike Correlation Detection Rules through code, supporting:
Synchronization between local rules and the API
Creation of new rules
Updates to existing rules
Deletion of rules
Version control through Git
Prerequisites
Python 3.x
CrowdStrike API Credential for read & write permission on the
Correlation Rules
scopeRequired Python packages: crowdstrike-falconpy
pip install crowdstrike-falconpy
Setup
Clone the repository:
git clone <repository-url>
cd detection-as-code
Set up environment variables:
export FALCON_CLIENT_ID="your-client-id"
export FALCON_CLIENT_SECRET="your-client-secret"
export FALCON_BASE_URL="your-base-url" # Optional
export LOG_LEVEL="as-desired" # Optional
- Valid values: DEBUG, INFO, WARNING, ERROR, CRITICAL
Usage
Initial Sync
To perform initial synchronization with the API:
python scripts/sync_detections.py
This will create/update rules/rules.json
with the current state from the API.
Creating New Rules
Add a new rule to
rules.json
without an ID:
{
"id": "",
"name": "New Detection Rule",
"severity": 50,
"customer_id": "<<CID>>",
"search": {
"filter": "your-query-here",
"outcome": "detection",
"lookback": "75m",
"trigger_mode": "summary"
},
"operation": {
"schedule": {
"definition": "@every 1h"
},
"start_on": "2025-02-18T22:30:00Z",
}
"status": "active"
}
Run the sync script to create the rule in the API.
Updating Rules
Modify the desired rule in
rules.json
Run the sync script to apply changes
Deleting Rules
Add
"deleted": true
to the rule in rules.jsonRun the sync script to delete the rule from the API
File Structure
.
├── README.md
├── rules/
│ └── rules.json
└── scripts/
└── sync_detections.py
GitHub Actions
This repository includes a GitHub Actions workflow that:
Runs on changes to rules.json
Validates and syncs rules with the API
Required GitHub Secrets
FALCON_CLIENT_ID
FALCON_CLIENT_SECRET
FALCON_BASE_URL (optional)
LOG_LEVEL (optional)
Last updated
Was this helpful?