Skip to main content

Custom Detection Rules

Create and manage custom security detection rules tailored to your environment and threat landscape.

Overview

CastellanAI supports two types of detection rules that you can customize:

Rule TypePurposeManagement
Security Event RulesMap Windows Event IDs to security alerts with MITRE ATT&CK techniquesAPI (Admin only)
Malware Rules (YARA)Signature-based file scanning patternsDashboard UI

Malware Rules (YARA)

YARA rules are the primary method for creating custom file-based detections. These rules use the industry-standard YARA syntax for pattern matching.

Accessing Malware Rules

Navigate to Malware Analysis in the sidebar, then access the Detection Rules section.

Importing Custom YARA Rules

  1. Click Import Rules on the Malware Analysis page
  2. Upload a YARA rule file (.yar, .yara, or .txt)
  3. Configure import settings:
    • Category - Classify the rule (Malware, Ransomware, Trojan, etc.)
    • Author - Rule author attribution
    • Skip Duplicates - Avoid importing existing rules
    • Enable by Default - Activate rules immediately after import
  4. Click Import to add the rules

YARA Rule Structure

YARA rules follow standard YARA syntax:

rule SuspiciousPowerShell : suspicious
{
meta:
description = "Detects encoded PowerShell commands"
author = "Security Team"
severity = "high"

strings:
$enc1 = "-encodedcommand" nocase
$enc2 = "-enc " nocase
$b64 = /[A-Za-z0-9+\/]{50,}={0,2}/

condition:
($enc1 or $enc2) and $b64
}

Rule Components

ComponentDescription
Rule NameUnique identifier (e.g., SuspiciousPowerShell)
TagsClassification tags (e.g., : suspicious)
MetaMetadata including description, author, severity
StringsPatterns to match (text, hex, regex)
ConditionLogic determining when rule triggers

Managing YARA Rules

From the Malware Analysis page, you can:

  • Enable/Disable - Toggle rule activation
  • View Details - See full rule content and match statistics
  • Delete - Remove custom rules (built-in rules cannot be deleted)
  • Filter - Search by name, category, threat level, or status

Security Event Rules

Security Event Rules map Windows Event Log entries to security alerts with MITRE ATT&CK technique mappings.

Rule Structure

Each Security Event Rule contains:

FieldDescription
Event IDWindows Event ID (e.g., 4625 for failed logon)
ChannelLog source (e.g., "Security", "PowerShell/Operational")
Event TypeSecurity classification (e.g., "AuthenticationFailure")
Risk LevelSeverity: low, medium, high, critical
ConfidenceDetection confidence score (0-100)
SummaryHuman-readable description
MITRE TechniquesMapped ATT&CK technique IDs
Recommended ActionsResponse guidance for analysts
PriorityRule priority for conflict resolution
TagsCategorization tags

Pre-built Rules

CastellanAI includes 50+ pre-built Security Event Rules covering:

  • Authentication Events - Logon success/failure (4624, 4625)
  • Privilege Escalation - Special privilege assignment (4672)
  • Account Management - User/group changes (4720, 4732)
  • Process Execution - PowerShell, scheduled tasks (4104, 4698)
  • Service Installation - New services (7045)
  • Security Policy - Audit policy changes (4719)

Creating Custom Security Event Rules

Custom Security Event Rules are managed via the API. Requires Admin role.

Create a Rule:

curl -X POST "http://localhost:5000/api/security-event-rules" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"eventId": 4688,
"channel": "Security",
"eventType": "ProcessCreation",
"riskLevel": "medium",
"confidence": 70,
"summary": "New process created",
"mitreTechniques": ["T1059"],
"recommendedActions": ["Review process details", "Check parent process"],
"isEnabled": true,
"priority": 100,
"description": "Monitors for suspicious process creation",
"tags": ["execution", "custom"]
}'

Update a Rule:

curl -X PUT "http://localhost:5000/api/security-event-rules/{id}" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"riskLevel": "high",
"confidence": 85
}'

Delete a Rule:

curl -X DELETE "http://localhost:5000/api/security-event-rules/{id}" \
-H "Authorization: Bearer YOUR_TOKEN"

API Endpoints

EndpointMethodDescription
/api/security-event-rulesGETList all rules with optional filtering
/api/security-event-rules/{id}GETGet specific rule
/api/security-event-rulesPOSTCreate new rule (Admin)
/api/security-event-rules/{id}PUTUpdate rule (Admin)
/api/security-event-rules/{id}DELETEDelete rule (Admin)
/api/security-event-rules/refresh-cachePOSTRefresh rule cache (Admin)

Best Practices

For YARA Rules

  • Start specific - Begin with narrow patterns, then broaden if needed
  • Test thoroughly - Validate rules don't cause false positives
  • Use metadata - Include author, description, and severity in meta section
  • Leverage community rules - Import from trusted sources like YARA-Rules repository

For Security Event Rules

  • Map to MITRE ATT&CK - Always include relevant technique IDs
  • Set appropriate risk levels - Reserve "critical" for high-confidence threats
  • Include recommended actions - Help analysts respond quickly
  • Use tags - Categorize rules for easier filtering

General Guidelines

DoDon't
Test rules before enablingEnable untested rules in production
Start with high-confidence detectionsCreate overly broad rules
Document rule purpose in descriptionLeave rules without context
Review rule performance regularlyIgnore high false positive rates
Use appropriate severity levelsMark everything as critical

Availability

FeatureSmall BusinessMedium BusinessEnterprise
Built-in YARA rulesYesYesYes
Import YARA rulesYesYesYes
Built-in Event rulesYesYesYes
Create Event rules via API-LimitedUnlimited
Rule performance analytics--Yes

What's Next?